Many cases `stEth::transferFrom` will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance
The stETH token uses shares for balance tracking, and due to rounding errors, a transferFrom may transfer 1-2 wei less than the requested amount. This can cause subsequent functions that rely on the exact amount to revert, leading to a denial of service.
Bauchibred Follow with EgisSecurity and zzykxx
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-05-sophon-judging/issues/63
The protocol has acknowledged this issue.
Found by
Bauchibred, EgisSecurity, zzykxx
Summary
When user calls depositStEth, he passes _amount param, which is set to IERC20(stETH).safeTransferFrom() func and then the sam _amount is passed down the chain:
IERC20(stETH).safeTransferFrom(
msg.sender,
address(this),
_amount
);
_depositPredefinedAsset(_amount, _amount, _boostAmount, PredefinedPool.wstETH);
Vulnerability Detail
The probability of issue appearing is high and you can check in the following discussion. It has also been classified as a High severity on past contests: https://github.com/lidofinance/lido-dao/issues/442
stETH is using shares for tracking balances and it is a known issue that due to rounding error, transferred shares may be 1-2 wei less than _amount passed.
This would revert on the following line as we have transferred _amount - 1 and farming contract do not hold stEth funds:
function _stEthTOwstEth(uint256 _amount) internal returns (uint256) {
// wrap returns exact amount of wstETH
return IwstETH(wstETH).wrap(_amount);
}
The impact may be bigger if the staking contract is implemented by 3rd party protocol and expect this the function to be always fine.
Impact
- Contract functionality DoS
Code Snippet
Tool used
Manual Review
Recommendation
Use lido recommendation to utilize transferShares function, so the _amount is realistic, or implement FoT approach, which compares the balance before and after the transfer.
Discussion
sherlock-admin4
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
valid because this parallels FOT as documented by Lido (best because the report is succinct and well documented)
mcbvictor0x
Fixed here: https://github.com/sophon-org/farming-contracts/commit/66e05ccb6cdfb8392b6a2bb4953931168cd247d3
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the use of transferFrom with stETH, which can result in a 1-2 wei shortfall due to rounding, instead of using transferShares or checking the actual balance change.
Impact
This could cause a denial of service by making the contract revert when it tries to wrap the full amount, and the impact may be bigger if a third-party staking contract expects the function to always succeed.
What the attacker needed
User has stETH and calls depositStEth
The fix
The issue was fixed by the protocol.
How it was found
- User calls depositStEth with an _amount.
- The contract calls safeTransferFrom to transfer _amount of stETH from the user.
- Due to rounding, the actual transferred amount may be _amount - 1 or _amount - 2 wei.
- The contract then calls _depositPredefinedAsset with the original _amount.
- This leads to a call to wrap _amount into wstETH, which may revert if the contract's balance is insufficient.
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.
When you send a token like stETH, the amount you receive might be slightly less than what you asked to send because of how the token calculates shares. If the receiving contract then tries to use the full amount, it may not have enough and the transaction fails.
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.