Skip to content
Business logic Audit finding Intermediate

No slippage protection on stake() in SafEth.sol

The stake() function lacks a minimum mint amount parameter, so users have no protection against receiving fewer safETH tokens if the underlying derivative prices move unfavourably between transaction submission and execution. An attacker could exploit this by manipulating derivative prices or front-running to cause stakers to receive less than expected.

RaymondFam Follow with rbserver, d3e4 and 11 others

Originally disclosed on Code4rena

Submitted by RaymondFam, also found by rbserver, d3e4, 0xepley, whoismatthewmc1, Parad0x, handsomegiraffe, silviaxyz, BPZ, yac, Franfran, RedTiger, ladboy233, and fyvgsk

mintAmount is determined both by totalStakeValueEth and preDepositPrice. While the former is associated with external interactions beyond users’ control, the latter should be linked to a slippage control to incentivize more staker participations.

Proof of Concept

As can be seen from the code block below, ethPerDerivative() serves to get the price of each derivative in terms of ETH. Although it is presumed the prices entailed would be closely/stably pegged 1:1, no one could guarantee the degree of volatility just as what has recently happened to the USDC depeg.

File: SafEth.sol#L71-L81

        for (uint i = 0; i < derivativeCount; i++)
            underlyingValue +=
                (derivatives[i].ethPerDerivative(derivatives[i].balance()) *
                    derivatives[i].balance()) /
                10 ** 18;

        uint256 totalSupply = totalSupply();
        uint256 preDepositPrice; // Price of safETH in regards to ETH
        if (totalSupply == 0)
            preDepositPrice = 10 ** 18; // initializes with a price of 1
        else preDepositPrice = (10 ** 18 * underlyingValue) / totalSupply;

When underlyingValue is less than totalSupply, preDepositPrice will be smaller and inversely make mintAmount bigger, and vice versa.

Any slight change in price movement in the same direction can be consistently cumulative and reflective in stake calculations. This can make two stakers calling stake() with the same ETH amount minutes apart getting minted different amount of stake ERC20 tokens.

Recommended Mitigation Steps

Consider having a user inputtable minMintAmountOut added in the function parameters of stake() and the function logic refactored as follows:

-    function stake() external payable {
+    function stake(uint256 minMintAmountOut) external payable {

        [... Snipped ...]

        _mint(msg.sender, mintAmount);
+        require(shares >= minSharesOut, "mint amount too low");

        [... Snipped ...]

Ideally, this slippage calculation should be featured in the UI, with optionally selectable stake amount impact, e.g. 0.1%.

Asymmetry mitigated:

Pass in minAmount.

Status: Incorrectly mitigated. Full details in reports from d3e4 (here and here) and adriro - and also shared below in the Mitigation Review section.


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

Likely the stake() function calculates the mint amount based on current derivative prices without allowing the user to specify a minimum acceptable amount, leaving them exposed to price slippage.

Impact

Stakers could receive fewer safETH tokens than expected due to price movements, and an attacker could potentially exploit this by manipulating prices or front-running to cause losses.

What the attacker needed

None

The fix

The function should be modified to accept a user-supplied minimum mint amount and revert if the calculated mint amount is below it.

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 stake ETH in this contract, the amount of safETH tokens you get depends on the current value of the underlying assets. If those assets lose value while your transaction is pending, you could get fewer tokens than you expected. This report says the function should let you specify a minimum number of tokens you are willing to accept, so you are protected from such price changes.

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.

More by RaymondFam

View all

18 more disclosed reports, best first.

More from Asymmetry Finance afETH Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.