Skip to content
Audit finding Beginner

Timelock contract should use canExecuteTransact

The report argues that the Timelock contract's executeTransaction function repeats several separate require checks that could instead be consolidated into a single call to the existing canExecuteTransaction helper. The author claims this would reduce gas costs, but shows no measured saving and no security impact.

shanb1605 Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

29318 - [SC - Insight] Timelock contract should use canExecuteTransact...

Submitted on Mar 13th 2024 at 22:35:50 UTC by @shanb1605 for Boost | Immunefi Arbitration

Report ID: #29318

Report type: Smart Contract

Report severity: Insight

Target: https://github.com/immunefi-team/vaults/blob/main/src/Timelock.sol

Impacts:

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

Description

Brief/Intro

The Timelock contract's executeTransaction() has multiple checks before executing a transaction:

Solidity
        require(txData.state == TxState.Queued, "Timelock: transaction is not queued");
        require(
            txData.queueTimestamp + txData.cooldown <= block.timestamp,
            "Timelock: transaction is not yet executable"
        );
        require(
            txData.expiration == 0 || txData.queueTimestamp + txData.cooldown + txData.expiration > block.timestamp,
            "Timelock: transaction is expired"
        );
        
         require(!vaultFreezer.isFrozen(vault), "Timelock: vault is frozen");

Instead of these multiple checks immunefi should consider using canExecuteTransaction()

Vulnerability Details

Using multiple require statements may cost too much gas to execute transaction.

Impact Details

Immunefi promises to offer a smooth arbitration between the project and Whitehat, using multiple require statements will cost too much gas to execute.

Recommendation

Immunefi can add this snippet if they wish to handle this as a single require statement:

Solidity
require(canExecuteTransaction(txHash) == true);

Proof of Concept

I have commented out unnecessary require statements on executeTransaction() and added a single line of code as per recommendation.

Also, I have changed the function visibility of canExecuteTransaction()from external to public

Solidity
    function executeTransaction(bytes32 txHash) external {
        TxStorageData memory txData = txHashData[txHash];
        //Fix
        require(canExecuteTransaction(txHash) == true, "!F");

        /*
        require(txData.state == TxState.Queued, "Timelock: transaction is not queued");
        require(
            txData.queueTimestamp + txData.cooldown <= block.timestamp,
            "Timelock: transaction is not yet executable"
        );
        require(
            txData.expiration == 0 || txData.queueTimestamp + txData.cooldown + txData.expiration > block.timestamp,
            "Timelock: transaction is expired"
        );*/

        (address to, uint256 value, bytes memory data, Enum.Operation operation, address vault) = abi.decode(
            txData.execData,
            (address, uint256, bytes, Enum.Operation, address)
        );

        require(msg.sender == vault, "Timelock: only vault can execute transaction");
        //require(!vaultFreezer.isFrozen(vault), "Timelock: vault is frozen");

        txHashData[txHash].state = TxState.Executed;

        emit TransactionExecuted(txHash, to, vault, value, data, operation);
        immunefiModule.execute(vault, to, value, data, operation);
    }

    function canExecuteTransaction(bytes32 txHash) public view returns (bool) {
        TxStorageData memory txData = txHashData[txHash];
        (, , , , address vault) = abi.decode(txData.execData, (address, uint256, bytes, Enum.Operation, address));
        return
            !vaultFreezer.isFrozen(vault) &&
            txData.state == TxState.Queued &&
            txData.queueTimestamp + txData.cooldown <= block.timestamp &&
            (txData.expiration == 0 || txData.queueTimestamp + txData.cooldown + txData.expiration > block.timestamp);
    }

Run forge test --mp test/foundry/Timelock.t.sol and everything works fine :)

The original report as published on Immunefi, by shanb1605. 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 function duplicates validation logic that already exists in a helper, rather than a genuine vulnerability.

Impact

The only claimed effect is slightly higher gas use when executing a transaction; no loss of funds or bypass is demonstrated.

What the attacker needed

None

The fix

The author suggests replacing the separate checks with a single call to the existing canExecuteTransaction helper, made public.

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 is a program on a blockchain, and every instruction costs a small fee called gas. This report says one function checks the same conditions in several separate steps and suggests combining them into one helper function to save a little gas. It is a style and efficiency suggestion, not a security flaw.

More by shanb1605

View all

3 more disclosed reports, best first.

More from Immunefi Arbitration

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.