Skip to content
Business logic Audit finding Intermediate

LibDiamond.diamondCut() should check diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] != 0

The diamondCut function checks that the acceptance time is less than the current block timestamp, but a rescinded cut sets the acceptance time to zero, which passes the check. Also, if no proposal was ever made, the acceptance time is zero and the check passes. This allows a malicious or compromised governance to bypass the delay and execute arbitrary cuts immediately.

GimelSec Follow

Originally disclosed on Code4rena

Submitted by GimelSec, also found by csanuragjain, Czar102, Lambda, minhquanym, and shenwilly

LibDiamond.sol#L100-L103 LibDiamond.sol#L71-L79 LibDiamond.sol#L83-L90

Normally, diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] will be set in LibDiamond.proposeDiamondCut(). Then in LibDiamond.diamondCut(), it checks that diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] < block.timestamp.

However, LibDiamond.rescindDiamondCut() will set diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] to 0. Which can easily pass the check in diamondCut(). But rescindDiamondCut should rescind _diamondCut. In conclusion, using rescindDiamondCut() can easily bypass the delay time.

Moreover, if proposeDiamondCut() has never been called, the check for delay time is always passed.

Proof of Concept

diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] will be set in LibDiamond.proposeDiamondCut() LibDiamond.sol#L71-L79

  function proposeDiamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
  ) internal {
    uint256 acceptance = block.timestamp + _delay;
    diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] = acceptance;
    emit DiamondCutProposed(_diamondCut, _init, _calldata, acceptance);
  }

Then in LibDiamond.diamondCut(), it checks that diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] < block.timestamp LibDiamond.sol#L100-L103

  function diamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
  ) internal {
    require(
      diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] < block.timestamp,
      "LibDiamond: delay not elapsed"
    );
    …
  }

However, LibDiamond.rescindDiamondCut() will set diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] to 0. Which can easily pass the check in diamondCut() LibDiamond.sol#L83-L90 function rescindDiamondCut( IDiamondCut.FacetCut[] memory *diamondCut, address _init, bytes memory _calldata ) internal { diamondStorage().acceptanceTimes[keccak256(abi.encode(*diamondCut))] = 0; emit DiamondCutRescinded(_diamondCut, _init, _calldata); }

diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] = 0 < block.timestamp

Recommended Mitigation Steps

Add another check in diamondCut

  function diamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
  ) internal {
    require(
      diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] < block.timestamp && diamondStorage().acceptanceTimes[keccak256(abi.encode(_diamondCut))] != 0,
      "LibDiamond: delay not elapsed"
    );
    …
  }

LayneHaber (Connext) confirmed

jakekidd (Connext) resolved:

Resolved by connext/nxtp@cde1353

0xleastwood (judge) decreased severity to Medium and commented:

I believe this issue to be valid but of medium severity as it requires a malicious or compromised governance. This issue would allow the protocol’s admin to propose and execute any arbitrary data within the same transaction.


The original report as published on Code4rena, by GimelSec. 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 check in diamondCut only verifies that the acceptance time is less than the current block timestamp, but does not ensure that the acceptance time is non-zero, so a zero value (from a rescinded or never-proposed cut) passes the check.

Impact

A malicious or compromised governance could bypass the delay and execute arbitrary diamond cuts immediately.

What the attacker needed

Malicious or compromised governance

The fix

The diamondCut function should also require that the acceptance time is not zero.

How it was found

  1. Call proposeDiamondCut to set an acceptance time in the future.
  2. Call rescindDiamondCut to set the acceptance time to zero.
  3. Call diamondCut with the same cut; the check passes because zero is less than the current timestamp.

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 has a delay mechanism to give users time to review changes before they are applied. The check for whether the delay has passed is flawed: it only checks if the stored time is in the past, but a value of zero (meaning no proposal or a cancelled proposal) also passes. So an attacker with governance power could apply changes instantly without waiting.

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 GimelSec

View all

18 more disclosed reports, best first.

More from Connext Amarok contest

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.