`EtherFiLib::_initiateWithdrawImpl` will revert because rebase tokens transfer 1-2 less wei
The withdrawal function assumes the amount of eETH received from unwrapping weETH equals the amount requested, but rebase tokens transfer 1-2 wei less due to rounding, causing the subsequent transfer to fail. An attacker could trigger this to cause a denial of service on withdrawals.
EtherFiLib::_initiateWithdrawImpl will revert because rebase tokens transfer 1-2 less wei
Vulnerability Detail
The protocol always assumes that the amount of tokens received is equal to the amount of tokens transferred.
This is not the case for rebasing tokens, such as stETH and eETH, because internally they transfer shares which generally results in the received amount of tokens being lower than the requested one by a couple of wei because of roundings: transferring 1e18 eETH tokens from A to B, will may result in B receiving 0.99999e18 eETH tokens.
1 Unwraps weETHToUnwrap weETH, meaning Transfers eETHReceived of eETH from the weETH contract to this contract itself
2 RequestWithdraw eETHReceived, which will attempt to transfer eETHReceived from the contract to the Etherfi protocol
But the actual amount of eETH received may be eETHReceived - 1~2 wei.
Step 2 will fail, because the contract doesn't have enough eETH. The issue lies in attempting to transfer eETHReceived of eETH in step 2 instead of wrapping the actual amount of tokens received.
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
It concerns deposit(), NOT wrap/unwrap
ZeroTrust01
Escalate
This should be considered a valid issue.
JavaScript
function unwrap(uint256 _weETHAmount) external returns (uint256) {
require(_weETHAmount > 0, "Cannot unwrap a zero amount");
uint256 eETHAmount = liquidityPool.amountForShare(_weETHAmount);
_burn(msg.sender, _weETHAmount);
@>> eETH.transfer(msg.sender, eETHAmount);
return eETHAmount;
}
The weETH::unwrap() function includes a transfer operation, so this involves the transfer of rebase tokens in this contract. In the LiquidityPool.requestWithdraw function, rebase tokens are transferred out of this contract because internally they transfer shares, which generally results in the received amount of tokens being lower than the requested one by a couple of wei due to rounding, So it will revert.
function unwrap(uint256 _weETHAmount) external returns (uint256) {
require(_weETHAmount > 0, "Cannot unwrap a zero amount");
uint256 eETHAmount = liquidityPool.amountForShare(_weETHAmount);
_burn(msg.sender, _weETHAmount);
@>> eETH.transfer(msg.sender, eETHAmount);
return eETHAmount;
}
The weETH::unwrap() function includes a transfer operation, so this involves the transfer of rebase tokens in this contract. In the LiquidityPool.requestWithdraw function, rebase tokens are transferred out of this contract because internally they transfer shares, which generally results in the received amount of tokens being lower than the requested one by a couple of wei due to rounding, So it will revert.
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.
mystery0x
Escalate This should be considered a valid issue.
JavaScript
function unwrap(uint256 _weETHAmount) external returns (uint256) {
require(_weETHAmount > 0, "Cannot unwrap a zero amount");
uint256 eETHAmount = liquidityPool.amountForShare(_weETHAmount);
_burn(msg.sender, _weETHAmount);
@>> eETH.transfer(msg.sender, eETHAmount);
return eETHAmount;
}
The weETH::unwrap() function includes a transfer operation, so this involves the transfer of rebase tokens in this contract. In the LiquidityPool.requestWithdraw function, rebase tokens are transferred out of this contract because internally they transfer shares, which generally results in the received amount of tokens being lower than the requested one by a couple of wei due to rounding, So it will revert.
Read through the report carefully, and you will notice wrap/unwrap is always 1:1. It's deposit() that's causing the 1-2 wei issue which does not apply to your report context.
ZeroTrust01
Escalate This should be considered a valid issue.
JavaScript
function unwrap(uint256 _weETHAmount) external returns (uint256) {
require(_weETHAmount > 0, "Cannot unwrap a zero amount");
uint256 eETHAmount = liquidityPool.amountForShare(_weETHAmount);
_burn(msg.sender, _weETHAmount);
@>> eETH.transfer(msg.sender, eETHAmount);
return eETHAmount;
}
The weETH::unwrap() function includes a transfer operation, so this involves the transfer of rebase tokens in this contract. In the LiquidityPool.requestWithdraw function, rebase tokens are transferred out of this contract because internally they transfer shares, which generally results in the received amount of tokens being lower than the requested one by a couple of wei due to rounding, So it will revert.
This is exactly the same issue as the one confirmed in the contest a few weeks ago. sherlock-audit/2024-05-sophon-judging#63sherlock-audit/2024-05-sophon-judging#119
Here's the selected report for Sophon contest that's related to your finding on eETH:
Read through the report carefully, and you will notice wrap/unwrap is always 1:1. It's deposit() that's causing the 1-2 wei issue which does not apply to your report context.
You mixed up the link I provided. I pointed out that this issue is exactly the same as issue group 1 (in the picture), but your link is to issue group 2 (in the picture). I never said it was the same as issue group 2.
WangSecurity
@ZeroTrust01 could you provide the link to the eETH contract please, so I can see how they've implemented their transfer function with fees.
ZeroTrust01
@ZeroTrust01 could you provide the link to the eETH contract please, so I can see how they've implemented their transfer function with fees.
This issue is not about the transfer function with fees; it is about rebase token transfer using shares. If the transfer amount is 1e18, the received amount might be (1e18 - 1 wei).
Thank you. For future reference, historical decisions are not sources of truth and each issue is different, so I would like to ask you instead of saying "this issue is the exact same as in the previous contest", prove that your issue is valid, regardless of other contests and decisions. Often it's the case that the same issue is valid in one contest, but invalid in an another.
About the issue. Even though, Notional's code fetches the eEthReceived from weEth.unwrap the eEthReceived represents the amount before eEth.transfer. eETH.transfer makes a conversion from input amount to token shares and sends the amount of shares received, which can be lower due to precision loss. Later, this will revert since the contract tries to send eEthreceived.
Planning to accept the escalation and validate the report with high severity since it can happen on every withdrawal from EtherFi. @mystery0x @ZeroTrust01 are there any duplicates?
The original report as published on Sherlock, by ZeroTrust. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The code used the requested amount instead of the actual received amount when transferring rebase tokens, ignoring rounding losses.
Impact
Contract functionality is subject to denial of service, as withdrawals can revert on every attempt.
What the attacker needed
None
The fix
The issue was fixed by measuring the actual balance change and using that amount for approval and withdrawal.
How it was found
Unwrap weETHToUnwrap weETH, which transfers eETHReceived of eETH to the contract.
Call requestWithdraw with eETHReceived, which attempts to transfer that amount from the contract to the EtherFi protocol.
The actual eETH received may be 1-2 wei less, so the transfer fails due to insufficient balance.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
Some tokens, called rebase tokens, change their balance through shares, so when you send an amount, the receiver may get slightly less due to rounding. The code here assumed the received amount was exactly the same as the sent amount, so a later transfer failed because the contract didn't have enough tokens. This meant withdrawals could be blocked.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.