Submitted by RaoulSchaffranek, also found by carlitox477
DBR.sol#L287
While a user borrows DOLA, his debt position in the DBR contract accrues more debt over time. However, Solidity contracts cannot update their storage automatically over time; state updates must always be triggered by externally owned accounts. For this reason, the DBR contract cannot accurately represent a users debt position in its storage at all times. Instead, the contract offers a method accrueDueTokens that, when called, updates the internal storage with the debts that accrued since the last update. This method is called before all critical financial operations that depend on an accurate value of the accumulated deficit in the contracts storage. On top, this method can also be invoked permissionless at any time. Suppose a borrower manages to call this function periodically and keep the time difference between updates short. In that case, a rounding error in the computation of the accrued debt can cause the expression to round down to zero. In this case, the user successfully avoided paying interest on his debt.
For reference, here is the affected code:
The problem is that the function updates the lastUpdated[user] storage variable even when accrued is 0.
Lets assume that the last update occurred at t_0.
Further assume that the next update occurs at t_1 with t_1 - t_0 = 12s. (12s is the current Ethereum block time)
Suppose that the users recorded debt position at t_0 is 1,000,000 wei.
Then the accrued debt formula gives us the following:
The accrued debt formula rounds towards zero if we have (t_1 - t_0) * debt < 365 days.
This gives us a method to compute the maximal debt that we can deposit to make the attack more efficient:
Notice that an attacker is not limited to these small loans. He can split a massive loan into multiple small loans, capped at 2,627,999.
To borrow X tokens (where X is given in WEI), we can compute the number of needed loans as:
For example, to borrow 1 DOLA:
To borrow 1,000,000 DOLA we would thus need 380,517,648,599,000,000 small loans.
The attack would be economically feasible if the costs of the attack were lower than the interest that accrued throughout the successful attack.
The dominating factor of the attack costs is the gas costs which the attacker needs to pay to update the accrued interest of the small loans every second. A clever attacker would batch as many updates into a single transaction as possible to minimize the gas overhead of the transaction. Still, at the current block time (12s), gas price (7 gwei), block gas limit (30,000,000), and current ETH price ($1,550.80), its hardly imaginable that this attack is economically feasible at the moment.
However, all these values could change in the future. And if we look at other networks, Layer2 or EVM compatible Layer1, the parameters might be different today.
Also, notice that if the contract were used to borrow a different asset than DOLA, the numbers would look drastically different. The risk increases with the assets price and becomes bigger the fewer decimals the token uses. For example, to borrow 1 WBTC (8 decimals), we would only need 39 small loans:
And to borrow WBTC worth $1,000,000 at a price of 20,746$/BTC, we would need 1864 small loans.
The following test demonstrates how to avoid paying interest on a loan for 1h. A failing test means that the attack was successful.
Output:
Classified as a high medium because the yields can get stolen/denied. Its not high risk because I dont see an economically feasible exploit.
VSCode, Wolramapha, Foundry
0xean (judge) commented:
08xmt (Inverse) confirmed and commented:
