Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
814053f
op-deployer: add 'verify' contracts command
bitwiseguy Feb 12, 2025
6de5015
fix rate limiter values
bitwiseguy Feb 12, 2025
6cb5671
verified SuperchainConfigImplAddress
bitwiseguy Feb 13, 2025
0cb5727
verified superchain bundle (including constructor support)
bitwiseguy Feb 13, 2025
fe45a22
cleanup logs and flags
bitwiseguy Feb 13, 2025
7a96df5
cleanup: remove unused code
bitwiseguy Feb 13, 2025
510201f
verified implementations bundle
bitwiseguy Feb 14, 2025
f163c3e
verified opchain bundle
bitwiseguy Feb 14, 2025
ebd7561
update searchRemappings comment
bitwiseguy Feb 17, 2025
301a75b
use more type-safe structs
bitwiseguy Feb 17, 2025
fc284a7
use l2-chain-id flag instead of l2-chain-index
bitwiseguy Feb 17, 2025
238f331
update to use new artifacts.Download function definition
bitwiseguy Feb 25, 2025
ff014da
read constructor args from deployment tx initcode
bitwiseguy Mar 4, 2025
554ba00
return error if contract creation query fails
bitwiseguy Mar 5, 2025
63263bd
use more informative contract-name flag description
bitwiseguy Mar 5, 2025
0dfc23c
calc num constructorArgSlots by parsing abi
bitwiseguy Mar 5, 2025
824322f
add json tags (matching contract bundle) to deploy script outputs
bitwiseguy Mar 5, 2025
b329200
bootstrap default to writing to bootstrap_<command>.json file
bitwiseguy Mar 5, 2025
01e5302
pass contracts-locator flag to verify command
bitwiseguy Mar 5, 2025
a498fdd
minimize flags required for bootstrap, verify
bitwiseguy Mar 6, 2025
b2d8534
fix TestArtifactJSON
bitwiseguy Mar 6, 2025
c6af537
add etherscan unit tests
bitwiseguy Mar 6, 2025
9ecb23d
fix go lint errors
bitwiseguy Mar 6, 2025
524968b
make artifact lookup compatible with fragmented opcm
bitwiseguy Mar 6, 2025
f3968f0
fix go lint errors
bitwiseguy Mar 6, 2025
a4533d2
use require instead of assert in tests
bitwiseguy Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion op-chain-ops/foundry/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (a Artifact) MarshalJSON() ([]byte, error) {
// foundry artifacts.
type artifactMarshaling struct {
ABI json.RawMessage `json:"abi"`
Source string `json:"source"`
StorageLayout solc.StorageLayout `json:"storageLayout"`
DeployedBytecode DeployedBytecode `json:"deployedBytecode"`
Bytecode Bytecode `json:"bytecode"`
Expand All @@ -77,7 +78,7 @@ type Metadata struct {

Settings struct {
// Remappings of the contract imports
Remappings json.RawMessage `json:"remappings"`
Remappings []string `json:"remappings"`
// Optimizer settings affect the compiler output, but can be arbitrary.
// We load them opaquely, to include it in the hash of what we run.
Optimizer json.RawMessage `json:"optimizer"`
Expand All @@ -102,6 +103,7 @@ type Metadata struct {
type ContractSource struct {
Keccak256 common.Hash `json:"keccak256"`
URLs []string `json:"urls"`
Content string `json:"content"`
License string `json:"license"`
}

Expand Down Expand Up @@ -153,3 +155,27 @@ func ReadArtifact(path string) (*Artifact, error) {
}
return &artifact, nil
}

// SearchRemappings applies the configured remappings to a given source path,
// or returns the source path unchanged if no remapping is found. It assumes that
// each remapping is of the form "alias/=actualPath".
func (a Artifact) SearchRemappings(sourcePath string) string {
for _, mapping := range a.Metadata.Settings.Remappings {
parts := strings.Split(mapping, "/=")
if len(parts) != 2 {
continue
}
alias := parts[0]
if !strings.HasSuffix(alias, "/") {
alias += "/"
}
actualPath := parts[1]
if !strings.HasSuffix(actualPath, "/") {
actualPath += "/"
}
if strings.HasPrefix(sourcePath, actualPath) {
return alias + sourcePath[len(actualPath):]
}
}
return sourcePath
}

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions op-deployer/cmd/op-deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/clean"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/upgrade"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/verify"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/bootstrap"
Expand Down Expand Up @@ -66,6 +67,12 @@ func main() {
Usage: "cleans up various things",
Subcommands: clean.Commands,
},
{
Name: "verify",
Usage: "verifies deployed contracts on Etherscan",
Flags: cliapp.ProtectFlags(deployer.VerifyFlags),
Action: verify.VerifyCLI,
},
}
app.Writer = os.Stdout
app.ErrWriter = os.Stderr
Expand Down
17 changes: 6 additions & 11 deletions op-deployer/pkg/deployer/bootstrap/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

const (
OutfileFlagName = "outfile"
ArtifactsLocatorFlagName = "artifacts-locator"
WithdrawalDelaySecondsFlagName = "withdrawal-delay-seconds"
MinProposalSizeBytesFlagName = "min-proposal-size-bytes"
ChallengePeriodSecondsFlagName = "challenge-period-seconds"
Expand All @@ -19,6 +18,7 @@ const (
MIPSVersionFlagName = "mips-version"
ProxyOwnerFlagName = "proxy-owner"
SuperchainProxyAdminOwnerFlagName = "superchain-proxy-admin-owner"
L1ContractsReleaseFlagName = "l1-contracts-release"
ProtocolVersionsOwnerFlagName = "protocol-versions-owner"
GuardianFlagName = "guardian"
PausedFlagName = "paused"
Expand All @@ -33,11 +33,6 @@ var (
EnvVars: deployer.PrefixEnvVar("OUTFILE"),
Value: "-",
}
ArtifactsLocatorFlag = &cli.StringFlag{
Name: ArtifactsLocatorFlagName,
Usage: "Locator for artifacts.",
EnvVars: deployer.PrefixEnvVar("ARTIFACTS_LOCATOR"),
}
WithdrawalDelaySecondsFlag = &cli.Uint64Flag{
Name: WithdrawalDelaySecondsFlagName,
Usage: "Withdrawal delay in seconds.",
Expand Down Expand Up @@ -114,7 +109,7 @@ var (
EnvVars: deployer.PrefixEnvVar("RECOMMENDED_PROTOCOL_VERSION"),
}
L1ContractsReleaseFlag = &cli.StringFlag{
Name: "l1-contracts-release",
Name: L1ContractsReleaseFlagName,
Usage: "Release version to set OPCM implementations for, of the format `op-contracts/vX.Y.Z`.",
EnvVars: deployer.PrefixEnvVar("L1_CONTRACTS_RELEASE"),
}
Expand Down Expand Up @@ -149,7 +144,7 @@ var ImplementationsFlags = []cli.Flag{
deployer.L1RPCURLFlag,
deployer.PrivateKeyFlag,
OutfileFlag,
ArtifactsLocatorFlag,
deployer.ArtifactsLocatorFlag,
L1ContractsReleaseFlag,
MIPSVersionFlag,
WithdrawalDelaySecondsFlag,
Expand All @@ -167,15 +162,15 @@ var ProxyFlags = []cli.Flag{
deployer.L1RPCURLFlag,
deployer.PrivateKeyFlag,
OutfileFlag,
ArtifactsLocatorFlag,
deployer.ArtifactsLocatorFlag,
ProxyOwnerFlag,
}

var SuperchainFlags = []cli.Flag{
deployer.L1RPCURLFlag,
deployer.PrivateKeyFlag,
OutfileFlag,
ArtifactsLocatorFlag,
deployer.ArtifactsLocatorFlag,
SuperchainProxyAdminOwnerFlag,
ProtocolVersionsOwnerFlag,
GuardianFlag,
Expand All @@ -188,7 +183,7 @@ var ValidatorFlags = []cli.Flag{
deployer.L1RPCURLFlag,
deployer.PrivateKeyFlag,
OutfileFlag,
ArtifactsLocatorFlag,
deployer.ArtifactsLocatorFlag,
ConfigFileFlag,
}

Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/bootstrap/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func ProxyCLI(cliCtx *cli.Context) error {
l1RPCUrl := cliCtx.String(deployer.L1RPCURLFlagName)
privateKey := cliCtx.String(deployer.PrivateKeyFlagName)
outfile := cliCtx.String(OutfileFlagName)
artifactsURLStr := cliCtx.String(ArtifactsLocatorFlagName)
artifactsURLStr := cliCtx.String(deployer.ArtifactsLocatorFlagName)
cacheDir := cliCtx.String(deployer.CacheDirFlag.Name)

artifactsLocator := new(artifacts.Locator)
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/bootstrap/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func SuperchainCLI(cliCtx *cli.Context) error {

l1RPCUrl := cliCtx.String(deployer.L1RPCURLFlagName)
privateKey := cliCtx.String(deployer.PrivateKeyFlagName)
artifactsURLStr := cliCtx.String(ArtifactsLocatorFlagName)
artifactsURLStr := cliCtx.String(deployer.ArtifactsLocatorFlagName)
artifactsLocator := new(artifacts.Locator)
if err := artifactsLocator.UnmarshalText([]byte(artifactsURLStr)); err != nil {
return fmt.Errorf("failed to parse artifacts URL: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/bootstrap/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func ValidatorCLI(cliCtx *cli.Context) error {
l1RPCUrl := cliCtx.String(deployer.L1RPCURLFlagName)
privateKey := cliCtx.String(deployer.PrivateKeyFlagName)
outfile := cliCtx.String(OutfileFlagName)
artifactsURLStr := cliCtx.String(ArtifactsLocatorFlagName)
artifactsURLStr := cliCtx.String(deployer.ArtifactsLocatorFlagName)
configFile := cliCtx.String(ConfigFileFlag.Name)
cacheDir := cliCtx.String(deployer.CacheDirFlag.Name)

Expand Down
58 changes: 46 additions & 12 deletions op-deployer/pkg/deployer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import (
)

const (
EnvVarPrefix = "DEPLOYER"
L1RPCURLFlagName = "l1-rpc-url"
CacheDirFlagName = "cache-dir"
L1ChainIDFlagName = "l1-chain-id"
L2ChainIDsFlagName = "l2-chain-ids"
WorkdirFlagName = "workdir"
OutdirFlagName = "outdir"
PrivateKeyFlagName = "private-key"
IntentTypeFlagName = "intent-type"
EnvVarPrefix = "DEPLOYER"
L1RPCURLFlagName = "l1-rpc-url"
CacheDirFlagName = "cache-dir"
L1ChainIDFlagName = "l1-chain-id"
ArtifactsLocatorFlagName = "artifacts-locator"
L2ChainIDsFlagName = "l2-chain-ids"
WorkdirFlagName = "workdir"
OutdirFlagName = "outdir"
PrivateKeyFlagName = "private-key"
IntentTypeFlagName = "intent-type"
EtherscanAPIKeyFlagName = "etherscan-api-key"
InputFileFlagName = "input-file"
ContractNameFlagName = "contract-name"
)

type DeploymentTarget string
Expand All @@ -48,14 +52,15 @@ func NewDeploymentTarget(s string) (DeploymentTarget, error) {
}
}

var homeDir string
var DefaultCacheDir string

func init() {
var err error
homeDir, err = os.UserHomeDir()
homeDir, err := os.UserHomeDir()
if err != nil {
panic(fmt.Sprintf("failed to get home directory: %s", err))
}
DefaultCacheDir = path.Join(homeDir, ".op-deployer/cache")
}

var (
Expand All @@ -67,12 +72,17 @@ var (
"L1_RPC_URL",
},
}
ArtifactsLocatorFlag = &cli.StringFlag{
Name: ArtifactsLocatorFlagName,
Usage: "Locator for artifacts.",
EnvVars: PrefixEnvVar("ARTIFACTS_LOCATOR"),
}
CacheDirFlag = &cli.StringFlag{
Name: CacheDirFlagName,
Usage: "Cache directory. " +
"If set, the deployer will attempt to cache downloaded artifacts in the specified directory.",
EnvVars: PrefixEnvVar("CACHE_DIR"),
Value: path.Join(homeDir, ".op-deployer/cache"),
Value: DefaultCacheDir,
}
L1ChainIDFlag = &cli.Uint64Flag{
Name: L1ChainIDFlagName,
Expand Down Expand Up @@ -117,6 +127,22 @@ var (
"intent-config-type",
},
}
EtherscanAPIKeyFlag = &cli.StringFlag{
Name: EtherscanAPIKeyFlagName,
Usage: "etherscan API key for contract verification.",
EnvVars: PrefixEnvVar("ETHERSCAN_API_KEY"),
Required: true,
}
InputFileFlag = &cli.StringFlag{
Name: InputFileFlagName,
Usage: "filepath of input file for command",
EnvVars: PrefixEnvVar("INPUT_FILE"),
}
ContractNameFlag = &cli.StringFlag{
Name: ContractNameFlagName,
Usage: "contract name (matching a field within a contract bundle struct)",
EnvVars: PrefixEnvVar("CONTRACT_NAME"),
}
)

var GlobalFlags = append([]cli.Flag{CacheDirFlag}, oplog.CLIFlags(EnvVarPrefix)...)
Expand All @@ -141,6 +167,14 @@ var UpgradeFlags = []cli.Flag{
DeploymentTargetFlag,
}

var VerifyFlags = []cli.Flag{
L1RPCURLFlag,
ArtifactsLocatorFlag,
EtherscanAPIKeyFlag,
InputFileFlag,
ContractNameFlag,
}

func PrefixEnvVar(name string) []string {
return op_service.PrefixEnvVar(EnvVarPrefix, name)
}
Expand Down
34 changes: 34 additions & 0 deletions op-deployer/pkg/deployer/inspect/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inspect

import (
"fmt"
"reflect"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"

Expand All @@ -20,6 +21,39 @@ type L1Contracts struct {
ImplementationsDeployment ImplementationsDeployment `json:"implementationsDeployment"`
}

const (
SuperchainBundle = "superchain"
ImplementationsBundle = "implementations"
OpChainBundle = "opchain"
)

var ContractBundles = []string{
SuperchainBundle,
ImplementationsBundle,
OpChainBundle,
}

func (l L1Contracts) GetContractAddress(name string, bundleName string) (common.Address, error) {
var bundle interface{}
switch bundleName {
case SuperchainBundle:
bundle = l.SuperchainDeployment
case ImplementationsBundle:
bundle = l.ImplementationsDeployment
case OpChainBundle:
bundle = l.OpChainDeployment
default:
return common.Address{}, fmt.Errorf("invalid contract bundle type: %s", bundleName)
}

field := reflect.ValueOf(bundle).FieldByName(name)
if !field.IsValid() {
return common.Address{}, fmt.Errorf("contract %s not found in %s bundle", name, bundleName)
}

return field.Interface().(common.Address), nil
}

func (l L1Contracts) AsL1Deployments() *genesis.L1Deployments {
return &genesis.L1Deployments{
AddressManager: l.OpChainDeployment.AddressManagerAddress,
Expand Down
36 changes: 18 additions & 18 deletions op-deployer/pkg/deployer/opcm/implementations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ func (input *DeployImplementationsInput) InputSet() bool {
}

type DeployImplementationsOutput struct {
Opcm common.Address
OpcmContractsContainer common.Address
OpcmGameTypeAdder common.Address
OpcmDeployer common.Address
OpcmUpgrader common.Address
DelayedWETHImpl common.Address
OptimismPortalImpl common.Address
PreimageOracleSingleton common.Address
MipsSingleton common.Address
SystemConfigImpl common.Address
L1CrossDomainMessengerImpl common.Address
L1ERC721BridgeImpl common.Address
L1StandardBridgeImpl common.Address
OptimismMintableERC20FactoryImpl common.Address
DisputeGameFactoryImpl common.Address
AnchorStateRegistryImpl common.Address
SuperchainConfigImpl common.Address
ProtocolVersionsImpl common.Address
Opcm common.Address `json:"opcmAddress"`
OpcmContractsContainer common.Address `json:"opcmContractsContainerAddress"`
OpcmGameTypeAdder common.Address `json:"opcmGameTypeAdderAddress"`
OpcmDeployer common.Address `json:"opcmDeployerAddress"`
OpcmUpgrader common.Address `json:"opcmUpgraderAddress"`
DelayedWETHImpl common.Address `json:"delayedWETHImplAddress"`
OptimismPortalImpl common.Address `json:"optimismPortalImplAddress"`
PreimageOracleSingleton common.Address `json:"preimageOracleSingletonAddress"`
MipsSingleton common.Address `json:"mipsSingletonAddress"`
SystemConfigImpl common.Address `json:"systemConfigImplAddress"`
L1CrossDomainMessengerImpl common.Address `json:"l1CrossDomainMessengerImplAddress"`
L1ERC721BridgeImpl common.Address `json:"l1ERC721BridgeImplAddress"`
L1StandardBridgeImpl common.Address `json:"l1StandardBridgeImplAddress"`
OptimismMintableERC20FactoryImpl common.Address `json:"optimismMintableERC20FactoryImplAddress"`
DisputeGameFactoryImpl common.Address `json:"disputeGameFactoryImplAddress"`
AnchorStateRegistryImpl common.Address `json:"anchorStateRegistryImplAddress"`
SuperchainConfigImpl common.Address `json:"superchainConfigImplAddress"`
ProtocolVersionsImpl common.Address `json:"protocolVersionsImplAddress"`
}

func (output *DeployImplementationsOutput) CheckOutput(input common.Address) error {
Expand Down
10 changes: 5 additions & 5 deletions op-deployer/pkg/deployer/opcm/superchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func (dsi *DeploySuperchainInput) InputSet() bool {
}

type DeploySuperchainOutput struct {
SuperchainProxyAdmin common.Address
SuperchainConfigImpl common.Address
SuperchainConfigProxy common.Address
ProtocolVersionsImpl common.Address
ProtocolVersionsProxy common.Address
SuperchainProxyAdmin common.Address `json:"proxyAdminAddress"`
SuperchainConfigImpl common.Address `json:"superchainConfigImplAddress"`
SuperchainConfigProxy common.Address `json:"superchainConfigProxyAddress"`
ProtocolVersionsImpl common.Address `json:"protocolVersionsImplAddress"`
ProtocolVersionsProxy common.Address `json:"protocolVersionsProxyAddress"`
}

func (output *DeploySuperchainOutput) CheckOutput(input common.Address) error {
Expand Down
Loading