-
Notifications
You must be signed in to change notification settings - Fork 98
Add automatic AztecScan contract verification after devnet deployment #243
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
FilipHarald
wants to merge
1
commit into
AztecProtocol:next
Choose a base branch
from
aztec-scan:next
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| import { createAztecNodeClient } from '@aztec/aztec.js/node'; | ||
| import { getAztecNodeUrl } from '../../config/config.js'; | ||
| import { EmbeddedWallet } from '@aztec/wallets/embedded'; | ||
| import configManager from '../../config/config.js'; | ||
|
|
||
| export async function setupWallet(): Promise<EmbeddedWallet> { | ||
| const nodeUrl = getAztecNodeUrl(); | ||
| const node = createAztecNodeClient(nodeUrl); | ||
| const wallet = await EmbeddedWallet.create(node, { ephemeral: true }); | ||
| // Real proofs required on devnet/testnet (fake proofs are rejected). | ||
| // Disabled on local network for faster iteration. | ||
| const proverEnabled = !configManager.isLocalNetwork(); | ||
| const wallet = await EmbeddedWallet.create(node, { | ||
| ephemeral: true, | ||
| pxeConfig: { proverEnabled }, | ||
| }); | ||
| return wallet; | ||
| } |
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,134 @@ | ||
| /** | ||
| * Verify contracts on AztecScan after deployment. | ||
| * | ||
| * Two-step verification: | ||
| * 1. Artifact verification — uploads the contract artifact JSON so AztecScan can | ||
| * match it byte-for-byte against the on-chain bytecode. | ||
| * 2. Instance verification — sends the deployment parameters (salt, deployer, | ||
| * publicKeysString, constructorArgs) so AztecScan can recompute and confirm | ||
| * the contract address. | ||
| * | ||
| * Uses raw fetch — no SDK dependency required. | ||
| */ | ||
|
|
||
| import type { AztecScanConfig } from "../../config/config.js"; | ||
|
|
||
| // ── Types ─────────────────────────────────────────────────────────── | ||
|
|
||
| export interface VerificationResult { | ||
| ok: boolean; | ||
| status: number; | ||
| statusText: string; | ||
| } | ||
|
|
||
| export interface VerifyInstanceArgs { | ||
| publicKeysString: string; | ||
| deployer: string; | ||
| salt: string; | ||
| constructorArgs: string[]; | ||
| } | ||
|
|
||
| // ── Artifact verification ─────────────────────────────────────────── | ||
|
|
||
| /** | ||
| * Verify a contract artifact (contract class) on AztecScan. | ||
| * | ||
| * POST /v1/{apiKey}/l2/contract-classes/{classId}/versions/{version} | ||
| * Body: { stringifiedArtifactJson: string } | ||
| * | ||
| * Returns 200 if already verified, 201 if newly verified. | ||
| */ | ||
| export async function verifyArtifactOnAztecScan( | ||
| config: AztecScanConfig, | ||
| contractClassId: string, | ||
| version: number, | ||
| artifact: Record<string, unknown>, | ||
| ): Promise<VerificationResult> { | ||
| const url = `${config.apiUrl}/v1/${config.apiKey}/l2/contract-classes/${contractClassId}/versions/${version}`; | ||
|
|
||
| // Handle { default: artifact } module-style exports | ||
| const raw = "default" in artifact && typeof artifact.default === "object" | ||
| ? artifact.default | ||
| : artifact; | ||
|
|
||
| const body = JSON.stringify({ stringifiedArtifactJson: JSON.stringify(raw) }); | ||
| const sizeMB = (new TextEncoder().encode(body).length / 1_000_000).toFixed(2); | ||
|
|
||
| console.log(`[aztecscan] Verifying artifact -> POST ${url} (${sizeMB} MB)`); | ||
|
|
||
| const response = await fetch(url, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body, | ||
| }); | ||
|
|
||
| console.log(`[aztecscan] Artifact verification: ${response.status} ${response.statusText}`); | ||
| if (!response.ok) { | ||
| const text = await response.text().catch(() => "(no body)"); | ||
| console.log(`[aztecscan] Artifact verification response: ${text.slice(0, 500)}`); | ||
| } | ||
| return { ok: response.ok, status: response.status, statusText: response.statusText }; | ||
| } | ||
|
|
||
| // ── Instance verification ─────────────────────────────────────────── | ||
|
|
||
| /** | ||
| * Verify a contract instance deployment on AztecScan. | ||
| * | ||
| * POST /v1/{apiKey}/l2/contract-instances/{address} | ||
| * Body: { verifiedDeploymentArguments: { salt, deployer, publicKeysString, constructorArgs, stringifiedArtifactJson? } } | ||
| * | ||
| * The server recomputes the contract address from the provided parameters. | ||
| */ | ||
| export async function verifyInstanceOnAztecScan( | ||
| config: AztecScanConfig, | ||
| contractAddress: string, | ||
| args: VerifyInstanceArgs, | ||
| artifact?: Record<string, unknown>, | ||
| ): Promise<VerificationResult> { | ||
| // Validate field lengths (matching server-side Zod schema) | ||
| if (args.publicKeysString.length !== 514) { | ||
| throw new Error(`Invalid publicKeysString length: expected 514, got ${args.publicKeysString.length}`); | ||
| } | ||
| if (args.deployer.length !== 66) { | ||
| throw new Error(`Invalid deployer length: expected 66, got ${args.deployer.length}`); | ||
| } | ||
| if (args.salt.length !== 66) { | ||
| throw new Error(`Invalid salt length: expected 66, got ${args.salt.length}`); | ||
| } | ||
|
|
||
| const url = `${config.apiUrl}/v1/${config.apiKey}/l2/contract-instances/${contractAddress}`; | ||
|
|
||
| const verifiedDeploymentArguments: Record<string, unknown> = { | ||
| salt: args.salt, | ||
| deployer: args.deployer, | ||
| publicKeysString: args.publicKeysString, | ||
| constructorArgs: args.constructorArgs, | ||
| }; | ||
|
|
||
| // Optionally include the artifact for combined verification | ||
| if (artifact) { | ||
| const raw = "default" in artifact && typeof artifact.default === "object" | ||
| ? artifact.default | ||
| : artifact; | ||
| verifiedDeploymentArguments.stringifiedArtifactJson = JSON.stringify(raw); | ||
| } | ||
|
|
||
| const body = JSON.stringify({ verifiedDeploymentArguments }); | ||
| const sizeMB = (new TextEncoder().encode(body).length / 1_000_000).toFixed(2); | ||
|
|
||
| console.log(`[aztecscan] Verifying instance -> POST ${url} (${sizeMB} MB)`); | ||
|
|
||
| const response = await fetch(url, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body, | ||
| }); | ||
|
|
||
| console.log(`[aztecscan] Instance verification: ${response.status} ${response.statusText}`); | ||
| if (!response.ok) { | ||
| const text = await response.text().catch(() => "(no body)"); | ||
| console.log(`[aztecscan] Instance verification response: ${text.slice(0, 500)}`); | ||
| } | ||
| return { ok: response.ok, status: response.status, statusText: response.statusText }; | ||
| } |
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.
im assuming this key is retrieved from your site?
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.
Well, yes, but we don't have signup yet. So this will work for all users for now.