This value will be used to choose between the mint or swap pathway (L156), and may be the actual number of tokens minted in didPay() (L205 or L207).
If the tokens are not minted by JBXBuybackDelegate then the number of tokens to mint in the terminal is instead calculated in JBSingleTokenPaymentTerminalStore3_1.recordPaymentFrom() at L427 as
and so is not necessarily 10**18.
This means that _tokenCount in JBXBuybackDelegate may be different from tokenCount in the terminal and lead to a different and incorrect amount of tokens minted.
Recommended Mitigation Steps
Perform the same calculation of _tokenCount in JBXBuybackDelegate as in the terminal.
Lines of code
https://github.com/code-423n4/2023-05-juicebox/blob/9d0458282511ff269b3b35b5b082b56d5cc08663/juice-buyback/contracts/JBXBuybackDelegate.sol#L150
Vulnerability details
Impact
JBXBuybackDelegate
may mint a different and incorrect amount of tokens than what would otherwise have been minted in the terminal.Proof of Concept
In
JBXBuybackDelegate
the total number of tokens to mint is calculated inpayParams()
at L150 asThis value will be used to choose between the mint or swap pathway (L156), and may be the actual number of tokens minted in
didPay()
(L205 or L207).If the tokens are not minted by
JBXBuybackDelegate
then the number of tokens to mint in the terminal is instead calculated inJBSingleTokenPaymentTerminalStore3_1.recordPaymentFrom()
at L427 as_weightRatio
is calculated just beforeand so is not necessarily
10**18
. This means that_tokenCount
inJBXBuybackDelegate
may be different fromtokenCount
in the terminal and lead to a different and incorrect amount of tokens minted.Recommended Mitigation Steps
Perform the same calculation of
_tokenCount
inJBXBuybackDelegate
as in the terminal.Assessed type
Context