stake() and rebalanceToWeight() might lose dust (funds) to the contract. #64
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-152
edited-by-warden
high quality report
This report is of especially high quality
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2023-03-asymmetry/blob/44b5cd94ebedc187a08884a7f685e950e987261c/contracts/SafEth/SafEth.sol#L63-L101
Vulnerability details
Impact
Detailed description of the impact of this finding.
stake()
andrebalanceToWeight()
might lose dust (funds) to the contract. The former might lead some loss of funds to the staker.Proof of Concept
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
The
stake()
function allows a user to stakeETH
into SafEth in exchange forsafETH
. It deposits ETH in proportion to weights to a list of underlying derivative contracts.https://github.com/code-423n4/2023-03-asymmetry/blob/44b5cd94ebedc187a08884a7f685e950e987261c/contracts/SafEth/SafEth.sol#L63-L101
The problem is that when calculating the proportion of
ETH
for each underlying derivative contract, there is some rounding down error due to the use of division bytotalWeight
. Since the protocol does not have a limit for the weight for each derivative contract,totalWeight
could large, let's say whentotalWeight = 100e18
(the dev uses 1e18 in their tests), then the round down error might be large as well.Similar problem occurs for the
rebalanceToWeights()
function, which also calculates the portion of ETH that needs to be allocated to each underlying derivative contract, with an implied rounding down error subject to the quantity oftotalWeight
.In summary, in both cases, some ETH dust will be left in the contract and for the case of
stake()
, it means some loss for the user.Tools Used
VSCode
Recommended Mitigation Steps
Two mitigations: 1) first, we can restrict the totalWeight <= 10000, which inmplies each weight <= 10000;
2) we will make sure all dust goes to the last derivative contract so that no dust of ETH will be left in SafETH.
The text was updated successfully, but these errors were encountered: