The zap router staked ETH with Lido using a low-level call that ignored reverts, so when Lido paused staking or hit its stake limit the deposit silently failed and the CDP flow continued, potentially losing the user's ETH or leaving the position in an unexpected state.
When EbtcLeverageZapRouter::openCdpWithEth and EbtcLeverageZapRouter::adjustCdpWithEth stake ETH with Lido, the underlying function performing the call assumes that any exceptions (from Lido) will be bubbled up, but with call being a low level rather than a Solidity function, it is not the case.
Lido stETH has two cases where a revert on depositing ETH for staking may be encountered, when deposits are paused or when staking limits are enabled and it is exceeded.
If Lido returns a revert it is ignored and the entire CDP flow continues (permits, flash loans, account synching, CDP initialization, eBTC minting), with a revert only being cause only by one of the last step of the flow, moving the collateral to the active pool.
Proof of Concept
The two parts to the issue:
Any possibility of reverts during staking ETH with Lido.
/**
* @notice Stops accepting new Ether to the protocol
*
* @dev While accepting new Ether is stopped, calls to the `submit` function,
* as well as to the default payable function, will revert.
*
* Emits `StakingPaused` event.
*/
function pauseStaking() external {
Lido can impose a per block stake limit on Ethereum stETH
Both these cause the same effect; a possible revert during the submit of ETH for staking with Ethereum stETH:
function _submit(address _referral) internal returns (uint256) {
require(msg.value != 0, "ZERO_DEPOSIT");
StakeLimitState.Data memory stakeLimitData = STAKING_STATE_POSITION.getStorageStakeLimitStruct();
// There is an invariant that protocol pause also implies staking pause.
// Thus, no need to check protocol pause explicitly.
@> require(!stakeLimitData.isStakingPaused(), "STAKING_PAUSED");
if (stakeLimitData.isStakingLimitSet()) {
uint256 currentStakeLimit = stakeLimitData.calculateCurrentStakeLimit();
@> require(msg.value <= currentStakeLimit, "STAKE_LIMIT");
2. Incorrect assumption that revert would bubble:
EbtcLeverageZapRouter and EbtcZapRouter both use the same ancestor function to stake ETH with Lido, that performs the call operation on a address in ZapRouterBase::_depositRawEthIntoLido
function _depositRawEthIntoLido(uint256 _initialETH) internal returns (uint256) {
// check before-after balances for 1-wei corner case
uint256 _balBefore = stEth.balanceOf(address(this));
// TODO call submit() with a referral?
@> payable(address(stEth)).call{value: _initialETH}("");
uint256 _deposit = stEth.balanceOf(address(this)) - _balBefore;
return _deposit;
}
call is a low level function to interact with other contracts.
This is the recommended method to use when you're just sending Ether via calling the fallback function.
However, it is not the recommended way to call existing functions.
Few reasons why low-level call is not recommended
Reverts are not bubbled up
Type checks are bypassed
Function existence checks are omitted
EbtcZapRouter does check the collateral balance in the function that follows the staking of ETH with Lido in EbtcZapRouter::_openCdpWithPermit()
require(
stEth.balanceOf(address(this)) >= _stEthBalance,
"EbtcZapRouter: not enough collateral for open!"
);
EbtcLeverageZapRouter performs no similar checks on the collateral balance after the staking, rather failing on a ERC20 transfer after another ~320K gas of other operations.
Test Case
Adds a pause to the CollateralTokenTester and demonstrates the non-propagation of the initial revert, instead relying on the later ERC20 revert.
The CollateralTokenTester mocks Lido stETH, add the following to the version used by the ebtc-zap-router tests (should be at /lib/ebtc/packages/contracts/TestContracts/CollateralTokenTester.sol):
- function deposit() public payable {
+ bool private depositsArePaused;
+
+ function pauseDeposits() external {
+ depositsArePaused = true;
+ }
+
+ function deposit() public payable {
+ require(!depositsArePaused, "STAKING_PAUSED");
function test_ZapOpenCdp_WithEth_LidoRReverts() external {
seedActivePool();
// Pausing deposits to mimic Lido's pauseStaking() or stakeLimit being set & exceeded
CollateralTokenTester(collateral).pauseDeposits();
// Logic equivalent to that from createLeveragedPosition(MarginType.ETH)
// Extracted to test correctly using expectRevert()
address user = vm.addr(userPrivateKey);
uint256 _debt = 1e18;
uint256 flAmount = _debtToCollateral(_debt);
uint256 marginAmount = 5 ether;
vm.deal(user, type(uint96).max);
IEbtcZapRouter.PositionManagerPermit memory pmPermit = createPermit(user);
vm.prank(user);
// Fails on the last step of BorrowerOperations::_openCdp(); transfer of collateral to the active pool
vm.expectRevert("ERC20: transfer amount exceeds balance");
_openTestCdp(MarginType.ETH, _debt, flAmount, marginAmount, pmPermit);
}
Run with forge test --match-contract LeverageZaps --match-test test_ZapOpenCdp_WithEth_LidoRReverts.
Tools Used
Foundry
Recommended Mitigation Steps
Use submit instead, as that will propagate any revert.
The Warden has demonstrated how a low-level interaction with the stETH system has not adequately handled the bool flag yielded which would indicate whether the call was successful or not, causing revert errors to be ignored.
I am not sure I fully agree with the Sponsor, as I believe certain code paths and CDP operations would result in the vulnerability regardless of the additional security checks imposed in the routers.
Specifically, a healthy CDP that has its debt increased and collateral added to it simultaneously via the ETH or WETH to stETH deposit flows would satisfy all conditions and be executed. Here’s a quick PoC that can be added to the LeverageZaps.t.sol file:
I believe that the above PoC sufficiently justifies a high severity risk rating as the funds transmitted alongside the call are lost and a CDP adjustment can leave the position in a worse-off state than the caller expected due to the unprocessed margin. To note, more PoCs can be observed in #37 and #22 that demonstrate the flaw and the possibility that funds will indeed be locked in the router.
A subset of submissions has been marked as no-reward due to lacking sufficient justification as to why the low-level interaction must be validated and how it can be exploited. Simply pointing out that the low-level call remains unchecked is insufficient for this particular vulnerability as it is identical to re-hashing static analysis output without properly understanding its ramifications.
To note, the primary submission of this duplicate set might change after PJQA as this submission details the vulnerability nicely but fails to demonstrate a valid exploitation path in its PoC.
@0xsomeone - I believe that the above PoC sufficiently justifies a high severity risk rating as the funds transmitted alongside the call are lost and a CDP adjustment can leave the position in a worse-off state than the caller expected due to the unprocessed margin.
It’s not valid, as like @GalloDaSballo stated and it’s just visible, if you adjust the position by 0 nothing worse can happen. In addition, there is a slippage ensuring that the position is as the user wants it, and a worse condition as you stated will be impossible.
What should the provided test show? This perhaps: demonstrate the flaw and the possibility that funds will indeed be locked in the router.
This is also an invalid assumption because the test will fail if the balance is not 0, since the assertion is for equality. assertEq(address(leverageZapRouter).balance, 0);
Note: to view the provided image, please see the original comment here.
Also, the probability of a low-level stETH call revert due to a pause or deposit limit is very unlikely. The current staking limit is set at 150,000 ETH, which makes it even less likely to happen. Reference this doc.
@Slavcheww, thank you for your feedback! The screenshot shared does not properly apply the PoC described as you did not perform the necessary adjustments in the CollateralTokenTester (i.e., stETH) contract for it to revert. As it is misleading, I strongly advise revising your latest feedback.
The PoC shared alongside the CollateralTokenTester adjustment demonstrates that the funds transmitted alongside the call were lost. As such, the vulnerability can lead to direct fund loss.
The likelihood of a stETH call reverting was deemed as medium-risk given that it has historically been breached (example) and is set in place for a reason.
While I am more than happy to hear opinions on and debate whether this vulnerability should be deemed medium-risk or high-risk, it is clear that the vulnerability exists.
@0xsomeone - I rechecked the whole flow and yes, the problem is there indeed.
The likelihood of a stETH call reverting was deemed as medium-risk given that it has historically been breached (example) and is set in place for a reason.
This article only announces that the stETH depositLimit is enabled at 150,000 ETH per day, which I already said. The article also clarifies that this 150 000 ETH has been set, because in the past one address deposited over 150,000 in a day and it is highly unlikely to happen again. So it only remains to happen if stETH is paused. With the user also providing a slippage for what they want to deposit, the severity of this should be Medium at maximum, in my opinion.
@Slavcheww - The slippage the user provides when it comes to leverage is not sufficient in protecting against this attack as evidenced by the PoCs.
I do understand the concerns around the likelihood of the vulnerability manifesting, however, the result of its manifestation is a direct and complete loss of native funds. Additionally, stETH is upgradeable and we cannot be sure of what the future holds with deposit limitations as it is an external project and not related to Badger.
Nevertheless, after consulting with a fellow judge I have decided to indeed reduce the severity of this submission to medium-risk. The low likelihood of the vulnerability manifesting would necessitate a critical impact (i.e. total loss of funds) which is not demonstrated here as we have a high impact (i.e. loss of funds for the caller at that particular time).
We agree with the decision above, going through various scenarios, not all scenarios would cause a loss of funds; however, some would and all are conditional on stETH being paused.
The original report as published on Code4rena, by 0xBinChook. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
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 30 seconds. 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 router used a low-level call to stake ETH with Lido and never checked the returned success flag, so a revert from Lido was silently ignored.
Impact
The user's ETH could be lost or the CDP adjustment could leave the position worse than expected, though this only happens when Lido pauses staking or exceeds its stake limit, which the report and discussion treat as unlikely.
What the attacker needed
Lido staking paused or stake limit exceeded; user calls a zap function with ETH
The fix
The code should call Lido's submit function directly so that any revert propagates, and the report notes the team agreed to fix it.
How it was found
Pause deposits on the mock Lido stETH contract to mimic Lido pausing staking or exceeding its stake limit.
Call the leveraged open CDP flow with ETH as margin.
Observe that the flow does not revert at the staking step and instead fails later on an ERC20 transfer.
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 30 seconds. 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
When a contract sends ETH to another contract, it can use a low-level call that does not automatically pass on errors. Here the router used such a call to stake ETH with Lido, so if Lido refused the deposit the router did not notice and carried on as if the stake had succeeded.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.