-
Notifications
You must be signed in to change notification settings - Fork 0
0x52 - amount_claimable_per_share accounting is broken and will result in vault insolvency #44
Comments
Dup of #114 |
Escalate for 1 USDC Not a dupe of #114. That focuses on depositing twice to the same token (which can't happen outside of admin abuse). The issue is that it generally applies to all deposits. Please re-read my example as to why this is an issue and how it leads to gross over-commitment of rewards. Two reasons I disagree with this being low:
Would like to add that this and #113 are the same issue and escalations should be resolved together. |
You've created a valid escalation for 1 USDC! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
Agree, duplicate of #113 and will fix. |
Escalation accepted Considering this & its duplicate #113 as valid issues |
This issue's escalations have been accepted! Contestants' payouts and scores will be updated according to the changes made on this issue. |
Fix is ok: I'd also like to highlight that some yield can be lost due to rounding, see example below. Example
Adding Probably negligible given low yield accumulation + short auction reasoning. Nevertheless, consider using a higher precision value. Edit: I see Unstoppable-DeFi/fair-funding#2 does just that. |
Message from Protocol Team:
Message from Lead Senior Watson:
|
0x52
high
amount_claimable_per_share accounting is broken and will result in vault insolvency
Summary
Claim accounting is incorrect if there is a deposit when amount_claimable_per_share !=0, because position.amount_claimed isn't initialized when the deposit is created.
Vulnerability Detail
https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/Vault.vy#L430-L440
When calculating the amount of WETH to claim for a user, the contract simply multiplies the share count by the current amount_claimable_per_share and then subtracts the amount that has already been paid out to that token holder. This is problematic for deposits that happen when amount_claimable_per_share != 0 because they will be eligible to claim WETH immediately as if they had been part of the vault since amount_claimable_per_share != 0.
Example;
User A deposits 1 ETH and receives 1 share. Over time the loan pays itself back and claim is able to withdraw 0.1 WETH. This causes amount_claimable_per_share = 0.1. Now User B deposits 1 ETH and receives 1 share. They can immediately call claim which yields them 0.1 WETH (1 * 0.1 - 0). This causes the contract to over-commit the amount of WETH to payout since it now owes a total of 0.2 WETH (0.1 ETH to each depositor) but only has 0.1 WETH.
Impact
Contract will become insolvent
Code Snippet
https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/Vault.vy#L200-L232
Tool used
Manual Review
Recommendation
position.amountClaimed needs to be initialized when a deposit is made:
The text was updated successfully, but these errors were encountered: