-
Notifications
You must be signed in to change notification settings - Fork 3.9k
op-deployer: add command to verify contracts on etherscan #14359
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8e0bbaa
op-deployer: add 'verify' contracts command
bitwiseguy 0db1736
fix rate limiter values
bitwiseguy a24f8fb
verified SuperchainConfigImplAddress
bitwiseguy 4821991
verified superchain bundle (including constructor support)
bitwiseguy 00e04e2
cleanup logs and flags
bitwiseguy 8ca109e
cleanup: remove unused code
bitwiseguy e232930
verified implementations bundle
bitwiseguy 9ee5079
verified opchain bundle
bitwiseguy 40dbf87
update searchRemappings comment
bitwiseguy 275b090
use more type-safe structs
bitwiseguy c4d0c69
use l2-chain-id flag instead of l2-chain-index
bitwiseguy b9226fe
update to use new artifacts.Download function definition
bitwiseguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package verify | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "path" | ||
| "strings" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-chain-ops/foundry" | ||
| ) | ||
|
|
||
| type contractArtifact struct { | ||
| ContractName string | ||
| CompilerVersion string | ||
| Optimizer OptimizerSettings | ||
| EVMVersion string | ||
| StandardInput string | ||
| ConstructorArgs string | ||
| } | ||
|
|
||
| // Map state.json struct's contract field names to forge artifact names | ||
| var contractNameExceptions = map[string]string{ | ||
| "OptimismPortalImpl": "OptimismPortal2", | ||
| "L1StandardBridgeProxy": "L1ChugSplashProxy", | ||
| "L1CrossDomainMessengerProxy": "ResolvedDelegateProxy", | ||
| "Opcm": "OPContractsManager", | ||
| } | ||
|
|
||
| func getArtifactName(name string) string { | ||
| lookupName := strings.TrimSuffix(name, "Address") | ||
|
|
||
| if artifactName, exists := contractNameExceptions[lookupName]; exists { | ||
| return artifactName | ||
| } | ||
|
|
||
| lookupName = strings.TrimSuffix(lookupName, "Proxy") | ||
| lookupName = strings.TrimSuffix(lookupName, "Impl") | ||
| lookupName = strings.TrimSuffix(lookupName, "Singleton") | ||
|
|
||
| // If it was a proxy and not a special case, return "Proxy" | ||
| if strings.HasSuffix(name, "ProxyAddress") { | ||
| return "Proxy" | ||
| } | ||
|
|
||
| return lookupName | ||
| } | ||
|
|
||
| func (v *Verifier) getContractArtifact(name string) (*contractArtifact, error) { | ||
| artifactName := getArtifactName(name) | ||
| artifactPath := path.Join(artifactName+".sol", artifactName+".json") | ||
|
|
||
| v.log.Info("Opening artifact", "path", artifactPath, "name", name) | ||
| f, err := v.artifactsFS.Open(artifactPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to open artifact: %w", err) | ||
| } | ||
| defer f.Close() | ||
|
|
||
| var art foundry.Artifact | ||
| if err := json.NewDecoder(f).Decode(&art); err != nil { | ||
| return nil, fmt.Errorf("failed to decode artifact: %w", err) | ||
| } | ||
|
|
||
| // Add all sources (main contract and dependencies) | ||
| sources := make(map[string]SourceContent) | ||
| for sourcePath, sourceInfo := range art.Metadata.Sources { | ||
| remappedKey := art.SearchRemappings(sourcePath) | ||
| sources[remappedKey] = SourceContent{Content: sourceInfo.Content} | ||
| v.log.Debug("added source contract", "originalPath", sourcePath, "remappedKey", remappedKey) | ||
| } | ||
|
|
||
| var optimizer OptimizerSettings | ||
| if err := json.Unmarshal(art.Metadata.Settings.Optimizer, &optimizer); err != nil { | ||
| return nil, fmt.Errorf("failed to parse optimizer settings: %w", err) | ||
| } | ||
|
|
||
| standardInput := newStandardInput(sources, optimizer, art.Metadata.Settings.EVMVersion) | ||
| standardInputJSON, err := json.Marshal(standardInput) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to generate standard input: %w", err) | ||
| } | ||
|
|
||
| // Get the contract name from the compilation target | ||
| var contractName string | ||
| for contractFile, name := range art.Metadata.Settings.CompilationTarget { | ||
| contractName = contractFile + ":" + name | ||
| break | ||
| } | ||
| v.log.Info("contractName", "name", contractName) | ||
|
|
||
| constructorArgs, err := v.getEncodedConstructorArgs(name) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get constructor args: %w", err) | ||
| } | ||
| v.log.Debug("constructorArgs", "args", constructorArgs) | ||
|
|
||
| return &contractArtifact{ | ||
| ContractName: contractName, | ||
| CompilerVersion: art.Metadata.Compiler.Version, | ||
| Optimizer: optimizer, | ||
| EVMVersion: art.Metadata.Settings.EVMVersion, | ||
| StandardInput: string(standardInputJSON), | ||
| ConstructorArgs: constructorArgs, | ||
| }, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change made it easier to construct the etherscan verification request