-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bigsam - After a User withdraws The interest Rate is not updated accordingly leading to the next user using an inflated index during next deposit before the rate is normalized again #387
Comments
1 comment(s) were left on this issue during the judging contest. Honour commented:
|
request poc |
PoC requested from @Tomiwasa0 Requests remaining: 15 |
++ import {IPool} from './../../../../contracts/interfaces/pool/IPool.sol';
++ import {MockFlashLoanSimpleReceiver} from './../../../../contracts/mocks/MockSimpleFlashLoanReceiver.sol';
contract PoolWithdrawTests is PoolSetup {
++ address alice = address(1);
++ address bob = address(2);
++ event Transfer(address indexed from, address indexed to, uint256 value);
function _generateFlashloanCondition() internal {
// Mint and approve tokenA and tokenC for bob
_mintAndApprove(bob, tokenA, 60 ether, address(pool));
_mintAndApprove(bob, tokenC, 2500 ether, address(pool));
// Start prank as bob to simulate transactions from bob's account
vm.startPrank(bob);
// Supply tokenC to the pool for bob
pool.supplySimple(address(tokenC), bob, 1000 ether, 0);
// Stop prank as bob
vm.stopPrank();
} Updated
|
Bigsam
Medium
After a User withdraws The interest Rate is not updated accordingly leading to the next user using an inflated index during next deposit before the rate is normalized again
Summary
A bug in Zerolend's withdrawal mechanism causes the interest rate to not be updated when funds are transferred to the treasury during a withdrawal. This failure leads to the next user encountering an inflated interest rate when performing subsequent actions like deposit, withdrawal or borrow before the rate is normalized again. The issue arises because the liquidity in the pool drops due to the funds being transferred to the treasury, but the system fails to update the interest rate to reflect this change.
Root Cause
Examples of update rate before transferring everywhere in the protocol to maintain Rate
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/SupplyLogic.sol#L69-L81
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/SupplyLogic.sol#L125-L146
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/BorrowLogic.sol#L88-L99
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/BorrowLogic.sol#L139-L158
The same process can be observed in Aave v 3.
Looking at the effect of updating rate
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/ReserveLogic.sol#L134-L182
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/periphery/ir/DefaultReserveInterestRateStrategy.sol#L98-L131
This rates are used to get the new index
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/ReserveLogic.sol#L225-L227
https://github.com/sherlock-audit/2024-06-new-scope/blob/main/zerolend-one/contracts/core/pool/logic/ReserveLogic.sol#L235-L237
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
In the current implementation of Zerolend, during a withdrawal, the protocol transfers a portion of the funds to the treasury. However, it does not update the interest rate before this transfer has being done for all transfers, leading to an inflated liquidity rate being used by the next user, particularly for deposits. This is problematic as the next user deposits/withdraws at a rate that is incorrectly high, causing them to receive fewer shares than they should.
In comparison, Aave mints shares to the treasury, which can later withdraw this funds like any other user.
Each withdrawal out of the contract in underlying asset in Aave updates the interest rate, ensuring the rates reflect the true liquidity available in the pool.
Zerolend's approach of transferring funds directly upon every user withdrawal fails to adjust the interest rate properly, resulting in a temporary discrepancy that affects subsequent users.
Code Context:
In the
executeMintToTreasury
function, the accrued shares for the treasury are transferred, but the interest rates are not updated to account for the change in liquidity.As can be seen in this snippet, the funds are transferred to the treasury, but the function does not invoke any interest rate update mechanism. The liquidity in the pool decreases, but the next user's deposit will use an inflated rate due to this oversight.
Interest Rate Update Example (Correct Flow):
In other parts of the code, such as during withdrawals, the interest rate is properly updated when liquidity changes:
The
updateInterestRates
function correctly calculates the new interest rate based on the changes in liquidity, ensuring the system uses accurate rates for subsequent operations.Example of Problem:
Consider the following scenario:
Since the actual liquidity is lower than the interest rate assumes, the user depositing gets fewer shares than expected.
Impact
PoC
No response
Mitigation
The mitigation involves ensuring that the interest rate is properly updated before transferring funds to the treasury. The rate update should account for the liquidity being transferred out, ensuring the new rates reflect the actual available liquidity in the pool.
Suggested Fix:
In the
executeMintToTreasury
function, call theupdateInterestRates
function before transferring the assets to the treasury. This will ensure that the interest rate reflects the updated liquidity in the pool before the funds are moved.Modified Code Example:
In this updated version, the interest rates are recalculated to account for the liquidity sent to the treasury. This ensures that the next user's deposit uses a correctly updated interest rate.
The text was updated successfully, but these errors were encountered: