Skip to content
DoS Audit finding Beginner

Withdrawing ETH collateral with max uint256 amount value reverts transaction

Withdrawing ETH collateral using the maximum uint256 amount causes the transaction to revert because the code tries to call decimals() on the zero address, which is not a valid token. An attacker could not exploit this for gain, but it prevents legitimate withdrawals of the full ETH balance.

berndartmueller Follow

Originally disclosed on Code4rena

Submitted by berndartmueller, also found by WatchPug

Withdrawing ETH collateral via the withdrawCollateral function using type(uint256).max for the _amount parameter reverts the transaction due to _asset being the zero-address and IERC20Detailed(_asset).decimals() not working for native ETH.

Proof of Concept

GeneralVault.sol#L121-L124

if (_amount == type(uint256).max) {
    uint256 decimal = IERC20Detailed(_asset).decimals(); // @audit-info does not work for native ETH. Transaction reverts
    _amount = _amountToWithdraw.mul(this.pricePerShare()).div(10**decimal);
}

Recommended mitigation steps

Check _asset and use hard coded decimal value (18) for native ETH.

sforman2000 (Sturdy) confirmed

atozICT20 (Sturdy) commented:

Fix the issue of transaction fails due to calculate ETH’s decimals sturdyfi/code4rena-may-2022#7

hickuphh3 (judge) commented:

Good find! Stated in _asset description that null address is interpreted as ETH, which isn’t a token, and therefore reverts when attempting to fetch its decimals.


The original report as published on Code4rena, by berndartmueller. 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.

How it worked

Root cause

The code assumes the asset is an ERC20 token and calls decimals() on it, but for native ETH the asset address is zero, which has no such function.

Impact

Users cannot withdraw their full ETH collateral in a single transaction using the maximum amount value; the transaction reverts.

What the attacker needed

User has ETH collateral deposited; User attempts to withdraw full amount

The fix

The code should check if the asset is native ETH and use a hardcoded decimal value of 18 instead of calling decimals().

How it was found

  1. Call withdrawCollateral with _amount set to type(uint256).max for native ETH.
  2. The function checks if _amount equals max and then calls decimals() on the zero address.
  3. The call reverts because the zero address does not implement decimals().

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 withdraw all your ETH from a smart contract, the code tries to look up how many decimal places ETH has, but ETH is not a token contract, so the lookup fails and the whole withdrawal is cancelled. This means you cannot withdraw your full ETH balance in one go.

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.

More by berndartmueller

View all

97 more disclosed reports, best first.

More from Sturdy contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.