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.
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
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.
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.
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
- 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.
- 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.