In summary, the minted of reservedTokens in the controller.burnTokensOf() function uses the exact same mathematical formula that is used to calculate the amount of _nonReservedToken.
Use the returned value to compare it agains the _reservedToken variable, and if they are not equals that means that an incorrect amount of reserve tokens were minted to the reserve
Lines of code
https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L337-L345
Vulnerability details
Impact
Break the internal accounting if the number of minted reserved tokens is incorrectly
Proof of Concept
The
_reservedToken
is calculated by substracting the_amountReceived - _nonReservedToken
, and_nonReservedToken
is calculated using the below formula, which is the exact same formula used in the controller.mintTokensOf() to determine the value ofbeneficiaryTokenCount
.And finally, the amount calculated for the
beneficiaryTokenCount
is used to mint the reservedTokens, that implies that the mint was made with the same formula used to calculate the value of the_nonReservedToken
in theJBXBuybackDelegate
contractIn summary, the minted of
reservedTokens
in thecontroller.burnTokensOf()
function uses the exact same mathematical formula that is used to calculate the amount of_nonReservedToken
.That breaks the assumption made on the comment that the reserve will have the
reservedTokens
, it will not, it will have the equivalent of the_nonReservedToken
Tools Used
Manual Audit
Recommended Mitigation Steps
comptroller.mintTokensOf()
function which is an uint representing the number of tokens received by the beneficiary._reservedToken
variable, and if they are not equals that means that an incorrect amount of reserve tokens were minted to the reserveAssessed type
Math