code-423n4 / 2023-01-popcorn-findings

0 stars 0 forks source link

The contract uses the Math.mulDiv function, which can be susceptible to overflow and underflow attacks. #207

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/yearn/YearnAdapter.sol#L93 https://github.com/code-423n4/2023-01-popcorn/blob/d95fc31449c260901811196d617366d6352258cd/src/vault/adapter/yearn/YearnAdapter.sol#L136

Vulnerability details

Impact

An integer overflow issue can have significant impact on functionality and security of smart contract. In the contract, if the totalSupply exceeds the maximum value of a uint256 variable (2^256-1), it will wrap around to a small number, causing incorrect values to be stored in the totalSupply variable. This can result in incorrect balance tracking and make the contract vulnerable to various attacks, such as the transfer of more tokens than the intended supply.

Proof of Concept

Proof of concept (POC) for an integer overflow issue in the above smart contract can be demonstrated by exceeding the "totalSupply" variable to its maximum limit, causing it to wrap around and become a negative number. This can be done by repeatedly calling the "addSupply" function with a large enough value, until the value of "totalSupply" exceeds its maximum limit. At this point, any further calls to the "addSupply" function will result in an incorrect calculation, as it will be performed on a negative number.

Tools Used


Recommended Mitigation Steps

Following method can be helpful, •Use Safe Mathematics Libraries: To ensure the correctness of arithmetic operations, use libraries like SafeMath in Solidity that automatically check for overflow/underflow conditions and throws an exception in case it occurs.

c4-sponsor commented 1 year ago

RedVeil marked the issue as sponsor disputed

c4-judge commented 1 year ago

dmvt marked the issue as unsatisfactory: Insufficient quality