Skip to content
Business logic Audit finding Intermediate

TxHash collision is possible

The timelock contract computes a transaction hash from the target, value, signature, data and eta, so queueing two identical calls with the same eta produces the same hash and the second overwrites the first. An admin could be deceived into thinking two transactions are queued when only one is, and the second cannot be executed.

Madalad Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

26259 - [SC - Insight] txHash collision is possible

Submitted on Nov 29th 2023 at 18:23:56 UTC by @Madalad for Boost | DeGate

Report ID: #26259

Report type: Smart Contract

Report severity: Insight

Target: https://etherscan.io/address/0xf2991507952d9594e71a44a54fb19f3109d213a5#code

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Bug Description

If the admin wishes to make the same call more than once with the same eta, this is impossible due to the fact they would share the same txHash. The admin would have to queue the transaction, wait at least 45 days, execute it, then queue it again and wait a further 45 days.

Impact

Queueing two similar transactions causes the first to be overwritten, potentially deceiving the admin and/or users.

Risk Breakdown

Difficulty to Exploit: Easy Weakness: CVSS2 Score:

Recommendation

While it is possible to workaround this issue fairly simply, e.g. altering the eta to differ by one second, implementing some form of nonce in the hash calculation is conventional and provides the least amount of confusion/inconvenience.

References

Proof of concept

See below the proof of concept in the form of a foundry test file.

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

pragma experimental ABIEncoderV2;

import "forge-std/Test.sol";
import "../../../src/contracts/timelock/Timelock.sol";

contract CollisionTest is Test {
    Timelock public timelock;

    address public admin = makeAddr("admin");
    uint256 public delay = 45 days;

    function setUp() public {
        vm.startPrank(admin);
        timelock = new Timelock({
            admin_: admin,
            delay_: delay
        });
        vm.stopPrank();
    }

    function testCollision() public {
        // Make transaction
        address target = makeAddr("target");
        uint256 value = 0;
        string memory signature = "";
        bytes memory data = abi.encode("data");
        uint256 eta = block.timestamp + delay;

        // Queue transaction twice
        vm.startPrank(admin);
        timelock.queueTransaction(target, value, signature, data, eta);
        timelock.queueTransaction(target, value, signature, data, eta);

        // Execute first transaction
        vm.warp(block.timestamp + delay);
        timelock.executeTransaction(target, value, signature, data, eta);

        // Cannot execute second transaction
        vm.warp(block.timestamp + delay);
        vm.expectRevert("Timelock::executeTransaction: Transaction hasn't been queued.");
        timelock.executeTransaction(target, value, signature, data, eta);
    }
}

Output:

Running 1 test for test/timelock/PoCs/Collision.t.sol:CollisionTest
[PASS] testCollision() (gas: 57777)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 109.99ms
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)

The original report as published on Immunefi, by Madalad. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 transaction hash used as the queue key does not include a unique nonce, so identical calls with the same eta collide.

Impact

The second identical transaction is lost and cannot be executed, which could deceive the admin or users; no funds are lost.

What the attacker needed

Admin role on the timelock; two identical calls with the same eta

The fix

The hash calculation should include a nonce so that identical calls with the same eta do not collide.

How it was found

  1. Deploy the Timelock with an admin and a 45-day delay.
  2. Queue the same transaction twice with the same eta.
  3. Advance time by the delay and execute the first transaction.
  4. Advance time again and try to execute the second transaction; it reverts because it was overwritten.

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 timelock is a contract that makes you wait before a change takes effect. It stores each pending change under a fingerprint built from the change details and the time it becomes executable. If two changes have the same fingerprint, the second replaces the first, so one of them silently disappears.

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.

More by Madalad

View all

2 more disclosed reports, best first.

More from DeGate

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.