The ThunderLoan
protocol's deposit
function includes a call to updateExchangeRate
within the AssetToken.sol
contract which inadvertently affects the redemption value of the liquidity provider's (LP's) tokens. The updateExchangeRate
function recalculates the exchange rate of the asset token, with the intention of distributing fees across token holders by increasing the exchange rate proportionally.
However, when a deposit is made, the exchange rate is updated before the LP can redeem, meaning they cannot redeem their tokens on a 1:1 basis immediately after depositing, as they should be able to. The update to the exchange rate effectively dilutes the value of the tokens just minted for the depositor due to the fee calculation and distribution.
The deposit
function in ThunderLoan.sol
and ThunderLoanUpgraded.sol
are as follow:
The associated updateExchangeRate
function in AssetToken.sol
updates the exchange rate based on the fee:
This flaw can lead to an immediate loss of value for LPs depositing their tokens, as the tokens they receive will be worth less than the deposited amount if they were to redeem them instantly. This undermines the confidence in the fairness of the protocol and can deter potential liquidity providers from participating.
To rectify this issue, the protocol should ensure that the exchange rate is updated in a way that does not affect the LPs who have just deposited. One approach would be to delay the fee distribution until after a certain period or until the next deposit or withdrawal occurs from another user, thus separating the exchange rate update from the individual deposit transaction.
Alternatively, the protocol can adjust the minted amount to account for the upcoming exchange rate change, so that the LPs receive an amount of tokens that will still hold the same value after the exchange rate is updated.
Here's a suggested code modification to adjust the minted amount:
This change calculates the mint amount by anticipating the new exchange rate post-update, thereby preserving the 1:1 value for immediate redemption.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.