The DebtToken::mint()
function contains a bug that causes double scaling of user debt when minting new tokens. This occurs due to using DebtToken::balanceOf()
instead of super.balanceOf()
for interest calculations, resulting in users receiving more debt tokens than they should.
In the DebtToken::mint()
function, when calculating interest for a new mint operation, the code incorrectly uses DebtToken::balanceOf()
instead of super.balanceOf()
. This causes two issues:
Wrong balance is used for interest calculation
Interest is effectively double counted due to adding balanceIncrease
to the mint amount
Here's a breakdown of what happens:
With Bug (Current):
First deposit = 1000 tokens
scaledBalance = 1000 (at index 1.0)
Index increases to 1.1
balance = 1100 (using balanceOf)
Second deposit = 1000 tokens
balanceIncrease = 1100 * 1.1 - 1100 = 110
amountToMint = 1000 + 110 = 1110
Final balance = 2210
Correct Calculation:
First deposit = 1000 tokens
scaledBalance = 1000 (at index 1.0)
Second deposit = 1000 tokens
scaledBalance = 1000/1.1 = 909.09 (at index 1.1)
Total scaledBalance = 1909.09
Final balance = 1909.09 * 1.1 = 2100
Create a file DebtTokenTest.t.sol
under /test/foundry/
with the following code:
This bug has severe implications for the protocol:
Users have higher debt than they should (5.2% increase in the example above)
Protocol's accounting is incorrect
Could lead to unfair liquidations due to inflated debt positions
Affects the overall stability and reliability of the lending protocol
The likelihood is HIGH because it occurs on every mint operation.
The impact is HIGH because the error compounds with each mint operation.
Manual review
Foundry
Fix the DebtToken::mint()
function:
Use super.balanceOf()
instead of balanceOf()
because balanceOf()
returns the non-scaled balance:
Remove the addition of balanceIncrease
to amountToMint
:
In reality scaledBalance
is used only for the balanceIncrease
calculation that we don't need because the interest accrual is inherent within the index based solution the protocol is using.
But we still have to correct it because it is used in the return value of DebtToken::mint()
to check if it is the firs mint.
The POC uses Foundry in a Hardhat project. To reproduce:
Install Foundry using their installation script:
Install the hardhat-foundry plugin:
Add require("@nomicfoundation/hardhat-foundry");
to the top of your hardhat.config.js file.
For detailed setup instructions, see Hardhat + Foundry Integration Guide.
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.