-
Notifications
You must be signed in to change notification settings - Fork 159
Add verification of deterministic deployments #145
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,51 @@ | ||
| import { exec } from 'child_process' | ||
| import { ethers } from 'ethers' | ||
| import { BigNumber, ethers, Signer } from 'ethers' | ||
|
|
||
| type VerificationRequest = { | ||
| signer: Signer | ||
| contractName: string | ||
| contractAddress: string | ||
| constructorArguments: any[] | ||
| } | ||
|
|
||
| // Helper function to encode constructor arguments based on their types | ||
| function abiEncodeConstructorArguments(args: any[]): string { | ||
| if (args.length === 0) return '' | ||
|
|
||
| // Infer types from the arguments | ||
| const types: string[] = args.map(arg => { | ||
| if (typeof arg === 'string' && arg.match(/^0x[a-fA-F0-9]{40}$/)) { | ||
| return 'address' | ||
| } else if (typeof arg === 'string' && arg.match(/^0x[a-fA-F0-9]*$/)) { | ||
| return 'bytes' | ||
| } else if (typeof arg === 'string') { | ||
| return 'string' | ||
| } else if (typeof arg === 'number' || BigNumber.isBigNumber(arg)) { | ||
| return 'uint256' | ||
| } else if (typeof arg === 'boolean') { | ||
| return 'bool' | ||
| } else if (Array.isArray(arg)) { | ||
| // For arrays, detect the inner type from first element | ||
| if (arg.length > 0) { | ||
| const innerType = | ||
| typeof arg[0] === 'string' && arg[0].match(/^0x[a-fA-F0-9]{40}$/) | ||
| ? 'address' | ||
| : 'string' | ||
| return `${innerType}[]` | ||
| } | ||
| return 'string[]' // fallback | ||
| } | ||
| return 'bytes32' // fallback for unknown types | ||
| }) | ||
|
|
||
| const abi = ethers.utils.defaultAbiCoder | ||
| return abi.encode(types, args) | ||
| } | ||
|
|
||
| export class ContractVerifier { | ||
| chainId: number | ||
| apiKey: string = '' | ||
| apiKey = '' | ||
| verificationQueue: VerificationRequest[] = [] | ||
|
|
||
| readonly NUM_OF_OPTIMIZATIONS = 100 | ||
| readonly COMPILER_VERSION = '0.8.16' | ||
|
|
@@ -17,41 +59,40 @@ export class ContractVerifier { | |
| 'node_modules/@offchainlabs/upgrade-executor/src/UpgradeExecutor.sol:UpgradeExecutor' | ||
|
|
||
| readonly contractToSource = { | ||
| l1TokenBridgeCreatorProxyAdmin: this.PROXY_ADMIN, | ||
| l1TokenBridgeCreatorLogic: | ||
| ProxyAdmin: this.PROXY_ADMIN, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the keys of this object to use directly the name of the contract instead of custom keys (since these are not used anymore in the calling function) |
||
| TransparentUpgradeableProxy: this.TUP, | ||
| UpgradeExecutor: this.EXECUTOR, | ||
| L1AtomicTokenBridgeCreator: | ||
| 'contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol:L1AtomicTokenBridgeCreator', | ||
| l1TokenBridgeCreatorProxy: this.TUP, | ||
| retryableSenderLogic: | ||
| L1TokenBridgeRetryableSender: | ||
| 'contracts/tokenbridge/ethereum/L1TokenBridgeRetryableSender.sol:L1TokenBridgeRetryableSender', | ||
| retryableSenderProxy: this.TUP, | ||
| routerTemplate: | ||
| L1GatewayRouter: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter', | ||
| standardGatewayTemplate: | ||
| L1ERC20Gateway: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway', | ||
| customGatewayTemplate: | ||
| L1CustomGateway: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway', | ||
| wethGatewayTemplate: | ||
| L1WethGateway: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway', | ||
| feeTokenBasedRouterTemplate: | ||
| L1OrbitGatewayRouter: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1OrbitGatewayRouter.sol:L1OrbitGatewayRouter', | ||
| feeTokenBasedStandardGatewayTemplate: | ||
| L1OrbitERC20Gateway: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1OrbitERC20Gateway.sol:L1OrbitERC20Gateway', | ||
| feeTokenBasedCustomGatewayTemplate: | ||
| L1OrbitCustomGateway: | ||
| 'contracts/tokenbridge/ethereum/gateway/L1OrbitCustomGateway.sol:L1OrbitCustomGateway', | ||
| upgradeExecutor: this.EXECUTOR, | ||
| l2TokenBridgeFactoryOnL1: | ||
| L2AtomicTokenBridgeFactory: | ||
| 'contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol:L2AtomicTokenBridgeFactory', | ||
| l2GatewayRouterOnL1: | ||
| L2GatewayRouter: | ||
| 'contracts/tokenbridge/arbitrum/gateway/L2GatewayRouter.sol:L2GatewayRouter', | ||
| l2StandardGatewayAddressOnL1: | ||
| L2ERC20Gateway: | ||
| 'contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol:L2ERC20Gateway', | ||
| l2CustomGatewayAddressOnL1: | ||
| L2CustomGateway: | ||
| 'contracts/tokenbridge/arbitrum/gateway/L2CustomGateway.sol:L2CustomGateway', | ||
| l2WethGatewayAddressOnL1: | ||
| L2WethGateway: | ||
| 'contracts/tokenbridge/arbitrum/gateway/L2WethGateway.sol:L2WethGateway', | ||
| l2WethAddressOnL1: 'contracts/tokenbridge/libraries/aeWETH.sol:aeWETH', | ||
| l2MulticallAddressOnL1: 'contracts/rpc-utils/MulticallV2.sol:ArbMulticall2', | ||
| l1Multicall: 'contracts/rpc-utils/MulticallV2.sol:Multicall2', | ||
| AeWETH: 'contracts/tokenbridge/libraries/aeWETH.sol:aeWETH', | ||
| ArbMulticall2: 'contracts/rpc-utils/MulticallV2.sol:ArbMulticall2', | ||
| Multicall2: 'contracts/rpc-utils/MulticallV2.sol:Multicall2', | ||
| } | ||
|
|
||
| constructor(chainId: number, apiKey: string) { | ||
|
|
@@ -61,12 +102,86 @@ export class ContractVerifier { | |
| } | ||
| } | ||
|
|
||
| queueContractForVerification( | ||
| signer: Signer, | ||
| contractName: string, | ||
| contractAddress: string, | ||
| constructorArguments: any[] = [] | ||
| ): void { | ||
| this.verificationQueue.push({ | ||
| signer, | ||
| contractName, | ||
| contractAddress, | ||
| constructorArguments, | ||
| }) | ||
| } | ||
|
|
||
| async verifyAllQueuedContracts(): Promise<void> { | ||
| if (this.verificationQueue.length === 0) { | ||
| return | ||
| } | ||
|
|
||
| if (!this.apiKey) { | ||
| console.warn( | ||
| 'ARBISCAN_API_KEY is not set. Skipping contract verification.' | ||
| ) | ||
| this.verificationQueue = [] // Clear queue | ||
| return | ||
| } | ||
|
|
||
| console.log() | ||
| console.log(`=== Verification of contracts ===`) | ||
|
|
||
| for (let i = 0; i < this.verificationQueue.length; i++) { | ||
| const request = this.verificationQueue[i] | ||
| await this.verifyContract( | ||
| request.signer, | ||
| request.contractName, | ||
| request.contractAddress, | ||
| request.constructorArguments | ||
| ) | ||
|
|
||
| // Add a small delay between verifications to avoid rate limiting | ||
| if (i < this.verificationQueue.length - 1) { | ||
| await new Promise(resolve => setTimeout(resolve, 1000)) | ||
| } | ||
| } | ||
|
|
||
| // Clear the queue after processing | ||
| this.verificationQueue = [] | ||
|
|
||
| // Allow a few seconds for all pending verifications to complete | ||
| await new Promise(resolve => setTimeout(resolve, 3000)) | ||
| } | ||
|
|
||
| async verifyContract( | ||
| signer: Signer, | ||
| contractName: string, | ||
| contractAddress: string, | ||
| constructorArguments: any[] = [] | ||
| ): Promise<void> { | ||
| const contractVerifier = new ContractVerifier( | ||
| (await signer.provider!.getNetwork()).chainId, | ||
| process.env.ARBISCAN_API_KEY! | ||
| ) | ||
|
|
||
| // Encode constructor arguments if provided | ||
| const encodedConstructorArgs = | ||
| abiEncodeConstructorArguments(constructorArguments) | ||
|
|
||
| await contractVerifier.verifyWithAddress( | ||
| contractName, | ||
| contractAddress, | ||
| encodedConstructorArgs | ||
| ) | ||
| } | ||
|
|
||
| async verifyWithAddress( | ||
| name: string, | ||
| contractAddress: string, | ||
| constructorArgs?: string, | ||
| _numOfOptimization?: number | ||
| ) { | ||
| ): Promise<void> { | ||
| // avoid rate limiting | ||
| await new Promise(resolve => setTimeout(resolve, 1000)) | ||
|
|
||
|
|
||
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.
Crafted this function to avoid having to pass the types of arguments for verification.
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.
very nice