Skip to content
Race condition Audit finding Intermediate

EIP712MetaTransaction.executeMetaTransaction() failed txs are open to replay attacks

A meta-transaction that fails during execution does not increment the signer's nonce, so the same signed transaction can be replayed later. An attacker could replay a previously failed transaction when conditions change, causing the signer's funds to be spent unexpectedly.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

Any transactions that fail based on some conditions that may change in the future are not safe to be executed again later (e.g. transactions that are based on others actions, or time-dependent etc).

In the current implementation, once the low-level call is failed, the whole tx will be reverted and so that _nonces[metaAction.from] will remain unchanged.

As a result, the same tx can be replayed by anyone, using the same signature.

EIP712MetaTransaction.sol#L86

    function executeMetaTransaction(
        MetaAction memory metaAction,
        bytes32 r,
        bytes32 s,
        uint8 v
    ) external payable returns (bytes memory) {
        require(
            _verify(metaAction.from, metaAction, r, s, v),
            "signer and signature don't match"
        );

        uint256 currentNonce = _nonces[metaAction.from];

        // intentionally allow this to overflow to save gas,
        // and it's impossible for someone to do 2 ^ 256 - 1 meta txs
        unchecked {
            _nonces[metaAction.from] = currentNonce + 1;
        }

        // Append the metaAction.from at the end so that it can be extracted later
        // from the calling context (see _msgSender() below)
        (bool success, bytes memory returnData) = address(this).call(
            abi.encodePacked(
                abi.encodeWithSelector(
                    IController(address(this)).operate.selector,
                    metaAction.actions
                ),
                metaAction.from
            )
        );

        require(success, "unsuccessful function call");
        emit MetaTransactionExecuted(
            metaAction.from,
            payable(msg.sender),
            currentNonce
        );
        return returnData;
    }

See also the implementation of OpenZeppelin’s MinimalForwarder:

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/metatx/MinimalForwarder.sol#L42-L66

Proof of Concept

Given:

  • The collateral is USDC;
  • Alice got 10,000 USDC in the wallet.
  • Alice submitted a MetaTransaction to operate() and _mintOptionsPosition() with 10,000 USDC;
  • Before the MetaTransaction get executed, Alice sent 1,000 USDC to Bob;
  • The MetaTransaction submited by Alice in step 1 get executed but failed;
  • A few days later, Bob sent 1,000 USDC to Alice;
  • The attacker can replay the MetaTransaction failed to execute at step 3 and succeed.

Alice’s 10,000 USDC is now been spent unexpectedly against her will and can potentially cause fund loss depends on the market situation.

Recommended Mitigation Steps

Failed txs should still increase the nonce.

While implementating the change above, consider adding one more check to require sufficient gas to be paid, to prevent “insufficient gas griefing attack” as described in this article.

0xca11 (Rolla) confirmed, resolved, and commented:

Meta transactions replay and insufficient gas griefing attacks are now prevented since RollaProject/quant-protocol#80.


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

Alice's 10,000 USDC could be spent unexpectedly against her will, potentially causing fund loss depending on market conditions.

What the attacker needed

A signed meta-transaction that failed; conditions change so it would succeed; attacker can submit the replay

The fix

Failed transactions should still increase the nonce, and the report also suggests requiring sufficient gas to prevent insufficient gas griefing; the project confirmed these were fixed.

How it was found

  1. Alice signs a meta-transaction to operate() with 10,000 USDC.
  2. Before it executes, Alice sends 1,000 USDC to Bob, so the meta-transaction fails.
  3. Days later, Bob sends 1,000 USDC back to Alice.
  4. An attacker replays the previously failed meta-transaction, which now succeeds.

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.

A meta-transaction lets someone else submit a transaction on your behalf using your signature. The contract keeps a counter (nonce) to ensure each signature is used only once. Here, if the transaction fails, the counter is not increased, so the same signed transaction can be submitted again later and might succeed then.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Rolla contest

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.