Skip to content
Access control Audit finding Advanced

Initialize function in L2GraphToken.sol , BridgeEscrow.sol , L2GraphTokenGateway.sol , L1GraphTokenGateway.sol can be invoked multiple times from the implementation contract

The initialize functions in four upgradeable contracts lack the initializer modifier, allowing them to be called multiple times from the implementation contract. If the implementation contract is compromised, an attacker could reinitialize the contracts, become the governor, and drain GRT tokens from BridgeEscrow.

ladboy233 Follow

Originally disclosed on Code4rena

Submitted by ladboy233, also found by csanuragjain

L2GraphTokenGateway.sol#L87 L2GraphToken.sol#L48 L1GraphTokenGateway.sol#L99 BridgeEscrow.sol#L20

Initialize function in L2GraphToken.sol, BridgeEscrow.sol, L2GraphTokenGateway.sol, and L1GraphTokenGateway.sol can be invoked multiple times from the implementation contract. This means a compromised implementation can reinitialize the contract above and become the owner to complete the privilege escalation then drain the user’s fund.

Usually in Upgradeable contract, an initialize function is protected by the modifier

 initializer

to make sure the contract can only be initialized once.

Proof of Concept

  1. The implementation contract is compromised,
  2. The attacker reinitialize the BridgeEscrow contract
    function initialize(address _controller) external onlyImpl {
        Managed._initialize(_controller);
    }

the onlyGovernor modifier’s result depends on the controller because

    function _onlyGovernor() internal view {
        require(msg.sender == controller.getGovernor(), "Caller must be Controller governor");
    }
  1. The attacker has the governor access to the BridgeEscrow,
  2. The attack can call the approve function to approve malicious contract
     function approveAll(address _spender) external onlyGovernor {
        graphToken().approve(_spender, type(uint256).max);
    }
  1. The attack can drain all the GRT token from the BridgeEscrow.

Recommended Mitigation Steps

We recommend the project use the modifier

 initializer

to protect the initialize function from being reinitiated

   function initialize(address _owner) external onlyImpl initializer  {

0xean (judge) commented:

Sponsor - please also review #72 which is a duplicate but has a slightly different impact statement to the same underlying issue.

pcarranzav (The Graph) confirmed and commented:

The impact from #72 was discussed with a warden and I consider it valid and worth fixing.

The impact from this one requires the implementation to be compromised in a way that allows calling initialize(). Since all implementations use GraphUpgradeable, I don’t see how that’s possible without also compromising the GraphProxyAdmin and therefore compromising the governor, which would mean much bigger problems.

I still consider this risky enough that a Medium severity is reasonable, both in #72 and this one.

Trust (warden) commented:

Exploit of this bug requires ProxyAdmin compromise, and if attacker has that then there are many ways to severely damage the proxy. It’s a good observation and should be fixed, but it seems to be a best practice issue.

pcarranzav (The Graph) resolved and commented:

Fix PRd in https://github.com/graphprotocol/contracts/pull/741

0xean (judge) commented:

@Trust - makes reasonable points, but I think it’s still correct to award this as Medium.

Trust (warden) reviewed mitigation:

Fixed in standalone PR. Fixed by using OpenZeppelin’s initializer guard in contracts BridgeEscrow, L1GraphTokenGateway, L2GraphTokenGateway and L2GraphToken.


The original report as published on Code4rena, by ladboy233. 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 initialize functions in the four contracts lack the initializer modifier, allowing them to be called multiple times.

Impact

If the implementation contract is compromised, an attacker could reinitialize the contracts, become governor, and drain all GRT tokens from BridgeEscrow; however, the sponsor notes this requires compromising the GraphProxyAdmin, which would already imply severe damage.

What the attacker needed

Compromise of implementation contract; Compromise of GraphProxyAdmin

The fix

The contracts were fixed by using OpenZeppelin’s initializer guard in BridgeEscrow, L1GraphTokenGateway, L2GraphTokenGateway, and L2GraphToken.

How it was found

  1. Compromise the implementation contract.
  2. Reinitialize the BridgeEscrow contract by calling its initialize function.
  3. Gain governor access to BridgeEscrow.
  4. Call approveAll to approve a malicious contract to spend GRT tokens.
  5. Drain all GRT tokens from BridgeEscrow.

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.

Upgradeable smart contracts often have an initialize function that sets up the contract once, similar to a constructor. This report found that the initialize functions in several contracts could be called more than once, which is dangerous if an attacker gains control of the implementation contract. The attacker could then reset the contract's owner and steal funds.

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 ladboy233

View all

47 more disclosed reports, best first.

More from The Graph L2 bridge 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.