Skip to content
Business logic Audit finding Intermediate

sfrxETH: The volatile result of previewMint() may prevent mintWithSignature from working

The previewMint() function's result changes with contract state, making the amount volatile in mintWithSignature when approveMax is false. A user's signed transaction can revert if a prior transaction in the same block alters the state so that previewMint(shares) differs from the signed amount.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by rotcivegaf, Trust, and wagmi

In sfrxETH contracts, the result of previewMint() changes with the state of the contract, which causes the value of amount to be volatile in the mintWithSignature function when approveMax is false.

And when using the mintWithSignature function, which requires the user to sign for an accurate amount value, when the amount used differs from the result of previewMint(), mintWithSignature will not work.

Consider the following scenarios.

User A signs using amount = 1000 and calls the mintWithSignature function.

During execution, the previous transaction in the same block changes the state of the contract so that previewMint(shares) == 1001, so the transaction is reverted due to a signature check failure.

Proof of Concept

https://github.com/code-423n4/2022-09-frax/blob/55ea6b1ef3857a277e2f47d42029bc0f3d6f9173/src/sfrxETH.sol#L75-L87

https://github.com/transmissions11/solmate/blob/bff24e835192470ed38bf15dbed6084c2d723ace/src/mixins/ERC4626.sol#L140-L144

Recommended Mitigation Steps

Consider that in the mintWithSignature function, the user provides a maxAmount, and then requires maxAmount >= previewMint(shares) and uses maxAmount to verify the signature.

FortisFortuna (Frax) acknowledged and commented:

Technically correct, though in practice, we will allow user-defined slippage on the UI.

0xean (judge) commented:

I don’t believe the UI will be able to assist with this issue unless modifications are made to the smart contracts. The signature will become invalidated due to the return value of previewMint() changing while the transaction is waiting to be included in a block.


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

Impact

A user's mintWithSignature transaction could revert if the contract state changes before execution, preventing the mint from succeeding.

What the attacker needed

User signs a mintWithSignature transaction; approveMax is false; contract state changes before execution

The fix

The mintWithSignature function should accept a user-provided maxAmount, require maxAmount >= previewMint(shares), and use maxAmount to verify the signature.

How it was found

  1. User A signs using amount = 1000 and calls the mintWithSignature function.
  2. During execution, the previous transaction in the same block changes the state of the contract so that previewMint(shares) == 1001.
  3. The transaction is reverted due to a signature check failure.

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.

This is a smart contract bug. A user signs a message authorising a specific amount of tokens to mint. But the amount the contract calculates can change between signing and execution, so the signature no longer matches and the transaction fails.

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 cccz

View all

104 more disclosed reports, best first.

More from Frax Ether Liquid Staking contest

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.