DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: low
Invalid

Tansaction will never revert when result is negative in `LibRedundantMathSigned128::sub()` function

Relevant GitHub Links

https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/4e0ad0b964f74a1b4880114f4dd5b339bc69cd3e/protocol/contracts/libraries/LibRedundantMathSigned128.sol#L41

Summary

The `LibRedundantMathSigned128::sub()` function is supposed to revert when there is an overflow or an underflow and also when a negative number is returned. But currently when a negative number is returned the function does not revert and returns the negative number.

Vulnerability Details

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract sub {
function subtract(int128 a, int128 b) public pure returns (int128) {
return a - b;
}
}

Executing this piece of code on (https://remix.ethereum.org/) with the example values of a=10 and b=20 will not cause an error, even though 10-20=-10 returned a negative value.

Impact

Negative values will be returned where either a revert or a positive value was expected.

Tools Used

remix.ethereum.org

Recommendations

function add(int128 a, int128 b) internal pure returns (int128) {
+ require(a >= b, "Negative value is not allowed")
return a + b;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.