Skip to content
Access control Audit finding Intermediate

State transition manager is unable to force upgrade a deployed ST, which invalidates the designed safeguard for ‘urgent high risk situation’

The StateTransitionManager contract lacks a method to force upgrade a deployed state transition contract, despite documentation stating it should be able to in urgent high-risk situations. This means a chain could postpone or avoid an upgrade, invalidating the designed safeguard.

oakcobalt Follow

Originally disclosed on Code4rena

Submitted by oakcobalt

Impact

State transition manager (STM) will be unable to force upgrade a deployed ST against intended design for ‘urgent high risk situation’.

This invalidates the designed safeguard mechanism of an STM force upgrade and ST.

Proof of Concept

According to doc, in case of urgent high risk situation, STM might force upgrade the contract(ST).

However, the above safeguard of force upgrading ST is not possible due to StateTransitionManger.sol’s incomplete implementation.

(1) A deployed chain(ST) can choose to perform a mandatory upgrade at its own convenience. It’s also possible for an ST to postpone an upgrade set by the state transition manager. An ST will perform an upgrade through upgradeChainFromVersion() on the Admin facet.

//code/contracts/ethereum/contracts/state-transition/chain-deps/facets/Admin.sol
    function upgradeChainFromVersion(
        uint256 _oldProtocolVersion,
        Diamond.DiamondCutData calldata _diamondCut
|>    ) external onlyAdminOrStateTransitionManager {
...

(https://github.com/code-423n4/2024-03-zksync/blob/4f0ba34f34a864c354c7e8c47643ed8f4a250e13/code/contracts/ethereum/contracts/state-transition/chain-deps/facets/Admin.sol#L103) Note that although upgradeChainFromVersion() is access-controlled by both chain admin and StateTransitionManager contract. StateTransitionManager will not be able to call it, because no methods or flows on StateTransitionManger.sol will invoke the call.

(2) Another method on Admin facet for upgrade is executeUpgrade() which is access-controlled by only StateTransitionManager contract. However, executeUpgrade() can only be invoked inside _setChainIdUpgrade(). And _setChainIdUpgrade() can only be invoked inside createNewChain(). This means, after a chain(ST)‘s genesis, executeUpgrade() cannot be invoked by stateTransitionManger again to perform further upgrades.

//code/contracts/ethereum/contracts/state-transition/chain-deps/facets/Admin.sol
    function executeUpgrade(
        Diamond.DiamondCutData calldata _diamondCut
|>    ) external onlyStateTransitionManager {
        Diamond.diamondCut(_diamondCut);
        emit ExecuteUpgrade(_diamondCut);
    }

(https://github.com/code-423n4/2024-03-zksync/blob/4f0ba34f34a864c354c7e8c47643ed8f4a250e13/code/contracts/ethereum/contracts/state-transition/chain-deps/facets/Admin.sol#L123)

    function _setChainIdUpgrade(
        uint256 _chainId,
        address _chainContract
    ) internal {
...
          //@audit executeUpgrade of an ST will only be called once at chain deployment, because _setChainIdUpgrade() is only invoked when creating a new chain.
|>        IAdmin(_chainContract).executeUpgrade(cutData);
...

(https://github.com/code-423n4/2024-03-zksync/blob/4f0ba34f34a864c354c7e8c47643ed8f4a250e13/code/contracts/ethereum/contracts/state-transition/StateTransitionManager.sol#L226)

As a result of (1)&(2), StateChainManager cannot force upgrade an ST in case of urgent high risk situation. This invalidates the safeguard of force upgrade as stated by doc.

Recommended Mitigation Steps

In StateTransitionManager.sol, add a method that can call executeUpgrade() or upgradeChainFromVersion() on a local chain.

saxenism (zkSync) confirmed and commented:

Agree with the finding. Thank you :)

0xsomeone (judge) commented:

The Warden has demonstrated how, in an urgent high-risk situation, a forced upgrade cannot be performed in contradiction with the project’s documentation.

Based on the fact that the vulnerability is correct and would surface in a low-likelihood scenario, a medium-risk assessment is appropriate.


The original report as published on Code4rena, by oakcobalt. 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 StateTransitionManager contract does not expose any function that calls the upgrade functions on a deployed state transition contract after its creation.

Impact

In an urgent high-risk situation, the state transition manager cannot force an upgrade, so the intended safeguard is invalidated; the report notes this would surface in a low-likelihood scenario.

What the attacker needed

Urgent high-risk situation; deployed state transition contract

The fix

Add a method in StateTransitionManager.sol that can call executeUpgrade() or upgradeChainFromVersion() on a local chain.

How it was found

  1. A state transition contract is deployed via createNewChain, which calls _setChainIdUpgrade and then executeUpgrade once.
  2. After deployment, the state transition manager has no function to call executeUpgrade or upgradeChainFromVersion on that contract.
  3. The state transition contract can choose when to upgrade or postpone an upgrade set by the manager.

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 state transition manager is a smart contract that oversees other contracts (state transitions) on a blockchain. The documentation says it can force an urgent upgrade if there is a high-risk situation, but the code does not provide a way to do that after the initial deployment. So the safety mechanism does not work as intended.

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 oakcobalt

View all

50 more disclosed reports, best first.

More from zkSync Era

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.