Introduction

This package contains the L1 and L2 smart contracts for the OP Stack. Detailed specifications for the contracts contained within this package can be found at specs.optimism.io. High-level information about these contracts can be found within this book and within the Optimism Developer Docs. For more information about contributing to OP Stack smart contract development, read on in this book.

Contributing

Contributing Guide

Contributions to the OP Stack are always welcome. Please refer to the CONTRIBUTING.md for general information about how to contribute to the OP Stack monorepo.

When contributing to the contracts-bedrock package there are some additional steps you should follow. These have been conveniently packaged into a just command which you should run before pushing your changes.

just pre-pr

Style Guide

OP Stack smart contracts should be written according to the style guide found within this book. Maintaining a consistent code style makes code easier to review and maintain, ultimately making the development process safer.

Contract Interfaces

OP Stack smart contracts use contract interfaces in a relatively unique way. Please refer to the [interfaces guide] ifaces to read more about how the OP Stack uses contract interfaces.

Solidity Versioning

OP Stack smart contracts are designed to utilize a single, consistent Solidity version. Please refer to the Solidity upgrades guide to understand the process for updating to newer Solidity versions.

Frozen Code

From time to time we need to ensure that certain files remain frozen, as they may be under audit or a large PR is in the works and we wish to avoid a large rebase. In order to enforce this, a hardcoded list of contracts is stored in ./scripts/checks/check-frozen-files.sh. Any change which affects the resulting init or source code of a contract which is not allowed to be modified will prevent merging to the develop branch.

In order to remove a file from the freeze it must be removed from the check file.

Smart Contract Style Guide

This document provides guidance on how we organize and write our smart contracts. For cases where this document does not provide guidance, please refer to existing contracts for guidance, with priority on the L2OutputOracle and OptimismPortal.

Standards and Conventions

Style

Comments

Optimism smart contracts follow the triple-slash solidity natspec comment style with additional rules. These are:

  • Always use @notice since it has the same general effect as @dev but avoids confusion about when to use one over the other.
  • Include a newline between @notice and the first @param.
  • Include a newline between @param and the first @return.
  • Use a line-length of 100 characters.

We also have the following custom tags:

  • @custom:proxied: Add to a contract whenever it's meant to live behind a proxy.
  • @custom:upgradeable: Add to a contract whenever it's meant to be inherited by an upgradeable contract.
  • @custom:semver: Add to version variable which indicate the contracts semver.
  • @custom:legacy: Add to an event or function when it only exists for legacy support.
  • @custom:network-specific: Add to state variables which vary between OP Chains.

Errors

  • Use require statements when making simple assertions.
  • Use revert(string) if throwing an error where an assertion is not being made (no custom errors). See here for an example of this in practice.
  • Error strings MUST have the format "{ContractName}: {message}" where message is a lower case string.

Function Parameters

  • Function parameters should be prefixed with an underscore.

Function Return Arguments

  • Arguments returned by functions should be suffixed with an underscore.

Event Parameters

  • Event parameters should NOT be prefixed with an underscore.

Immutable variables

Immutable variables:

  • should be in SCREAMING_SNAKE_CASE
  • should be internal
  • should have a hand written getter function

This approach clearly indicates to the developer that the value is immutable, without exposing the non-standard casing to the interface. It also ensures that we don’t need to break the ABIs if we switch between values being in storage and immutable.

Spacers

We use spacer variables to account for old storage slots that are no longer being used. The name of a spacer variable MUST be in the format spacer_<slot>_<offset>_<length> where <slot> is the original storage slot number, <offset> is the original offset position within the storage slot, and <length> is the original size of the variable. Spacers MUST be private.

Proxy by Default

All contracts should be assumed to live behind proxies (except in certain special circumstances). This means that new contracts MUST be built under the assumption of upgradeability. We use a minimal Proxy contract designed to be owned by a corresponding ProxyAdmin which follow the interfaces of OpenZeppelin's Proxy and ProxyAdmin contracts, respectively.

Unless explicitly discussed otherwise, you MUST include the following basic upgradeability pattern for each new implementation contract:

  1. Extend OpenZeppelin's Initializable base contract.
  2. Include a function initialize with the modifier initializer().
  3. In the constructor:
    1. Call _disableInitializers() to ensure the implementation contract cannot be initialized.
    2. Set any immutables. However, we generally prefer to not use immutables to ensure the same implementation contracts can be used for all chains, and to allow chain operators to dynamically configure parameters

Because reinitializer(uint64 version) is not used, the process for upgrading the implementation is to atomically:

  1. Upgrade the implementation to the StorageSetter contract.
  2. Use that to set the initialized slot (typically slot 0) to zero.
  3. Upgrade the implementation to the desired new implementation and initialize it.

Versioning

All (non-library and non-abstract) contracts MUST inherit the ISemver interface which exposes a version() function that returns a semver-compliant version string.

Contracts must have a version of 1.0.0 or greater to be production ready.

Additionally, contracts MUST use the following versioning scheme when incrementing their version:

  • patch releases are to be used only for changes that do NOT modify contract bytecode (such as updating comments).
  • minor releases are to be used for changes that modify bytecode OR changes that expand the contract ABI provided that these changes do NOT break the existing interface.
  • major releases are to be used for changes that break the existing contract interface OR changes that modify the security model of a contract.

The remainder of the contract versioning and release process can be found in `VERSIONING.md.

Exceptions

We have made an exception to the Semver rule for the WETH contract to avoid making changes to a well-known, simple, and recognizable contract.

Additionally, bumping the patch version does change the bytecode, so another exception is carved out for this. In other words, changing comments increments the patch version, which changes bytecode. This bytecode change implies a minor version increment is needed, but because it's just a version change, only a patch increment should be used.

Dependencies

Where basic functionality is already supported by an existing contract in the OpenZeppelin library, we should default to using the Upgradeable version of that contract.

Source Code

The following guidelines should be followed for all contracts in the src/ directory:

  • All state changing functions should emit a corresponding event. This ensures that all actions are transparent, can be easily monitored, and can be reconstructed from the event logs.

Tests

Tests are written using Foundry.

All test contracts and functions should be organized and named according to the following guidelines.

These guidelines are also encoded in a script which can be run with:

tsx scripts/checks/check-test-names.ts

Expect Revert with Low Level Calls

There is a non-intuitive behavior in foundry tests, which is documented here. When testing for a revert on a low-level call, please use the revertsAsExpected pattern suggested there.

Note: This is a work in progress, not all test files are compliant with these guidelines.

Organizing Principles

  • Solidity contracts are used to organize the test suite similar to how mocha uses describe.
  • Every non-trivial state changing function should have a separate contract for happy and sad path tests. This helps to make it very obvious where there are not yet sad path tests.
  • Simpler functions like getters and setters are grouped together into test contracts.

Test function naming convention

Test function names are split by underscores, into 3 or 4 parts. An example function name is test_onlyOwner_callerIsNotOwner_reverts().

The parts are: [method]_[FunctionName]_[reason]_[status], where:

  • [method] is either test, testFuzz, or testDiff
  • [FunctionName] is the name of the function or higher level behavior being tested.
  • [reason] is an optional description for the behavior being tested.
  • [status] must be one of:
    • succeeds: used for most happy path cases
    • reverts: used for most sad path cases
    • works: used for tests which include a mix of happy and sad assertions (these should be broken up if possible)
    • fails: used for tests which 'fail' in some way other than reverting
    • benchmark: used for tests intended to establish gas costs

Contract Naming Conventions

Test contracts should be named one of the following according to their use:

  • TargetContract_Init for contracts that perform basic setup to be reused in other test contracts.
  • TargetContract_Function_Test for contracts containing happy path tests for a given function.
  • TargetContract_Function_TestFail for contracts containing sad path tests for a given function.

To minimize clutter, getter functions can be grouped together into a single test contract, ie. TargetContract_Getters_Test.

Withdrawing From Fee Vaults

See the file scripts/FeeVaultWithdrawal.s.sol to withdraw from the L2 fee vaults. It includes instructions on how to run it. foundry is required.

Interfaces

This document outlines the guidelines and best practices for using and creating interfaces in the contracts-bedrock package.

Importance of Interfaces

Interfaces are valuable for developers because:

  1. They allow interaction with OP Stack contracts without importing the source code.
  2. They provide compatibility across different compiler versions.
  3. They can reduce contract compilation time.

Example of Interface Usage

Instead of importing the full contract:

import "./ComplexContract.sol";

contract MyContract {
    ComplexContract public complexContract;

    constructor(address _complexContractAddress) {
        complexContract = ComplexContract(_complexContractAddress);
    }

    function doSomething() external {
        complexContract.someFunction();
    }
}

You can use an interface:

import "./interfaces/IComplexContract.sol";`

contract MyContract {
    IComplexContract public complexContract;

    constructor(address _complexContractAddress) {
        complexContract = IComplexContract(_complexContractAddress);
    }

    function doSomething() external {
        complexContract.someFunction();
    }
}

This approach allows for interaction without being tied to the specific implementation or compiler version of ComplexContract.

Current Interface Policy

No Interface Imports in Source Contracts

Contrary to common practice, source contracts for which an interface is defined SHOULD NOT use the interface contract. This means:

  • contract Whatever is IWhatever is NOT allowed.
  • Source contracts should not use types or other definitions from their interfaces.
  • Contracts that build on base contracts (e.g., contract OtherWhatever is Whatever) should not import IWhatever or IOtherWhatever.

Correct Implementation Example

Instead of:

import "./IWhatever.sol";

contract Whatever is IWhatever {
    // Implementation
}

Do this:

contract Whatever {
    // Direct implementation without importing interface
}

Reasons for This Policy

  1. Automation Potential: We aim to auto-generate interfaces in the future. Importing interfaces into source contracts would prevent this automation by creating a circular dependency.

  2. ABI Compatibility: Achieving 1:1 compatibility between interface and source contract ABI becomes problematic when the source contract imports other contracts along with the interface. This is due to Solidity's handling of function redefinitions. See Example of ABI Compatibility Issue below for more context.

Example of ABI Compatibility Issue

contract SomeBaseContract {
    event SomeEvent();
}

interface IWhatever {
    event SomeEvent();
    function someOtherFunction() external;
}

contract Whatever is IWhatever, SomeBaseContract {
    function someOtherFunction() external {}
}

In this case, Solidity will return the following compilation error:

DeclarationError: Event with same name and parameter types defined twice.

Importing External Interfaces

Contracts CAN import interfaces for OTHER contracts. This practice helps mitigate compilation time issues in older Solidity versions. As Solidity improves, we plan to phase out this exception.

Example of Allowed Interface Usage

import "./IOtherContract.sol";

contract MyContract {
    IOtherContract public otherContract;

    constructor(address _otherContractAddress) {
        otherContract = IOtherContract(_otherContractAddress);
    }

    // Rest of the contract
}

Creating Interfaces

You have several options for creating interfaces:

  1. Use cast interface:

    cast interface ./path/to/contract/artifact.json
    
  2. Use forge inspect:

    forge inspect <ContractName> abi --pretty
    
  3. Create the interface manually:

    interface IMyContract {
        function someFunction() external;
        function anotherFunction(uint256 _param) external returns (bool);
        // ... other functions and events
    }
    

Regardless of the method chosen, ensure that your ABIs are a 1:1 match with their source contracts.

NOTE: Using cast interface or forge inspect can fail to preserve certain types like enum values. You may need to manually fix these issues or CI will complain.

Verifying Interface Accuracy

To check if all interfaces match their source contracts:

  • Run just interface-check or just interface-check-no-build

These commands will compare the ABIs of your interfaces with their corresponding source contracts and report any discrepancies.

Future Goals

Our long-term objectives for interfaces include:

  1. Automating interface generation
  2. Using interfaces only for external users, not internally
  3. Eliminating the need for interface imports in source contracts

Until we achieve these goals, we maintain the current policy to balance development efficiency and compilation time improvements.

OP Contracts Manager (OPCM)

The OPCM is an important smart contract that is used to orchestrate OP Chain deployments and upgrades. It is responsible for the following:

  1. Keeping track of the canonical implementation contracts for each contracts release.
  2. Deploying new L1 contracts for each OP Chain.
  3. Upgrading from one contract release to another.
  4. Maintaining the fault proof system by adding game types or updating prestates.

All contract upgrades that touch live chains must be performed via the OPCM. This guide will walk you through the OPCM's architecture, and how to hook your contracts into it.

Architecture

The OPCM consists of multiple contracts:

  1. OPContractsManager, which serves as the entry point.
  2. OPContractsManagerGameTypeAdder, which is used to add new game types and update prestates.
  3. OPContractsManagerDeployer, which is used to deploy new OP Chains.
  4. OPContractsManagerUpgrader, which is used to upgrade existing OP Chains.
  5. OPContractsManagerContractsContainer, which is a repository for contract implementations and blueprints.

They fit together like the diagram below:

stateDiagram-v2
    state OpContractsManager {
        direction LR
        deploy() --> OpContractsManagerDeployer: staticcall
        upgrade() --> OpContractsManagerUpgrader: delegatecall
        addGameType() --> OpContractsManagerGameTypeAdder: delegatecall
        updatePrestate() --> OpContractsManagerGameTypeAdder: delegatecall
    }

    state Logic {
        OpContractsManagerDeployer --> OpContractsManagerContractsContainer: getImplementations()/getBlueprints()
        OpContractsManagerUpgrader --> OpContractsManagerContractsContainer: getImplementations()/getBlueprints()
        OpContractsManagerGameTypeAdder --> OpContractsManagerContractsContainer: getImplementations()/getBlueprints()
    }

    state Implementations {
        OpContractsManagerContractsContainer
    }

One OPCM is deployed per smart contract release per chain. Each OPCM supports deploying a new chain at its corresponding smart contract release, and upgrading existing chains from one version prior to its corresponding smart contract release. Chains that are multiple versions behind must be upgraded in multiple stages across multiple OPCMs.

The OPCM supports upgrading Superchain-wide contracts like ProtocolVersions and the SuperchainConfig. The OPCM will perform the upgrade when the user calling the upgrade method is also the UpgradeController.

Usage

Typically, users do not call into the OPCM directly. Instead, they use OP Deployer to either directly call deploy when spinning up a new chain or generate calldate for use with upgrade.

If you want to call the OPCM directly, check out the implementation to see exactly what the inputs and outputs are to each method. This changes between releases, and will not be covered directly here.

Updating the OPCM

Whenever you make updates to in-protocol contracts, you'll need to make corresponding changes inside the OPCM. While the details of each change will vary, we've included some general guidelines below.

Updating Logic Contracts

As their name implies, the logic contracts contain the actual logic used to deploy or upgrade contracts. When modifying these contracts keep the following tips in mind:

  • The deploy method can typically be modified in-place since the deployment process doesn't change much from release to release. For example, most changes to the deploy method will involve either adding a new contract or modifying the constructor/initializer for existing contracts. You can use the existing implementation as a guide.
  • The upgrade method changes much more frequently. That said, you can still use the existing implementation as a guide. Just make sure to delete any old upgrade code that is no longer needed. The OPContractsManagerUpgrader logic contract also contains helpers for things like deploying new dispute games and upgrading proxies to new implementations. See the upgradeTo method for an example.
  • The upgrade method will always set the RC on the OPCM to false when called by the upgrade controller. It will only sometimes (depending on your specific upgrade) upgrade Superchain contracts.

Fork Tests

The OPCM is tested using fork tests. These tests fork mainnet and "run" the upgrade against OP Mainnet. This allows us to validate that the upgrades work as expected in CI prior to deploying them to betanets or production.

To run fork tests, run just test-upgrade. You will need to set ETH_RPC_URL to an archival mainnet node.

When multiple upgrades are in flight at the same time, the fork tests stack upgrades on top of one another. Since the tip of develop must contain the implementation for the latest upgrade only, fork tests that run upgrades prior to the latest one must use deployed instances of the OPCM. For example, as of this writing upgrades 13, 14, and 15 are all in flight. Therefore, the fork tests will use deployed versions of the OPCM for upgrades 13 and 14 and whatever is on develop for upgrade 15. See OPContractsManager.t.sol for the implementation of the fork tests.

Solidity Versioning Policy

This document outlines the process for proposing and implementing Solidity version updates in the OP Stack codebase.

Unified Solidity Version

The OP Stack codebase maintains a single, unified Solidity version across all contracts and components. This ensures consistency, simplifies maintenance, and reduces the risk of version-related issues.

Important: New Solidity versions must not be introduced to any part of the codebase without going through the formal version update proposal process outlined in this document.

Update Process

  1. Minimum Delay Period: A new Solidity version must be at least 6 months old before it can be considered for adoption.
  2. Proposal Submission: Before any Solidity version upgrades are made, a detailed proposal must be submitted as a pull request to the ethereum-optimism/design-docs repository in the solidity/ subfolder, following the standardized format outlined below. This applies to the entire codebase; individual components or contracts cannot be upgraded separately.
  3. Review and Approval: A dedicated review panel will assess the proposal based on the following criteria:
    • Is the Solidity version at least 6 months old?
    • Does the proposed upgrade provide clear value to the codebase?
    • Do any new features or bug fixes pose an unnecessary risk to the codebase?
  4. Implementation: If the proposal receives unanimous approval from the review panel, the Solidity version upgrade will be implemented across the entire OP Stack codebase.

Proposal Submission Guidelines

To submit a Solidity version upgrade proposal, create a new pull request to the ethereum-optimism/design-docs repository, adding a new file in the solidity/ subfolder. Please use the dedicated Solidity update proposal format. Ensure that all sections are filled out comprehensively. Incomplete proposals may be delayed or rejected.

Review Process

The review panel will evaluate each proposal based on the criteria mentioned in the "Review and Approval" section above. They may request additional information or clarifications if needed.

Implementation

If approved, the Solidity version upgrade will be implemented across the entire OP Stack codebase. This process will be managed by the development team to ensure consistency and minimize potential issues. The upgrade will apply to all contracts and components simultaneously.

Smart Contract Code Freeze Process

The Smart Contract Freeze Process is used to protect specific files from accidental changes during sensitive periods.

Code Freeze

Code freezes are implemented by comparison of the bytecode and source code hashes of the local file against the upstream files.

To enable a code freeze, follow these steps:

  1. Create a PR.
  2. The semver-lock.json file should already be up to date, but run anyway just semver-lock to be sure.
  3. Comment out the path and filename of the file/s you want to freeze in check-frozen-files.sh.

To disable a code freeze, comment out the path and filename of the file/s you want to unfreeze in check-frozen-files.sh.

  1. Create a PR.
  2. Uncomment the path and filename of all files in check-frozen-files.sh.

Exceptions

To bypass the freeze you can apply the "M-exempt-frozen-files" label on affected PRs. This should be done upon agreement with the code owner. Expected uses of this exception are to fix issues found on audits or to add comments to frozen files.

Smart Contract Versioning and Release Process

The Smart Contract Versioning and Release Process closely follows a true semver for both individual contracts and monorepo releases. However, there are some changes to accommodate the unique nature of smart contract development and governance cycles.

There are five parts to the versioning and release process:

[!NOTE] The rules described in this document must be enforced manually. Ideally, a check can be added to CI to enforce the conventions defined here, but this is not currently implemented.

Semver Rules

Version increments follow the style guide rules for when to bump major, minor, and patch versions in individual contracts:

  • patch releases are to be used only for changes that do NOT modify contract bytecode (such as updating comments).
  • minor releases are to be used for changes that modify bytecode OR changes that expand the contract ABI provided that these changes do NOT break the existing interface.
  • major releases are to be used for changes that break the existing contract interface OR changes that modify the security model of a contract.

Bumping the patch version does change the bytecode, so another exception is carved out for this. In other words, changing comments increments the patch version, which changes bytecode. This bytecode change implies a minor version increment is needed, but because it's just a version change, only a patch increment should be used.

Individual Contract Versioning

Individual contract versioning allows us to uniquely identify which version of a contract from the develop branch corresponds to each deployed contract instance.

Versioning for individual contracts works as follows:

  • A contract on develop always has a version of X.Y.Z, regardless of whether is has been governance approved and meets our security bar. This DOES NOT indicate these contracts are always safe for production use. More on this below.
  • For contracts with feature-specific changes, a +feature-name identifier must be appended to the version number. See the Smart Contract Feature Development design document to learn more.
  • When making changes to a contract, always bump to the lowest possible version based on the specific change you are making. We do not want to e.g. optimistically bump to a major version, because protocol development sequencing may change unexpectedly. Use these examples to know how to bump the version:
    • Example 1: A contract is currently on 1.2.3 on develop and you are working on a new feature on your feature branch off develop.
      • We don't yet know when the next release of this contract will be. However, you are simply fixing typos in comments so you bump the version to 1.2.4.
      • The next commit to the feature branch clarifies some comments. We only consider the aggregated feature changes with regards to develop when determining the version, so we stay at 1.2.4.
      • The next commit to the feature branch introduces a breaking change, which bumps the version from 1.2.4 to 2.0.0.
    • Example 2: A contract is currently on 2.4.7.
      • We know the next release of this contract will be a breaking change. Regardless, as you start development by fixing typos in comments, bump the version to 2.4.8. This is because we may end up putting out a release before the breaking change is added.
      • Once you start working on the breaking change, bump the version to 3.0.0.
  • New contracts start at 1.0.0.

Versioning is enforced by CI checks:

  • Any contract that differs from its version in the develop branch must be bumped to a new semver value, or the build will fail.
  • Any branch with at least one modified contract must have its semver-lock.json file updated, or the build will fail. You can use the semver-lock or pre-commit just commands to do so.

Note: Previously, the versioning scheme included -beta.n and -rc.n qualifiers. These are no longer used to reduce the amount of work required to execute this versioning system.

Deprecating Individual Contract Versioning

Individual contract versioning could be deprecated when the following conditions are met:

  1. Every OPCM instance is registered in the superchain registry
  2. All contracts are implemented as either proxies or concrete singletons, allowing verification of governance approval through the OPCM.Implementations struct
  3. We have validated with engineering teams (such as the fault proofs team) and ecosystem partners (such as L2Beat) that removing version() functions would not negatively impact their workflows

Monorepo Contracts Release Versioning

Versioning for monorepo releases works as follows:

  • Monorepo releases continue to follow the op-contracts/vX.Y.Z naming convention.
  • The version used for the next release is determined by the highest version bump of any individual contract in the release.
    • Example 1: The monorepo is at op-contracts/v1.5.0. Clarifying comments are made in contracts, so all contracts only bump the patch version. The next monorepo release will be op-contracts/v1.5.1.
    • Example 2: The monorepo is at op-contracts/v1.5.1. Various tech debt and code is cleaned up in contracts, but no features are added, so at most, contracts bumped the minor version. The next monorepo release will be op-contracts/v1.6.0.
    • Example 3: The monorepo is at op-contracts/v1.5.1. Legacy ALL_CAPS() getter methods are removed from a contract, causing that contract to bump the major version. The next monorepo release will be op-contracts/v2.0.0.
  • Feature specific monorepo releases (such as a release of the custom gas token feature) are supported, and should follow the guidelines in the Smart Contract Feature Development design doc. Bump the overall monorepo semver as required by the above rules. For example, if the last release before the custom gas token feature was op-contracts/v1.5.1, because the custom gas token introduces breaking changes, its release will be op-contracts/v2.0.0.
    • A subsequent release of the custom gas token feature that fixes bugs and introduces an additional breaking change would be op-contracts/v3.0.0.
    • This means +feature-name naming is not used for monorepo releases, only for individual contracts as described below.
  • A monorepo contracts release must map to an exact set of contract semvers, and this mapping must be defined in the contract release notes which are the source of truth. See op-contracts/v1.4.0-rc.4 for an example of what release notes should look like.

Optimism Contracts Manager (OPCM) Versioning

The OPCM is the contract that manages the deployment of all contracts on L1.

The OPCM is the source of truth for the contracts that belong in a release, available as on-chain addresses by querying the getImplementations function.

When developing a new release of the contracts, the isRC flag must be set to true to indicate that the OPCM refers to a release candidate. The flag is automatically set to false the first time the OPCM upgrade method is invoked from governance's Upgrade Controller Safe. This Safe is a 2/2 held by the Security Council and Optimism Foundation.

Release Process

When a release is proposed to governance, the proposal includes a commit hash, and often the contracts from that commit hash are already deployed to mainnet with their addresses included in the proposal. For example, the Fault Proofs governance proposal provides specific addresses that will be used.

To accommodate this, once contract changes are ready for governance approval, the release flow is:

  1. Go to https://github.com/ethereum-optimism/optimism/releases/new
  2. Enter the release title as op-contracts/vX.Y.Z-rc.1
  3. In the "choose a tag" dropdown, enter the same op-contracts/vX.Y.Z-rc.1 and click the "Create new tag" option that shows up
  4. Populate the release notes.
  5. Check "set as pre-release" since it's not yet governance approved
  6. Uncheck "Set as the latest release" and "Create a discussion for this release".
  7. Click publish release.
  8. After governance vote passes, edit the relase to uncheck "set as pre-release", and remove the -rc.1 tag.

Although the tools exist to apply a code freeze to specific contracts, this is discouraged. If a change is required to a release candidate after it has been tagged, the Additional Release Candidates for more information on this flow.

Additional Release Candidates

Sometimes additional release candidate versions are needed, in that case, the follow process should be used. This process is designed to (1) ensures fixes are made on both the release and the trunk branch and (2) avoids the need to stop development efforts on the trunk branch.

  1. Make the fixes on develop. For whatever the normal semver level increment should be, bump that value by 5.
  2. Create a new release branch, named proposal/op-contracts/X.Y.Z-rc.n+1 off of the rc tag.
  3. Cherry pick the fixes from develop into that branch. *Bump the semvers as normal, ensuring that the resulting version is less than the one on develop.
  4. After merging the changes into the new release branch, tag the resulting commit on the proposal branch as op-contracts/vX.Y.Z-rc.2. Create a new release for this tag per the instructions above.

Note: The reason for the larger semver increment on develop is to prevent a collision, wherein a contract could have the same semver, but different source/bytecode on the two branches.

For example: if the current version of a contract is 1.1.1 and a minor bump is required (most common for a bug fix), then the fixed version should become 1.8.0 on develop. Then on the release branch is should become 1.2.0.

Merging Back to Develop After Governance Approval

A release will change a set of contracts, and those contracts may have changed on develop since the release candidate was created.

If there have been no changes to a contract since the release candidate, the version of that contract stays at X.Y.Z and just has the -rc.n removed. For example, if the release candidate is 1.2.3-rc.1, the resulting version on develop will be 1.2.3.

If there have been changes to a contract, the X.Y.Z will stay the same as whatever is the latest version on develop, with the -beta.n qualifier incremented.

For example, given that ContractA is 1.2.3-rc.1 on develop, then the initial sequence of events is:

  • We create the release branch, and on that branch remove the -rc.1, giving a final ContractA version on that branch of 1.2.3
  • Governance proposal is posted, pointing to the corresponding monorepo tag.
  • Governance approves the release.
  • Open a PR to merge the final versions of the contracts (ContractA) back into develop.

Now there are two scenarios for the PR that merges the release branch back into develop:

  1. On develop, no changes have been made to ContractA. The PR therefore changes ContractA's version on develop from 1.2.3-rc.1 to 1.2.3, and no other changes to ContractA occur.
  2. On develop, breaking changes have been made to ContractA for a new feature, and it's currently versioned as 2.0.0-beta.3. The PR should bump the version to 2.0.0-beta.4 if it changes the source code of ContractA.
    • In practice, this one unlikely to occur when using inheritance for feature development, as specified in Smart Contract Feature Development architecture. It's more likely that (1) is the case, and we merge the version change into the base contract.

This flow also provides a dedicated branch for each release, making it easy to deploy a patch or bug fix, regardless of other changes that may have occurred on develop since the release.