Omniscia Beanstalk Audit
LibIncentive Manual Review Findings
LibIncentive Manual Review Findings
LIE-01M: Undocumented Code
Type | Severity | Location |
---|---|---|
Mathematical Operations | LibIncentive.sol:L14-L25 |
Description:
The linked code is meant to represent a binomial approximation of a fractional exponent function that is outlined in section 5 and 6.4.5, however, the necessary adjustments that were made to the formula for the code to approximate are not documented.
Example:
14function fracExp(uint k, uint q, uint n, uint x) internal pure returns (uint) {15 uint p = log_two(n) + 1 + x * n / q;16 uint s = 0;17 uint N = 1;18 uint B = 1;19 for (uint i = 0; i < p; ++i){20 s += k * N / B / (q**i);21 N = N * (n-i);22 B = B * (i+1);23 }24 return s;25}
Recommendation:
We advise the simplification to be included in the whitepaper for validation purposes beyond the log_two
function which was validated. Once that is performed, this finding will be replaced by new findings regarding the fracExp
function (if any).
Alleviation:
The fracExp
function has been extensively documented to indicate what the calculation is meant to represent and we have deem the code implementation true to its documentation. To note, the p
value is meant to represent an upper bound that the approximation is meant to converge to and the Beanstalk team state that they have deemed this value to be the most gas optimal one.