Skip to content
Smart contracts Audit finding Intermediate

Silent overflow of _fCashAmount

The contract downcasts a user-supplied amount to a smaller integer type without checking, so a value larger than the type's maximum silently overflows. An attacker could pass such a value to cause unexpected behaviour, though the text does not specify the exact consequence.

GreyArt Follow

Originally disclosed on Code4rena

Submitted by GreyArt, also found by Meera

https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L526

Description

If a _fCashAmount value that is greater than uint88 is passed into the _mint function, downcasting it to uint88 will silently overflow.

Recommended Mitigation Steps

// Use a safe downcast function e.g. wfCashLogic::_safeUint88
function _safeUint88(uint256 x) internal pure returns (uint88) {hil
    require(x <= uint256(type(uint88).max));
    return uint88(x);
}

ckoopmann (Index Coop) confirmed and commented:

This seems reasonable and we’ll probably adopt the suggested mitigation approach.


The original report as published on Code4rena, by GreyArt. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the code casts a uint256 to uint88 without first checking that the value fits, so the cast truncates silently.

Impact

An attacker could supply an oversized amount to trigger the silent overflow, potentially causing incorrect accounting or unexpected behaviour, though the text does not detail the exact impact.

What the attacker needed

Ability to call the _mint function with a large _fCashAmount

The fix

The project should use a safe downcast function that checks the value is within the target type's range before converting.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract stores numbers in fixed-size containers. If you try to put a number that is too big into a smaller container, the extra part is cut off without warning, like pouring a litre of water into a 100 ml glass. This report says the contract does that with an amount, which could make the contract behave in an unintended way.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by GreyArt

View all

12 more disclosed reports, best first.

More from Notional x Index Coop

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.