Skip to content
Access control Audit finding Intermediate

Some setters’ timelock can be bypassed

The timelock mechanism for setting privileged addresses in several contracts could be bypassed by the owner. An attacker with owner privileges could set a new minter or distributor without waiting for the intended delay, reducing the notice period for such changes.

zzzitron Follow

Originally disclosed on Code4rena

Submitted by zzzitron, also found by berndartmueller, GimelSec, GiveMeTestEther, and sseefried

https://github.com/code-423n4/2022-07-golom/blob/7bbb55fca61e6bae29e57133c1e45806cbb17aa4/contracts/governance/GolomToken.sol#L58-L72

https://github.com/code-423n4/2022-07-golom/blob/7bbb55fca61e6bae29e57133c1e45806cbb17aa4/contracts/core/GolomTrader.sol#L444-L457

https://github.com/code-423n4/2022-07-golom/blob/7bbb55fca61e6bae29e57133c1e45806cbb17aa4/contracts/rewards/RewardDistributor.sol#L298-L311

MED - Function could be impacted

As the timelock does not work as supposed to work, the owner of the contract can bypass timelock.

  • Affected Functions:

    • GolomToken: setMinter, executeSetMinter
    • GolomTrader: setDistributor, executeSetDistributor
    • RewardDistributor: addVoteEscrow, executeAddVoteEscrow

Proof of Concept

The first poc shows to bypass timelock for GolomTrader::setDistributor. The same logic applies for the RewardDistributor::addVoteEscrow. 0. The setDistributor was called once in the beforeEach block to set the initial distributor. For this exploit to work, the setDistributor should be called only once. If setDistributor was called more than once, one can set the distributor to zero address (with timelock like in the GolomToken case, then set to a new distributor after that)

  1. reset distributor to zero address without timelock by calling executeSetDistributor
  2. set a new distributor without timelock by calling setDistributor
  3. Rinse and repeat: as long as setDistributor is not called multiple times in row, the owner can keep setting distributor without timelock.

A little bit different variation of timelock bypass was found in the GolomToken. Although the owner should wait for the timelock to set the minter to zero address, but after that, the owner can set to the new minter without waiting for a timelock. Since the meaning of timelock is to let people know the new minter’s implementation, if the owner can bypass that, the timelock is almost meaningless. The exploitation steps: the second proof of concept

  1. call setMineter with zero address
  2. wait for the timelock
  3. call executeSetMineter to set the minter to zero address
  4. now the onwer can call setMineter with any address and call executeSetMinter without waiting for the timelock

The owner can call executeSetdistributor even though there is no pendingDistributor set before. Also, setDistributor sets the new distributor without timelock when the existing distributor’s address is zero.

// GolomTrader
// almost identical logic was used in `RewardDistributor` to addVoteEscrow
// similar logic was used in `GolomToken` to `setMineter`

444     function setDistributor(address _distributor) external onlyOwner {
445         if (address(distributor) == address(0)) {
446             distributor = Distributor(_distributor);
447         } else {
448             pendingDistributor = _distributor;
449             distributorEnableDate = block.timestamp + 1 days;
450         }
451     }
452
453     /// @notice Executes the set distributor function after the timelock
454     function executeSetDistributor() external onlyOwner {
455         require(distributorEnableDate <= block.timestamp, 'not allowed');
456         distributor = Distributor(pendingDistributor);
457     }

Recommended Mitigation Steps

To mitigate, execute functions can check whether pendingDistributor is not zero. It will ensure that the setters are called before executing them, as well as prevent to set to zero addresses.

0xsaruman (Golom) disputed and commented:

call setMineter with zero address wait for the timelock

This alone will trigger awareness that something malicious is happening and since timelock is there people have time to get out.

0xsaruman (Golom) confirmed and commented:

The second POC is valid.

0xsaruman (Golom) resolved and commented:

Removed all secondary time locks in the contract and only using the primary timelock that will be behind the owner.

https://github.com/golom-protocol/contracts/commit/366c0455547041003c28f21b9afba48dc33dc5c7#diff-94d75c3059a714c355bd15d139c30d4f9899df283d29717622ffd5c930445499R59


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

Likely the setter functions allow setting the privileged address to zero without a timelock, and the execute functions do not require a pending address to be set, so the owner can reset and then set a new address immediately.

Impact

The owner could bypass the timelock and change critical addresses without the intended delay, reducing the notice period for users.

What the attacker needed

Owner privileges

The fix

The execute functions should check that the pending address is not zero, ensuring setters are called before executing and preventing setting to zero addresses.

How it was found

  1. Call setDistributor to set the distributor to the zero address without a timelock.
  2. Call executeSetDistributor to reset the distributor to zero.
  3. Call setDistributor again with a new address, which now sets it without a timelock.
  4. Repeat as long as setDistributor is not called multiple times in a row.

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 delay that gives people time to see and react to a change before it happens. Here, the delay could be skipped by first setting the address to zero and then setting a new one, so the protection was ineffective.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by zzzitron

View all

21 more disclosed reports, best first.

More from Golom contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.