Skip to content
Race condition Audit finding Advanced

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.

GalloDaSballo Follow

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 PermitC to 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 Pearlmit that 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 permitTransferFromWithAdditionalDataERC20 on 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 _checkAndInvalidateNonce function if you want to do ordered where you have a tracker by account and make sure that nonce == nextNonce[owner] but we don’t want that for our base case as unordered nonces are required to execute orders out of sequence.


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

  1. Victim signs Permit A, B and C.
  2. Notice how any of the permutations of [A, B, C] could be used out of order.
  3. 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.

More by GalloDaSballo

View all

30 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.