Github username: @aviggiano
Submission hash (on-chain): 0x675f36f00cd9a8a5098b0d6003ff381cbf7d9d4ec14882562dfae8d87d8663d6
Severity: medium
Description:
Description
In BondCalculator.sol:69, the function computeCvgExpected will always sum 1 to the result even if the division is exact. ABDKMathQuad.div, by default, rounds the result down. However, when the division is exact, adding 1 to the result is not necessary, and will in fact cause the result to be 1 more than necessary.
For example, in order to round up the result of the integer division roundUp(79/20), one can sum 1 to the final result, which will be 4 = roundUp(79/20) == 79/20+1 == 3+1 == 4. However, if the division is exact, summing up does not mean the result will be rounded up, but rather it will be off by one: 4 = roundUp(80/20) != 80/20+1 == 4+1 == 5.
Attack scenario
An attacker could exploit this rounding issue in the event composedFunction is set to 1 (ln bonding computation) in order to gain a greater amount of cvgExpected than expected.
To resolve this issue, it is recommended to remove the addition of 1 for when the composedFunction equals 1, and instead use the actual result of the division operation.
Github username: @aviggiano Submission hash (on-chain): 0x675f36f00cd9a8a5098b0d6003ff381cbf7d9d4ec14882562dfae8d87d8663d6 Severity: medium
Description:
Description
In
BondCalculator.sol:69
, the functioncomputeCvgExpected
will always sum 1 to the result even if the division is exact.ABDKMathQuad.div
, by default, rounds the result down. However, when the division is exact, adding 1 to the result is not necessary, and will in fact cause the result to be 1 more than necessary.For example, in order to round up the result of the integer division
roundUp(79/20)
, one can sum 1 to the final result, which will be4 = roundUp(79/20) == 79/20+1 == 3+1 == 4
. However, if the division is exact, summing up does not mean the result will be rounded up, but rather it will be off by one:4 = roundUp(80/20) != 80/20+1 == 4+1 == 5
.Attack scenario
An attacker could exploit this rounding issue in the event
composedFunction
is set to 1 (ln bonding computation) in order to gain a greater amount ofcvgExpected
than expected.Proof of Concept
Recommendation
To resolve this issue, it is recommended to remove the addition of 1 for when the
composedFunction
equals 1, and instead use the actual result of the division operation.