Unordered Nonces open up to further MEV risks
The PermitC contract allows nonces to be executed out of order, so when a victim signs multiple permits, an attacker can choose the order that leaves allowances non-zero or causes transactions to revert. This can lead to unintended token claims or bridging, and enables MEV extraction.
Originally disclosed on Code4rena
Submitted by GalloDaSballo
While a great effort was made to mitigate out of order nonce execution, the reality is that since PermitC allows unordered nonces, then nonces could be executed out of order. This opens up more problems than the original Permit Exploit. The original Permit exploit allowed to effectively always make multi-operations revert. This new scenario instead allows to use the order of nonces that will cause the most damage.
The most basic example would be using the reverse order to keep allowances to be non-zero. This may open up to more exploits, an example being claiming TAP, twTAP or rewards to router addresses by keeping the allowance as non-zero. Additionally, any time more than one Permit is issued, a race condition is available. This race condition would allow an exploiter to consume the nonces out of order, and then causes the transaction to revert. This, in contrast to the previous iteration, allows all possible sequences of combinations of allowances to determine the final result, while the original permit operation would allow only the proper sequence to be executed (with pauses between each step).
This additional risk can create scenarios in which outstanding allowance is left, which could incorrectly signal the willingness to claim tokens or the willingness to allow a target to bridge funds at a different time than intended. It’s worth reiterating how Signatures can be executed as soon as made available on any mempool, whether a L2 or LayerZeros system.
POC
- Victim signs Permit A, B and C.
- Notice how any of the permutations of
[A, B, C]could be used out of order. - Front-runner will execute those signatures at whichever order is best for them to leak the most value.
Mitigation
The only solution I have found is to ensure that all “Macros” in Magnetar always approve a specific contract at most once. Revokes are done without signatures, either by consuming the allowance via a transferFrom (which may not be possible) or by introducing a function that allows an operator to reset their allowance.
Assessed type
MEV
0xRektora (Tapioca) acknowledged and commented:
If I remember correctly, the team from Limit Break did not build
PermitCto have batched transaction, but it can be dangerous if implemented wrong. Will forward the message.As for Tapioca, we do have a batch function in
Pearlmitthat will force the signatures to be verified against the order they were sent to.We believe the solution to the griefing scenario would be to use something like
permitTransferFromWithAdditionalDataERC20on said batch, by effectively binding the whole Tx (approvals paired with compose messages) and force the approval to be executed only in the case, which would nullify the front-running incentives.
0xRektora (Tapioca) commented:
Limit Break answer —
Yes - as designed it’s explicitly allowed to use unordered nonces, so this would be valid. A modification could be made to the
_checkAndInvalidateNoncefunction if you want to do ordered where you have a tracker by account and make sure thatnonce == nextNonce[owner]but we don’t want that for our base case as unordered nonces are required to execute orders out of sequence.
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 PermitC contract does not enforce sequential nonce usage, allowing permits to be executed in any order.
Impact
This could allow an attacker to leave allowances non-zero, potentially leading to unintended token claims or bridging, and enables MEV extraction through out-of-order execution.
What the attacker needed
Victim signs multiple permits; attacker can front-run transactions
The fix
The only solution found is to ensure that all “Macros” in Magnetar always approve a specific contract at most once, and revokes are done without signatures.
How it was found
- Victim signs Permit A, B and C.
- Notice how any of the permutations of [A, B, C] could be used out of order.
- Front-runner will execute those signatures at whichever order is best for them to leak the most value.
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 sign a permit, you authorise someone to spend your tokens. If you sign several permits, they are supposed to be used in a specific order. Here, the system allows them to be used in any order, so an attacker can pick the order that benefits them, possibly leaving your tokens at risk.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.