Skip to content

design doc for the ocpm superchain upgrade fix #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

AmadiMichael
Copy link
Member

design doc for the ocpm superchain upgrade fix

@AmadiMichael AmadiMichael requested review from mds1 and maurelian July 29, 2025 12:52

This means all upgrades from that OPCM is not possible any longer.

## Proposed Solution
Copy link
Contributor

@maurelian maurelian Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we talk about a solution, we first need to outline the requirements. Please try to list the various situations we need to consider, and the correct behaviour in each situation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you re-review?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Towards @maurelian's point, can we move the "Requirements and Expected behaviour" above, so it comes before "Proposed Solution"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I see now that the "Requirements and Expected behaviour" is really talking about the Requirements and Expected behaviour needed to successfully implement the proposed solution. I believe what @maurelian is asking for (which I agree with) is a section that comes before "Proposed Solution" to explain what customer and developer requirements are, i.e. for various situations what is the expected behavior when calling upgrade? In slack @maurelian gave some scenarios, here are a few to start with:

Scenario Number PAO == superchainPAO? Target version is latest? SuperchainConfig already on latest? Expected Output
1 Yes Yes Yes TODO
2 Yes Yes No TODO
3 No Yes Yes TODO
4 No Yes No TODO
5 Yes No Yes TODO
6 Yes No No TODO
7 No No Yes TODO
8 No No No TODO

What should happen in each of those scenarios? It would be great to include a table like this will all the TODOs populated.

Can you think through any other missing scenarios (i.e. headers), and add the completed version to a new "Customer Requirements and Expected Behavior" section before "Proposed Solution"? I think we can also delete the "Requirements and Expected behaviour" header and make that part of the "Proposed Solution" header.

I just really want to make sure we are clear on the "Customer Requirements and Expected Behavior" before agreeing on a solution, and we'll want to get approval from Product on this design doc as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, makes for a nice flowchart

graph TD
    A{PAO == superchainPAO?}
    A -- Yes --> B{Target version is latest?}
    A -- No  --> E{Target version is latest?}

    B -- Yes --> C{SuperchainConfig already upgraded?}
    B -- No  --> D{SuperchainConfig already upgraded?}

    E -- Yes --> F{SuperchainConfig already upgraded?}
    E -- No  --> G{SuperchainConfig already upgraded?}

    C -- Yes --> S1["TODO"]
    C -- No  --> S2["TODO"]

    D -- Yes --> S5["TODO"]
    D -- No  --> S6["TODO"]

    F -- Yes --> S3["TODO"]
    F -- No  --> S4["TODO"]

    G -- Yes --> S7["TODO"]
    G -- No  --> S8["TODO"]
Loading

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed the table

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second column here doesn't make sense to me.
In any situation where the ChainAPAO != superchainPAO you will always get a revert if you are trying to upgrade contracts with a different PAO.

The more relevant consideration is ChainAProxyAdmin == superchainProxyAdmin?, because that determines whether or not the current interface enables us to access the superchainProxyAdmin.


| Scenario | Description | Expected Behavior |
|----------|-------------|------------------|
| Dedicated SuperchainConfig ProxyAdmin | A SuperchainConfig has its own ProxyAdmin that is not shared with any of it's OP chains | When OPCM.upgrade() is called by this SuperchainProxyAdminOwner, it should check if the SuperchainConfig is already upgraded via a isSuperchainUpgraded mapping. If not upgraded, it should upgrade the SuperchainConfig and set isSuperchainUpgraded for that SuperchainConfig to true. No other contract upgrades would occur since this ProxyAdmin only controls the SuperchainConfig. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When OPCM.upgrade() is called... If not upgraded, it should upgrade the SuperchainConfig...

How can we achieve that? AFAIK there is no way of getting the SuperchainProxyAdmin address from within the upgrade() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

achieve what in particular?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we upgrade the superchainConfig, if the SuperchainConfigProxyAdmin is not shared with the OP Chain? I don't think we can unless we add an argument to upgrade()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we call upgrade with the superchainPAO and pass in an empty opChainConfig array

## Failure Mode Analysis

- **Protecting the `setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function from being called directly by a malicious actor:**
- Explainer: The way the OPCM sets the `isSuperchainUpgraded` variable is by calling `OPCMUpgrader.setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function. This is safe and does not need checks because if a malicious actor tries doing this, it will fail when trying to actually upgrade the superchainConfig. However, A malicious actor could call the `setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function directly (not via an OPCM upgrade call) to set the `isSuperchainUpgraded` variable to true for any superchainConfig while not being that Superchain's ProxyAdmin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is safe and does not need checks because if a malicious actor tries doing this, it will fail when trying to actually upgrade the superchainConfig

This seems to imply that the upgrade itself happens within setSuperchainUpgraded() is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nope, i was talking about when calling the setSuperchainUpgraded from the upgrade function. it is safe since the upgrade will happen next and if the caller is not the superchainProxyAdmin, the tx will revert


- **Protecting the `setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function from being called directly by a malicious actor:**
- Explainer: The way the OPCM sets the `isSuperchainUpgraded` variable is by calling `OPCMUpgrader.setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function. This is safe and does not need checks because if a malicious actor tries doing this, it will fail when trying to actually upgrade the superchainConfig. However, A malicious actor could call the `setSuperchainUpgraded(ISuperchainConfig superchainConfig)` function directly (not via an OPCM upgrade call) to set the `isSuperchainUpgraded` variable to true for any superchainConfig while not being that Superchain's ProxyAdmin.
- Mitigation: The obvious way to do this is to check that the msg.sender is the Superchain's ProxyAdmin. This is possible for future OPCM versions because the proxyAdmin variable is accessible via the SuperchainConfig contract. For v2.0.0 and v4.0.0, this is not possible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this. If the mitigation is impossible, what can we actually do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am still looking into it currently

- The SuperchainConfig's implementation is Impl0
- The OPCM has stored Impl1 as the implementation to upgrade to

If ChainA's proxyAdmin (also the SuperchainConfig's ProxyAdmin) calls the OPCM's `upgrade()` function, the check above (if (superchainProxyAdmin.getProxyImplementation(address(superchainConfig)) != impls.superchainConfigImpl)) will be true and it will upgrade the SuperchainConfig to Impl1 and also upgrade ChainA's L1 contracts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We say ProxyAdmin a lot in this section, but is it correct that really it's the ProxyAdmin Owner that matter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

- The OPCM's `upgrade()` function is called and the SuperchainConfig's implementation is upgraded to Impl2
- A new chain, ChainC comes in or is behind and has to use the old OPCM first

When it calls the OPCM's `upgrade()` function, the check above (if (superchainProxyAdmin.getProxyImplementation(address(superchainConfig)) != impls.superchainConfigImpl)) will be true and it will attempt to upgrade the SuperchainConfig which will fail since it's ProxyAdmin will not be the SuperchainConfig's ProxyAdmin.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, implicit here is that ChainC has a different ProxyAdmin Owner (PAO)—let's state that explicitly for clarity

We should also explain what happens when ChainC has the same PAO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Comment on lines +83 to +90
A proposed solution for this is to change the check:
- Create a variable `bool isSuperchainUpgraded` in the OPCMUpgrader contract.
- When `OPCM.upgrade()` is called, it delegates call to `OPCMUpgrader.upgrade()` as usual.
- `OPCMUpgrader.upgrade()` calls back into itself (to be able to access it's storage) and checks if the superchainConfig is already upgraded by checking the `isSuperchainUpgraded` variable.
- If it is not upgraded, it calls back into itself once more to set the `isSuperchainUpgraded` variable to true and then upgrade the superchainConfig.
- If it is already upgraded, it will skip the upgrade and continue execution.

While at it, it is proposed to also add support for different superchainConfigs i.e different Superchains. We can easily do this by replacing the `isSuperchainUpgraded` variable with a mapping `mapping(ISuperchainConfig superchainConfig => bool isSuperchainUpgraded)`. This way we can check which superchainConfig is being upgraded and set the `isSuperchainUpgraded` variable to true for that superchainConfig while also preventing the same superchainConfig from being upgraded again.
Copy link
Contributor

@mds1 mds1 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm the control flow here feels a bit confusing and error prone. Is there a solution where we add inputs so the caller can simply specify whether they want to try upgrading the superchainConfig, with the following logic:

  • Add bool shouldUpgradeSuperchainConfig as an input to the upgrade method`
  • If isRc == false, this input value MUST be true. Revert if this condition is violated
  • Otherwise, proceed to do the upgrade as normal and try upgrading superchainConfig when requested
  • Note: Downside here is that chains with their own superchainConfig must remember to manually pass in true for this new bool

Alternatively, can we just make the (superchainProxyAdmin.getProxyImplementation(address(superchainConfig)) != impls.superchainConfigImpl)) check smarter to do a greater than/less than semver comparison instead of strict inequality?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but we want to try not changing the interface at all

Copy link
Contributor

@mds1 mds1 Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, so would it be fair to say there's two solutions here:

  • Short term patches for the existing OPCM where we don't want to change the interface
  • Longer term solution (i.e. for all future OPCMs) where we are ok with breaking the interface to simplify things. In these future OPCMs, we can read the PAO from any contract, therefore we can keep the interfaces the same and just have smarter internal logic about when to upgrade?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly

}
```

## Requirements and Expected behaviour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this section since we added a similar one above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants