Omniscia Beanstalk Audit
C Code Style Findings
C Code Style Findings
PRO-01C: Inexplicable Value Literal
Type | Severity | Location |
---|---|---|
Code Style | C.sol:L124, L128, L132, L136, L140 |
Description:
The 1e18
value literal is repeated across the codebase as the base of the various percentages used by the Beanstalk protocol.
Example:
127function getUpperBoundPodRate() internal pure returns (Decimal.D256 memory) {128 return Decimal.ratio(POD_RATE_UPPER_BOUND,1e18);129}130
131function getLowerBoundPodRate() internal pure returns (Decimal.D256 memory) {132 return Decimal.ratio(POD_RATE_LOWER_BOUND,1e18);133}134
135function getUpperBoundDPD() internal pure returns (Decimal.D256 memory) {136 return Decimal.ratio(DELTA_POD_DEMAND_UPPER_BOUND,1e18);137}138
139function getLowerBoundDPD() internal pure returns (Decimal.D256 memory) {140 return Decimal.ratio(DELTA_POD_DEMAND_LOWER_BOUND,1e18);141}
Recommendation:
We advise it to be stored to a library-level constant
that clearly depicts its purpose (i.e. PERCENTAGE_BASE
) and is utilised in place of the literals within the code.
Alleviation:
The literal representations were replaced by decimal-accuracy literals offset by the same base (e18
) thereby increasing the legibility of the codebase.
PRO-02C: Suboptimal Code Legibility
Description:
The linked constant
declarations are meant to represent percentages with a base of 1e18
, however, they all utilise different exponent offsets.
Example:
25// Sun26uint256 private constant HARVESET_PERCENTAGE = 5e17; // 50%27
28// Weather29uint256 private constant POD_RATE_LOWER_BOUND = 5e16; // 5%30uint256 private constant OPTIMAL_POD_RATE = 15e16; // 15%31uint256 private constant POD_RATE_UPPER_BOUND = 25e16; // 25%32
33uint256 private constant DELTA_POD_DEMAND_LOWER_BOUND = 95e16; // 95%34uint256 private constant DELTA_POD_DEMAND_UPPER_BOUND = 105e16; // 105%
Recommendation:
We advise the same exponent offset to be utilised across all declarations by utilising fractional representations that are automatically substituted with integers by the compiler (i.e. 0.05e18
is an acceptable representation of 5% by the compiler).
Alleviation:
The value literal was properly replaced by a newly declared PERCENT_BASE
constant representing 1e18
as the mainnet accuracy configuration.