-
Notifications
You must be signed in to change notification settings - Fork 0
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
First depositor can make subsequent depositor lose all of her or his deposit #1473
Comments
DadeKuma marked the issue as primary issue |
DadeKuma marked the issue as sufficient quality report |
We can always discard a vault that has not been used by the users so even if the attacker is paying a lot of gas and is sending his transaction right after we deployed and before we deposit a minimum amount into the vault ourselves (which means that this issue has been materialized) we can discard the vault and deploy a new one. Also at the end, the keeper network is responsible calling the "calculateDeposit" function. So this means that multiple user's deposits will be calculated in one transaction and the attacker can't execute another transaction in the middle of calculateDeposit function. So this is not an issue. |
gzeon-c4 marked the issue as satisfactory |
gzeon-c4 marked the issue as selected for report |
gzeon-c4 changed the severity to 2 (Med Risk) |
Usually donation attack would be considered as High Risk but downgrading to Med since keepers are involved for successful attack. |
Lines of code
https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L226-L250
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L151-L153
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L225-L227
https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L591-L593
https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L627-L630
Vulnerability details
Impact
For calculating the
shares
for the corresponding deposit, the followingcalculateDepositShares
function call thepreviewDeposit
function below, which further calls the_convertToShares
,totalAssets
, andTVL
functions below. HigherbaseToken.balanceOf(address(this))
causes the values returned by theTVL
andtotalAssets
functions to be higher and the calculatedshares
to be lower for the same deposit amount. Thus, the first depositor can deposit just 1 wei ofbaseToken
and then transfer a huge amount ofbaseToken
to theAccountingManager
contract after theshares
are calculated for her or his deposit. Afterwards, theshares
calculated for the subsequent depositor's deposit can round down to 0. In this case, the first depositor can later withdraw all of her or his deposit and transferred amount but the subsequent depositor cannot withdraw any of her or his deposit since she or he owns 0 shares. As a result, the subsequent depositor loses all of her or his deposit.https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L226-L250
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L151-L153
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol#L225-L227
https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L591-L593
https://github.com/code-423n4/2024-04-noya/blob/cc3854f634a72bd4a8b597021887088ca2d6d29f/contracts/accountingManager/AccountingManager.sol#L627-L630
Proof of Concept
Please add the following test in
testFoundry\TestAccounting.sol
. This test will pass to demonstrate the described scenario.Tools Used
Manual Review
Recommended Mitigation Steps
Certain amount of shares can be minted to
address(0)
during the deployment of theAccountingManager
contract, and the first depositor can be required to mint a minimal amount of shares.Assessed type
Other
The text was updated successfully, but these errors were encountered: