This repository has been archived by the owner on May 26, 2023. It is now read-only.
Tricko - New investors claims may lead to reverts #98
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Non-Reward
This issue will not receive a payout
Tricko
medium
New investors claims may lead to reverts
Summary
New investors are able to claim WETH withdrawn before their registration, possibly leading to reverting claims.
Vulnerability Detail
An investor who gets registered at time X is able to claim funds withdraw before X. It is not clear from the README if this is intentional. These funds withdrawn are released collateral, due to the self-repaying property of Alchemix loans, therefore from a theoretical standpoint, it does not makes sense for these funds to get payments from before their deposit time.
But also, on a pratical level, this can lead to states where claims becomes impossible for one or more investors. For ease of explanation, consider that
withdraw_underlying_to_claim
is called on regular intervals (let's call them epochs), each epoch the vault receives 1WETH per share to be redistributed. Initially, Alice is the sole investor registered and she has10**18
shares.1. 1° epoch:
amount_claimable_per_share
= 1.0, vault's WETH balance =10**18
2. Alice claims
10**18
WETH3. 2° epoch:
amount_claimable_per_share
= 2.0, vault's WETH balance =10**18
4. Alice claims
10**18
WETH5. Bob gets registered with
10**18
shares.6. 3° epoch:
amount_claimable_per_share
= 3.0, vault's WETH balance =2*10**18
7. Alice claims
10**18
WETH8. Bob tries to claim
3*10**18
WETH, but transaction reverts due to lack of funds in the vault contract.In this scenario, unless extra WETH is added to the vault, Bob will never be able to claim because his claimable amount will always be bigger than
ERC20(WETH).balanceOf(self)
. See the proof of concept for this scenario on the POC section below.On a general case, in a vault with dozens of investors registred, there are three possible outcomes:
- If Bob manages to claim faster than others investors, one or more investors (depending on how much Bob claimable amount was) won't be able to claim.
- If Bob tries to claim later than the others, he will not be able to claim.
- If the contract has sufficient extra balance (more than what is due to
withdraw_underlying_to_claim
). Bob will be able to claim, but will incur permanent loss of funds to the contract.Impact
As explained above, depending on the exact circumstances, one or more user won't be able to claim or contract's funds will be permanently loss.
Proof of Concept
Run the following test with pytest
Code Snippet
https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/Vault.vy#L408-L419
https://github.com/sherlock-audit/2023-02-fair-funding/blob/main/fair-funding/contracts/Vault.vy#L443-L462
Tool used
Manual Review
Recommendation
During registration consider storing
amount_claimable_per_share
at that time in thePosition
struct, so it can be subtracted from futureclaimable_for_token
calculations.Duplicate of #114
The text was updated successfully, but these errors were encountered: