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.
- 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.
// 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)
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
- Deploy the Timelock with an admin and a 45-day delay.
- Queue the same transaction twice with the same eta.
- Advance time by the delay and execute the first transaction.
- 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.