DeFiHardhat
12,000 USDC
View results
Submission Details
Severity: low
Invalid

`ConstantProduct2.sol` error since it doesn't explicitly pass in "using LibMath for uint256" Statement

Summary

The contract does not attach the using LibMath for uint256 statement, preventing access to the functionality provided by the LibMath library unlike has been intended

Vulnerability Detail

The contract relies on the LibMath library for certain mathematical operations. However, it does not include the necessary using LibMath for uint256 statement to enable direct access to the library's functions.

See https://github.com/Cyfrin/2024-04-Beanstalk-DIB/blob/038609d8adf1bf941f8abd12820bc92ecd998375/src/functions/ConstantProduct2.sol#L10-L26

/**
* @title ConstantProduct2
* @author Publius
* @notice Gas efficient Constant Product pricing function for Wells with 2 tokens.
* @dev Constant Product Wells with 2 tokens use the formula:
* `b_0 * b_1 = s^2`
*
* Where:
* `s` is the supply of LP tokens
* `b_i` is the reserve at index `i`
*/
contract ConstantProduct2 is ProportionalLPToken2, IBeanstalkWellFunction {
using Math for uint256;
uint256 constant EXP_PRECISION = 1e12;
uint256 constant CALC_RATE_PRECISION = 1e18;

Impact

The absence of the using LibMath for uint256 statement results in an error. Without access to the LibMath functionality, the contract is unable to perform certain calculations, leading to a failure of executions.

Tool used

Manual Review

Recommendation

Add the using LibMath for uint256 statement to the contract to enable access to the LibMath library's functionality. Change https://github.com/Cyfrin/2024-04-Beanstalk-DIB/blob/038609d8adf1bf941f8abd12820bc92ecd998375/src/functions/ConstantProduct2.sol#L10-L26 to

/**
* @title ConstantProduct2
* @author Publius
* @notice Gas efficient Constant Product pricing function for Wells with 2 tokens.
* @dev Constant Product Wells with 2 tokens use the formula:
* `b_0 * b_1 = s^2`
*
* Where:
* `s` is the supply of LP tokens
* `b_i` is the reserve at index `i`
*/
contract ConstantProduct2 is ProportionalLPToken2, IBeanstalkWellFunction {
using Math for uint256;
+ using LibMath for uint256;
uint256 constant EXP_PRECISION = 1e12;
uint256 constant CALC_RATE_PRECISION = 1e18;
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Informational/Invalid

Support

FAQs

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