diff --git a/boxes/boxes/react/src/config.ts b/boxes/boxes/react/src/config.ts index d2aac474f2ca..e809f466a301 100644 --- a/boxes/boxes/react/src/config.ts +++ b/boxes/boxes/react/src/config.ts @@ -1,6 +1,6 @@ import { createPXEClient, PXE } from '@aztec/aztec.js'; import { BoxReactContractArtifact } from '../artifacts/BoxReact'; -import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; +import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing/lazy'; export class PrivateEnv { private constructor(private pxe: PXE) {} diff --git a/boxes/boxes/vanilla/src/index.ts b/boxes/boxes/vanilla/src/index.ts index e60d4b5b46e7..3a05fe499285 100644 --- a/boxes/boxes/vanilla/src/index.ts +++ b/boxes/boxes/vanilla/src/index.ts @@ -1,6 +1,6 @@ import { Fr, Wallet, createPXEClient } from '@aztec/aztec.js'; -import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; +import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing/lazy'; import { VanillaContract } from '../artifacts/Vanilla'; const pxe = createPXEClient(process.env.PXE_URL || 'http://localhost:8080'); diff --git a/boxes/boxes/vite/package.json b/boxes/boxes/vite/package.json index 7c0f58afc945..f8ed2fa832fb 100644 --- a/boxes/boxes/vite/package.json +++ b/boxes/boxes/vite/package.json @@ -21,6 +21,7 @@ "@aztec/bb-prover": "latest", "@aztec/key-store": "latest", "@aztec/kv-store": "latest", + "@aztec/protocol-contracts": "latest", "@aztec/pxe": "latest", "@aztec/simulator": "latest", "@aztec/stdlib": "latest", diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index f2b3c0e9804e..694801ce6d2b 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -1,5 +1,5 @@ -import { getInitialTestAccounts } from "@aztec/accounts/testing"; -import { getSchnorrAccount } from "@aztec/accounts/schnorr"; +import { getInitialTestAccounts } from "@aztec/accounts/testing/lazy"; +import { getSchnorrAccount } from "@aztec/accounts/schnorr/lazy"; import { AccountWalletWithSecretKey, createAztecNodeClient, @@ -14,6 +14,7 @@ import { KVPxeDatabase } from "@aztec/pxe/database"; import { PXEService } from "@aztec/pxe/service"; import { WASMSimulator } from "@aztec/simulator/client"; import { BoxReactContractArtifact } from "../artifacts/BoxReact"; +import { LazyProtocolContractsProvider } from "@aztec/protocol-contracts/providers/lazy"; export class PrivateEnv { pxe: PXEService; @@ -30,7 +31,7 @@ export class PrivateEnv { const simulationProvider = new WASMSimulator(); const proofCreator = new BBWASMLazyPrivateKernelProver( simulationProvider, - 16, + 16 ); const l1Contracts = await aztecNode.getL1ContractAddresses(); const configWithContracts = { @@ -41,7 +42,7 @@ export class PrivateEnv { const store = await createStore( "pxe_data", configWithContracts, - createLogger("pxe:data:idb"), + createLogger("pxe:data:idb") ); const keyStore = new KeyStore(store); @@ -49,6 +50,8 @@ export class PrivateEnv { const db = await KVPxeDatabase.create(store); const tips = new L2TipsStore(store, "pxe"); + const protocolContractsProvider = new LazyProtocolContractsProvider(); + this.pxe = new PXEService( keyStore, aztecNode, @@ -56,7 +59,8 @@ export class PrivateEnv { tips, proofCreator, simulationProvider, - config, + protocolContractsProvider, + config ); await this.pxe.init(); const [accountData] = await getInitialTestAccounts(); @@ -64,7 +68,7 @@ export class PrivateEnv { this.pxe, accountData.secret, accountData.signingKey, - accountData.salt, + accountData.salt ); await account.register(); this.wallet = await account.getWallet(); @@ -79,5 +83,5 @@ export const deployerEnv = new PrivateEnv(); const IGNORE_FUNCTIONS = ["constructor", "process_log", "sync_notes"]; export const filteredInterface = BoxReactContractArtifact.functions.filter( - (f) => !IGNORE_FUNCTIONS.includes(f.name), + (f) => !IGNORE_FUNCTIONS.includes(f.name) ); diff --git a/boxes/yarn.lock b/boxes/yarn.lock index d830853f4a24..f8b6145f10e9 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -45,6 +45,12 @@ __metadata: languageName: node linkType: soft +"@aztec/protocol-contracts@link:../yarn-project/protocol-contracts::locator=aztec-app%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@aztec/protocol-contracts@link:../yarn-project/protocol-contracts::locator=aztec-app%40workspace%3A." + languageName: node + linkType: soft + "@aztec/pxe@link:../yarn-project/pxe::locator=aztec-app%40workspace%3A.": version: 0.0.0-use.local resolution: "@aztec/pxe@link:../yarn-project/pxe::locator=aztec-app%40workspace%3A." @@ -141,6 +147,7 @@ __metadata: "@aztec/bb-prover": "npm:latest" "@aztec/key-store": "npm:latest" "@aztec/kv-store": "npm:latest" + "@aztec/protocol-contracts": "npm:latest" "@aztec/pxe": "npm:latest" "@aztec/simulator": "npm:latest" "@aztec/stdlib": "npm:latest" diff --git a/playground/package.json b/playground/package.json index 8034efb534fa..356f40f28b5e 100644 --- a/playground/package.json +++ b/playground/package.json @@ -18,6 +18,7 @@ "@aztec/foundation": "link:../yarn-project/foundation", "@aztec/key-store": "link:../yarn-project/key-store", "@aztec/kv-store": "link:../yarn-project/kv-store", + "@aztec/protocol-contracts": "link:../yarn-project/protocol-contracts", "@aztec/pxe": "link:../yarn-project/pxe", "@aztec/simulator": "link:../yarn-project/simulator", "@aztec/stdlib": "link:../yarn-project/stdlib", diff --git a/playground/src/aztecEnv.ts b/playground/src/aztecEnv.ts index 5431c6613dbb..3f78aa3e8012 100644 --- a/playground/src/aztecEnv.ts +++ b/playground/src/aztecEnv.ts @@ -17,6 +17,7 @@ import { createContext } from "react"; import { NetworkDB, WalletDB } from "./utils/storage"; import { type ContractFunctionInteractionTx } from "./utils/txs"; import { type Logger, createLogger } from "@aztec/aztec.js/log"; +import { LazyProtocolContractsProvider } from "@aztec/protocol-contracts/providers/lazy"; process.env = Object.keys(import.meta.env).reduce((acc, key) => { acc[key.replace("VITE_", "")] = import.meta.env[key]; @@ -192,6 +193,8 @@ export class AztecEnv { const db = await KVPxeDatabase.create(store); const tips = new L2TipsStore(store, "pxe"); + const protocolContractsProvider = new LazyProtocolContractsProvider(); + const pxe = new PXEService( keyStore, aztecNode, @@ -199,6 +202,7 @@ export class AztecEnv { tips, proofCreator, simulationProvider, + protocolContractsProvider, config, WebLogger.getInstance().createLogger("pxe:service") ); diff --git a/playground/src/components/sidebar/components/createAccountDialog.tsx b/playground/src/components/sidebar/components/createAccountDialog.tsx index e5f4466d18e4..41ce95b4e958 100644 --- a/playground/src/components/sidebar/components/createAccountDialog.tsx +++ b/playground/src/components/sidebar/components/createAccountDialog.tsx @@ -1,7 +1,7 @@ import DialogTitle from "@mui/material/DialogTitle"; import Dialog from "@mui/material/Dialog"; import { AccountWalletWithSecretKey, Fr } from "@aztec/aztec.js"; -import { getSchnorrAccount } from "@aztec/accounts/schnorr"; +import { getSchnorrAccount } from "@aztec/accounts/schnorr/lazy"; import { Button, CircularProgress, diff --git a/playground/src/components/sidebar/sidebar.tsx b/playground/src/components/sidebar/sidebar.tsx index 98d229704fde..e5b4711b693b 100644 --- a/playground/src/components/sidebar/sidebar.tsx +++ b/playground/src/components/sidebar/sidebar.tsx @@ -11,11 +11,11 @@ import { AztecAddress, AccountManager, } from "@aztec/aztec.js"; -import { getInitialTestAccounts } from "@aztec/accounts/testing"; +import { getInitialTestAccounts } from "@aztec/accounts/testing/lazy"; import { NetworkDB, WalletDB } from "../../utils/storage"; import { useContext, useEffect, useState } from "react"; import { CreateAccountDialog } from "./components/createAccountDialog"; -import { getSchnorrAccount } from "@aztec/accounts/schnorr"; +import { getSchnorrAccount } from "@aztec/accounts/schnorr/lazy"; import AddIcon from "@mui/icons-material/Add"; import { Button, Divider, Typography } from "@mui/material"; import { diff --git a/playground/yarn.lock b/playground/yarn.lock index e38ec06cf2c6..6bbf9f00eedd 100644 --- a/playground/yarn.lock +++ b/playground/yarn.lock @@ -41,6 +41,12 @@ __metadata: languageName: node linkType: soft +"@aztec/protocol-contracts@link:../yarn-project/protocol-contracts::locator=playground%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@aztec/protocol-contracts@link:../yarn-project/protocol-contracts::locator=playground%40workspace%3A." + languageName: node + linkType: soft + "@aztec/pxe@link:../yarn-project/pxe::locator=playground%40workspace%3A.": version: 0.0.0-use.local resolution: "@aztec/pxe@link:../yarn-project/pxe::locator=playground%40workspace%3A." @@ -3750,6 +3756,7 @@ __metadata: "@aztec/foundation": "link:../yarn-project/foundation" "@aztec/key-store": "link:../yarn-project/key-store" "@aztec/kv-store": "link:../yarn-project/kv-store" + "@aztec/protocol-contracts": "link:../yarn-project/protocol-contracts" "@aztec/pxe": "link:../yarn-project/pxe" "@aztec/simulator": "link:../yarn-project/simulator" "@aztec/stdlib": "link:../yarn-project/stdlib" diff --git a/yarn-project/accounts/package.json b/yarn-project/accounts/package.json index 386648f08389..90201b7bc29c 100644 --- a/yarn-project/accounts/package.json +++ b/yarn-project/accounts/package.json @@ -8,9 +8,13 @@ "./dapp": "./dest/dapp/index.js", "./defaults": "./dest/defaults/index.js", "./ecdsa": "./dest/ecdsa/index.js", + "./ecdsa/lazy": "./dest/ecdsa/lazy.js", "./schnorr": "./dest/schnorr/index.js", + "./schnorr/lazy": "./dest/schnorr/lazy.js", "./single_key": "./dest/single_key/index.js", + "./single_key/lazy": "./dest/single_key/lazy.js", "./testing": "./dest/testing/index.js", + "./testing/lazy": "./dest/testing/lazy.js", "./utils": "./dest/utils/index.js" }, "typedocOptions": { diff --git a/yarn-project/accounts/src/defaults/account_contract.ts b/yarn-project/accounts/src/defaults/account_contract.ts index 76d015df4e76..0d4b671d5329 100644 --- a/yarn-project/accounts/src/defaults/account_contract.ts +++ b/yarn-project/accounts/src/defaults/account_contract.ts @@ -11,12 +11,9 @@ import { DefaultAccountInterface } from '../defaults/account_interface.js'; export abstract class DefaultAccountContract implements AccountContract { abstract getAuthWitnessProvider(address: CompleteAddress): AuthWitnessProvider; abstract getDeploymentArgs(): Promise; + abstract getContractArtifact(): Promise; - constructor(private artifact: ContractArtifact) {} - - getContractArtifact(): ContractArtifact { - return this.artifact; - } + constructor() {} getInterface(address: CompleteAddress, nodeInfo: NodeInfo): AccountInterface { return new DefaultAccountInterface(this.getAuthWitnessProvider(address), address, nodeInfo); diff --git a/yarn-project/accounts/src/defaults/account_interface.ts b/yarn-project/accounts/src/defaults/account_interface.ts index c1017d027437..b221514b85ce 100644 --- a/yarn-project/accounts/src/defaults/account_interface.ts +++ b/yarn-project/accounts/src/defaults/account_interface.ts @@ -1,9 +1,11 @@ -import type { AztecAddress, NodeInfo } from '@aztec/aztec.js'; -import { type AccountInterface, type AuthWitnessProvider, CompleteAddress } from '@aztec/aztec.js/account'; +import type { AccountInterface, AuthWitnessProvider } from '@aztec/aztec.js/account'; import type { EntrypointInterface, ExecutionRequestInit } from '@aztec/aztec.js/entrypoint'; import { DefaultAccountEntrypoint } from '@aztec/entrypoints/account'; import { Fr } from '@aztec/foundation/fields'; import type { AuthWitness } from '@aztec/stdlib/auth-witness'; +import type { AztecAddress } from '@aztec/stdlib/aztec-address'; +import { CompleteAddress } from '@aztec/stdlib/contract'; +import type { NodeInfo } from '@aztec/stdlib/contract'; import type { TxExecutionRequest } from '@aztec/stdlib/tx'; /** diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts b/yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts index 5d0091c4ed6d..3995d2e9bd6a 100644 --- a/yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts +++ b/yarn-project/accounts/src/ecdsa/ecdsa_k/account_contract.ts @@ -1,20 +1,20 @@ import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { Ecdsa } from '@aztec/foundation/crypto'; import type { Fr } from '@aztec/foundation/fields'; -import type { ContractArtifact } from '@aztec/stdlib/abi'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; import { CompleteAddress } from '@aztec/stdlib/contract'; import { DefaultAccountContract } from '../../defaults/account_contract.js'; -import { EcdsaKAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using ECDSA signatures * verified against a secp256k1 public key stored in an immutable encrypted note. + * This abstract version does not provide a way to retrieve the artifact, as it + * can be implemented with or without lazy loading. */ -export class EcdsaKAccountContract extends DefaultAccountContract { +export abstract class EcdsaKBaseAccountContract extends DefaultAccountContract { constructor(private signingPrivateKey: Buffer) { - super(EcdsaKAccountContractArtifact as ContractArtifact); + super(); } async getDeploymentArgs() { diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_k/artifact.ts b/yarn-project/accounts/src/ecdsa/ecdsa_k/artifact.ts deleted file mode 100644 index 045ea90480de..000000000000 --- a/yarn-project/accounts/src/ecdsa/ecdsa_k/artifact.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { type ContractArtifact, type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js'; - -import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' }; - -export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact( - EcdsaKAccountContractJson as NoirCompiledContract, -); diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_k/index.ts b/yarn-project/accounts/src/ecdsa/ecdsa_k/index.ts index fdc43b7513b1..ec5a87c897c4 100644 --- a/yarn-project/accounts/src/ecdsa/ecdsa_k/index.ts +++ b/yarn-project/accounts/src/ecdsa/ecdsa_k/index.ts @@ -4,16 +4,36 @@ * * @packageDocumentation */ -import type { AztecAddress, Fr } from '@aztec/aztec.js'; import { AccountManager, type Salt } from '@aztec/aztec.js/account'; import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; +import type { NoirCompiledContract } from '@aztec/stdlib/noir'; -import { EcdsaKAccountContract } from './account_contract.js'; +import EcdsaKAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' }; +import { EcdsaKBaseAccountContract } from './account_contract.js'; -export { EcdsaKAccountContractArtifact } from './artifact.js'; -export { EcdsaKAccountContract }; +export const EcdsaKAccountContractArtifact: ContractArtifact = loadContractArtifact( + EcdsaKAccountContractJson as NoirCompiledContract, +); +/** + * Account contract that authenticates transactions using ECDSA signatures + * verified against a secp256k1 public key stored in an immutable encrypted note. + * Eagerly loads the contract artifact + */ +export class EcdsaKAccountContract extends EcdsaKBaseAccountContract { + constructor(signingPrivateKey: Buffer) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return Promise.resolve(EcdsaKAccountContractArtifact); + } +} /** * Creates an Account that relies on an ECDSA signing key for authentication. * @param pxe - An PXE server instance. diff --git a/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts b/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts new file mode 100644 index 000000000000..39a28438b11d --- /dev/null +++ b/yarn-project/accounts/src/ecdsa/ecdsa_k/lazy.ts @@ -0,0 +1,66 @@ +/** + * The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption. + * Consider using this account type when working with integrations with Ethereum wallets. + * + * @packageDocumentation + */ +import { AccountManager, type Salt } from '@aztec/aztec.js/account'; +import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; + +import { EcdsaKBaseAccountContract } from './account_contract.js'; + +/** + * Lazily loads the contract artifact + * @returns The contract artifact for the ecdsa K account contract + */ +export async function getEcdsaKAccountContractArtifact() { + const { default: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaKAccount.json'); + return loadContractArtifact(ecdsaKAccountContractJson); +} + +/** + * Account contract that authenticates transactions using ECDSA signatures + * verified against a secp256k1 public key stored in an immutable encrypted note. + * Lazily loads the contract artifact + */ +export class EcdsaKAccountContract extends EcdsaKBaseAccountContract { + constructor(signingPrivateKey: Buffer) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return getEcdsaKAccountContractArtifact(); + } +} +/** + * Creates an Account that relies on an ECDSA signing key for authentication. + * @param pxe - An PXE server instance. + * @param secretKey - Secret key used to derive all the keystore keys. + * @param signingPrivateKey - Secp256k1 key used for signing transactions. + * @param salt - Deployment salt. + * @returns An account manager initialized with the account contract and its deployment params + */ +export function getEcdsaKAccount( + pxe: PXE, + secretKey: Fr, + signingPrivateKey: Buffer, + salt?: Salt, +): Promise { + return AccountManager.create(pxe, secretKey, new EcdsaKAccountContract(signingPrivateKey), salt); +} + +/** + * Gets a wallet for an already registered account using ECDSA signatures. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - ECDSA key used for signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getEcdsaKWallet(pxe: PXE, address: AztecAddress, signingPrivateKey: Buffer): Promise { + return getWallet(pxe, address, new EcdsaKAccountContract(signingPrivateKey)); +} diff --git a/yarn-project/accounts/src/ecdsa/lazy.ts b/yarn-project/accounts/src/ecdsa/lazy.ts new file mode 100644 index 000000000000..105dfe28443e --- /dev/null +++ b/yarn-project/accounts/src/ecdsa/lazy.ts @@ -0,0 +1,2 @@ +export * from './ecdsa_k/lazy.js'; +export * from './ssh_ecdsa_r/lazy.js'; diff --git a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/account_contract.ts b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/account_contract.ts index fd89b8e95d00..46707e3973fe 100644 --- a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/account_contract.ts +++ b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/account_contract.ts @@ -1,12 +1,11 @@ -import { type AuthWitnessProvider, CompleteAddress } from '@aztec/aztec.js/account'; +import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { EcdsaSignature } from '@aztec/foundation/crypto'; import type { Fr } from '@aztec/foundation/fields'; -import type { ContractArtifact } from '@aztec/stdlib/abi'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; +import { CompleteAddress } from '@aztec/stdlib/contract'; import { DefaultAccountContract } from '../../defaults/account_contract.js'; import { signWithAgent } from '../../utils/ssh_agent.js'; -import { EcdsaRAccountContractArtifact } from './artifact.js'; const secp256r1N = 115792089210356248762697446949407573529996955224135760342422259061068512044369n; /** @@ -15,10 +14,12 @@ const secp256r1N = 1157920892103562487626974469494075735299969552241357603424222 * Since this implementation relays signatures to an SSH agent, we provide the * public key here not for signature verification, but to identify actual identity * that will be used to sign authwitnesses. + * This abstract version does not provide a way to retrieve the artifact, as it + * can be implemented with or without lazy loading. */ -export class EcdsaRSSHAccountContract extends DefaultAccountContract { +export abstract class EcdsaRSSHBaseAccountContract extends DefaultAccountContract { constructor(private signingPublicKey: Buffer) { - super(EcdsaRAccountContractArtifact as ContractArtifact); + super(); } getDeploymentArgs() { diff --git a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/artifact.ts b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/artifact.ts deleted file mode 100644 index ea8382b61372..000000000000 --- a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/artifact.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js'; - -import EcdsaRAccountContractJson from '../../../artifacts/EcdsaRAccount.json' assert { type: 'json' }; - -export const EcdsaRAccountContractArtifact = loadContractArtifact(EcdsaRAccountContractJson as NoirCompiledContract); diff --git a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/index.ts b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/index.ts index 86bd732b9510..2191ce6eb707 100644 --- a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/index.ts +++ b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/index.ts @@ -4,15 +4,39 @@ * * @packageDocumentation */ -import type { AztecAddress, Fr } from '@aztec/aztec.js'; import { AccountManager, type Salt } from '@aztec/aztec.js/account'; import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; +import type { NoirCompiledContract } from '@aztec/stdlib/noir'; -import { EcdsaRSSHAccountContract } from './account_contract.js'; +import EcdsaRAccountContractJson from '../../../artifacts/EcdsaKAccount.json' assert { type: 'json' }; +import { EcdsaRSSHBaseAccountContract } from './account_contract.js'; -export { EcdsaRAccountContractArtifact } from './artifact.js'; -export { EcdsaRSSHAccountContract }; +export const EcdsaRAccountContractArtifact: ContractArtifact = loadContractArtifact( + EcdsaRAccountContractJson as NoirCompiledContract, +); + +/** + * Account contract that authenticates transactions using ECDSA signatures + * verified against a secp256r1 public key stored in an immutable encrypted note. + * Since this implementation relays signatures to an SSH agent, we provide the + * public key here not for signature verification, but to identify actual identity + * that will be used to sign authwitnesses. + * Eagerly loads the contract artifact + */ +export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract { + constructor(signingPrivateKey: Buffer) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return Promise.resolve(EcdsaRAccountContractArtifact); + } +} /** * Creates an Account that relies on an ECDSA signing key for authentication. diff --git a/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/lazy.ts b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/lazy.ts new file mode 100644 index 000000000000..370aae214f19 --- /dev/null +++ b/yarn-project/accounts/src/ecdsa/ssh_ecdsa_r/lazy.ts @@ -0,0 +1,73 @@ +/** + * The `@aztec/accounts/ecdsa` export provides an ECDSA account contract implementation, that uses an ECDSA private key for authentication, and a Grumpkin key for encryption. + * Consider using this account type when working with integrations with Ethereum wallets. + * + * @packageDocumentation + */ +import { AccountManager, type Salt } from '@aztec/aztec.js/account'; +import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; + +import { EcdsaRSSHBaseAccountContract } from './account_contract.js'; + +/* + * Lazily loads the contract artifact + * @returns The contract artifact for the ecdsa R account contract + */ +/** + * + */ +export async function getEcdsaRAccountContractArtifact() { + const { default: ecdsaKAccountContractJson } = await import('../../../artifacts/EcdsaRAccount.json'); + return loadContractArtifact(ecdsaKAccountContractJson); +} + +/** + * Account contract that authenticates transactions using ECDSA signatures + * verified against a secp256r1 public key stored in an immutable encrypted note. + * Since this implementation relays signatures to an SSH agent, we provide the + * public key here not for signature verification, but to identify actual identity + * that will be used to sign authwitnesses. + * Lazily loads the contract artifact + */ +export class EcdsaRSSHAccountContract extends EcdsaRSSHBaseAccountContract { + constructor(signingPrivateKey: Buffer) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return getEcdsaRAccountContractArtifact(); + } +} + +/** + * Creates an Account that relies on an ECDSA signing key for authentication. + * @param pxe - An PXE server instance. + * @param secretKey - Secret key used to derive all the keystore keys. + * @param signingPublicKey - Secp2561 key used to identify its corresponding private key in the SSH Agent. + * @param salt - Deployment salt. + * @returns An account manager initialized with the account contract and its deployment params + */ +export function getEcdsaRSSHAccount( + pxe: PXE, + secretKey: Fr, + signingPublicKey: Buffer, + salt?: Salt, +): Promise { + return AccountManager.create(pxe, secretKey, new EcdsaRSSHAccountContract(signingPublicKey), salt); +} + +/** + * Gets a wallet for an already registered account using ECDSA signatures. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - ECDSA key used for signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getEcdsaRSSHWallet(pxe: PXE, address: AztecAddress, signingPublicKey: Buffer): Promise { + return getWallet(pxe, address, new EcdsaRSSHAccountContract(signingPublicKey)); +} diff --git a/yarn-project/accounts/src/schnorr/account_contract.ts b/yarn-project/accounts/src/schnorr/account_contract.ts index 3fd7c556bc73..980627ccabb9 100644 --- a/yarn-project/accounts/src/schnorr/account_contract.ts +++ b/yarn-project/accounts/src/schnorr/account_contract.ts @@ -1,21 +1,20 @@ -import { CompleteAddress, getAccountContractAddress } from '@aztec/aztec.js'; import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { Schnorr } from '@aztec/foundation/crypto'; -import { type Fr, GrumpkinScalar } from '@aztec/foundation/fields'; -import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; -import { deriveSigningKey } from '@aztec/stdlib/keys'; +import { CompleteAddress } from '@aztec/stdlib/contract'; import { DefaultAccountContract } from '../defaults/account_contract.js'; -import { SchnorrAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using Schnorr signatures * verified against a Grumpkin public key stored in an immutable encrypted note. + * This abstract version does not provide a way to retrieve the artifact, as it + * can be implemented with or without lazy loading. */ -export class SchnorrAccountContract extends DefaultAccountContract { +export abstract class SchnorrBaseAccountContract extends DefaultAccountContract { constructor(private signingPrivateKey: GrumpkinScalar) { - super(SchnorrAccountContractArtifact as ContractArtifact); + super(); } async getDeploymentArgs() { @@ -29,7 +28,7 @@ export class SchnorrAccountContract extends DefaultAccountContract { } /** Creates auth witnesses using Schnorr signatures. */ -class SchnorrAuthWitnessProvider implements AuthWitnessProvider { +export class SchnorrAuthWitnessProvider implements AuthWitnessProvider { constructor(private signingPrivateKey: GrumpkinScalar) {} async createAuthWit(messageHash: Fr): Promise { @@ -38,15 +37,3 @@ class SchnorrAuthWitnessProvider implements AuthWitnessProvider { return new AuthWitness(messageHash, [...signature.toBuffer()]); } } - -/** - * Compute the address of a schnorr account contract. - * @param secret - A seed for deriving the signing key and public keys. - * @param salt - The contract address salt. - * @param signingPrivateKey - A specific signing private key that's not derived from the secret. - */ -export async function getSchnorrAccountContractAddress(secret: Fr, salt: Fr, signingPrivateKey?: GrumpkinScalar) { - const signingKey = signingPrivateKey ?? deriveSigningKey(secret); - const accountContract = new SchnorrAccountContract(signingKey); - return await getAccountContractAddress(accountContract, secret, salt); -} diff --git a/yarn-project/accounts/src/schnorr/artifact.ts b/yarn-project/accounts/src/schnorr/artifact.ts deleted file mode 100644 index 88c1c5d1e4e4..000000000000 --- a/yarn-project/accounts/src/schnorr/artifact.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js'; - -import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' }; - -export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract); diff --git a/yarn-project/accounts/src/schnorr/index.ts b/yarn-project/accounts/src/schnorr/index.ts index 0ce3ff3418c0..202a8dadf5e5 100644 --- a/yarn-project/accounts/src/schnorr/index.ts +++ b/yarn-project/accounts/src/schnorr/index.ts @@ -4,16 +4,35 @@ * * @packageDocumentation */ -import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js'; -import { AccountManager, type Salt } from '@aztec/aztec.js/account'; +import { AccountManager, type Salt, getAccountContractAddress } from '@aztec/aztec.js/account'; import { type AccountWallet, type AccountWalletWithSecretKey, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PXE } from '@aztec/stdlib/interfaces/client'; +import { deriveSigningKey } from '@aztec/stdlib/keys'; +import type { NoirCompiledContract } from '@aztec/stdlib/noir'; -import { SchnorrAccountContract } from './account_contract.js'; +import SchnorrAccountContractJson from '../../artifacts/SchnorrAccount.json' assert { type: 'json' }; +import { SchnorrBaseAccountContract } from './account_contract.js'; -export { SchnorrAccountContract, getSchnorrAccountContractAddress } from './account_contract.js'; +export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract); -export { SchnorrAccountContractArtifact } from './artifact.js'; +/** + * Account contract that authenticates transactions using Schnorr signatures + * verified against a Grumpkin public key stored in an immutable encrypted note. + * Eagerly loads the contract artifact + */ +export class SchnorrAccountContract extends SchnorrBaseAccountContract { + constructor(signingPrivateKey: GrumpkinScalar) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return Promise.resolve(SchnorrAccountContractArtifact); + } +} /** * Creates an Account Manager that relies on a Grumpkin signing key for authentication. @@ -64,3 +83,15 @@ export async function getSchnorrWalletWithSecretKey( const account = await getSchnorrAccount(pxe, secretKey, signingPrivateKey, salt); return account.getWallet(); } + +/** + * Compute the address of a schnorr account contract. + * @param secret - A seed for deriving the signing key and public keys. + * @param salt - The contract address salt. + * @param signingPrivateKey - A specific signing private key that's not derived from the secret. + */ +export async function getSchnorrAccountContractAddress(secret: Fr, salt: Fr, signingPrivateKey?: GrumpkinScalar) { + const signingKey = signingPrivateKey ?? deriveSigningKey(secret); + const accountContract = new SchnorrAccountContract(signingKey); + return await getAccountContractAddress(accountContract, secret, salt); +} diff --git a/yarn-project/accounts/src/schnorr/lazy.ts b/yarn-project/accounts/src/schnorr/lazy.ts new file mode 100644 index 000000000000..0a9752ea2960 --- /dev/null +++ b/yarn-project/accounts/src/schnorr/lazy.ts @@ -0,0 +1,102 @@ +/** + * The `@aztec/accounts/schnorr` export provides an account contract implementation that uses Schnorr signatures with a Grumpkin key for authentication, and a separate Grumpkin key for encryption. + * This is the suggested account contract type for most use cases within Aztec. + * + * @packageDocumentation + */ +import { AccountManager, type Salt, getAccountContractAddress } from '@aztec/aztec.js/account'; +import { type AccountWallet, type AccountWalletWithSecretKey, getWallet } from '@aztec/aztec.js/wallet'; +import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import { AztecAddress } from '@aztec/stdlib/aztec-address'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; +import { deriveSigningKey } from '@aztec/stdlib/keys'; + +import { SchnorrBaseAccountContract } from './account_contract.js'; + +/** + * Lazily loads the contract artifact + * @returns The contract artifact for the schnorr account contract + */ +export async function getSchnorrAccountContractArtifact() { + const { default: schnorrAccountContractJson } = await import('../../artifacts/SchnorrAccount.json'); + return loadContractArtifact(schnorrAccountContractJson); +} + +/** + * Account contract that authenticates transactions using Schnorr signatures + * verified against a Grumpkin public key stored in an immutable encrypted note. + * Lazily loads the contract artifact + */ +export class SchnorrAccountContract extends SchnorrBaseAccountContract { + constructor(signingPrivateKey: GrumpkinScalar) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return getSchnorrAccountContractArtifact(); + } +} + +/** + * Creates an Account Manager that relies on a Grumpkin signing key for authentication. + * @param pxe - An PXE server instance. + * @param secretKey - Secret key used to derive all the keystore keys. + * @param signingPrivateKey - Grumpkin key used for signing transactions. + * @param salt - Deployment salt. + * @returns An account manager initialized with the account contract and its deployment params + */ +export function getSchnorrAccount( + pxe: PXE, + secretKey: Fr, + signingPrivateKey: GrumpkinScalar, + salt?: Salt, +): Promise { + return AccountManager.create(pxe, secretKey, new SchnorrAccountContract(signingPrivateKey), salt); +} + +/** + * Gets a wallet for an already registered account using Schnorr signatures. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - Grumpkin key used for signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getSchnorrWallet( + pxe: PXE, + address: AztecAddress, + signingPrivateKey: GrumpkinScalar, +): Promise { + return getWallet(pxe, address, new SchnorrAccountContract(signingPrivateKey)); +} + +/** + * Gets a wallet for an already registered account using Schnorr signatures. + * @param pxe - An PXE server instance. + * @param secretKey - Secret key used to derive all the keystore keys. + * @param signingPrivateKey - Grumpkin key used for signing transactions. + * @param salt - Deployment salt. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export async function getSchnorrWalletWithSecretKey( + pxe: PXE, + secretKey: Fr, + signingPrivateKey: GrumpkinScalar, + salt: Salt, +): Promise { + const account = await getSchnorrAccount(pxe, secretKey, signingPrivateKey, salt); + return account.getWallet(); +} + +/** + * Compute the address of a schnorr account contract. + * @param secret - A seed for deriving the signing key and public keys. + * @param salt - The contract address salt. + * @param signingPrivateKey - A specific signing private key that's not derived from the secret. + */ +export async function getSchnorrAccountContractAddress(secret: Fr, salt: Fr, signingPrivateKey?: GrumpkinScalar) { + const signingKey = signingPrivateKey ?? deriveSigningKey(secret); + const accountContract = new SchnorrAccountContract(signingKey); + return await getAccountContractAddress(accountContract, secret, salt); +} diff --git a/yarn-project/accounts/src/single_key/account_contract.ts b/yarn-project/accounts/src/single_key/account_contract.ts index 3b44b4181d8d..a66a74373ad7 100644 --- a/yarn-project/accounts/src/single_key/account_contract.ts +++ b/yarn-project/accounts/src/single_key/account_contract.ts @@ -1,19 +1,20 @@ -import { type AuthWitnessProvider, CompleteAddress } from '@aztec/aztec.js/account'; +import type { AuthWitnessProvider } from '@aztec/aztec.js/account'; import { Schnorr } from '@aztec/foundation/crypto'; import { type Fr, GrumpkinScalar } from '@aztec/foundation/fields'; -import type { ContractArtifact } from '@aztec/stdlib/abi'; import { AuthWitness } from '@aztec/stdlib/auth-witness'; +import { CompleteAddress } from '@aztec/stdlib/contract'; import { DefaultAccountContract } from '../defaults/account_contract.js'; -import { SchnorrSingleKeyAccountContractArtifact } from './artifact.js'; /** * Account contract that authenticates transactions using Schnorr signatures verified against * the note encryption key, relying on a single private key for both encryption and authentication. + * This abstract version does not provide a way to retrieve the artifact, as it + * can be implemented with or without lazy loading. */ -export class SingleKeyAccountContract extends DefaultAccountContract { +export abstract class SingleKeyBaseAccountContract extends DefaultAccountContract { constructor(private encryptionPrivateKey: GrumpkinScalar) { - super(SchnorrSingleKeyAccountContractArtifact as ContractArtifact); + super(); } getDeploymentArgs() { diff --git a/yarn-project/accounts/src/single_key/artifact.ts b/yarn-project/accounts/src/single_key/artifact.ts deleted file mode 100644 index f48ee9a14e8e..000000000000 --- a/yarn-project/accounts/src/single_key/artifact.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js'; - -import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' }; - -export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact( - SchnorrSingleKeyAccountContractJson as NoirCompiledContract, -); diff --git a/yarn-project/accounts/src/single_key/index.ts b/yarn-project/accounts/src/single_key/index.ts index b6484f87390e..ada23860fe44 100644 --- a/yarn-project/accounts/src/single_key/index.ts +++ b/yarn-project/accounts/src/single_key/index.ts @@ -7,14 +7,33 @@ import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js'; import { AccountManager, type Salt } from '@aztec/aztec.js/account'; import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; import type { PXE } from '@aztec/stdlib/interfaces/client'; import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys'; +import type { NoirCompiledContract } from '@aztec/stdlib/noir'; -import { SingleKeyAccountContract } from './account_contract.js'; +import SchnorrSingleKeyAccountContractJson from '../../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' }; +import { SingleKeyBaseAccountContract } from './account_contract.js'; -export { SingleKeyAccountContract }; +export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact( + SchnorrSingleKeyAccountContractJson as NoirCompiledContract, +); -export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArtifact } from './artifact.js'; +/** + * Account contract that authenticates transactions using Schnorr signatures verified against + * the note encryption key, relying on a single private key for both encryption and authentication. + * Eagerly loads the contract artifact + */ +export class SingleKeyAccountContract extends SingleKeyBaseAccountContract { + constructor(signingPrivateKey: GrumpkinScalar) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return Promise.resolve(SchnorrSingleKeyAccountContractArtifact); + } +} /** * Creates an Account that uses the same Grumpkin key for encryption and authentication. @@ -23,7 +42,7 @@ export { SchnorrSingleKeyAccountContractArtifact as SingleKeyAccountContractArti * @param salt - Deployment salt. * @returns An account manager initialized with the account contract and its deployment params */ -export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt) { +export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) { const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey); return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt); } @@ -35,12 +54,10 @@ export function getSingleKeyAccount(pxe: PXE, secretKey: Fr, salt?: Salt) { * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions. * @returns A wallet for this account that can be used to interact with a contract instance. */ -export function getSingleKeyWallet( +export function getUnsafeSchnorrWallet( pxe: PXE, address: AztecAddress, - signingKey: GrumpkinScalar, + signingPrivateKey: GrumpkinScalar, ): Promise { - return getWallet(pxe, address, new SingleKeyAccountContract(signingKey)); + return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey)); } - -export { getSingleKeyAccount as getUnsafeSchnorrAccount, getSingleKeyWallet as getUnsafeSchnorrWallet }; diff --git a/yarn-project/accounts/src/single_key/lazy.ts b/yarn-project/accounts/src/single_key/lazy.ts new file mode 100644 index 000000000000..d5c3fe041b8a --- /dev/null +++ b/yarn-project/accounts/src/single_key/lazy.ts @@ -0,0 +1,66 @@ +/** + * The `@aztec/accounts/single_key` export provides a testing account contract implementation that uses a single Grumpkin key for both authentication and encryption. + * It is not recommended to use this account type in production. + * + * @packageDocumentation + */ +import type { AztecAddress, Fr, GrumpkinScalar } from '@aztec/aztec.js'; +import { AccountManager, type Salt } from '@aztec/aztec.js/account'; +import { type AccountWallet, getWallet } from '@aztec/aztec.js/wallet'; +import type { ContractArtifact } from '@aztec/stdlib/abi'; +import { loadContractArtifact } from '@aztec/stdlib/abi'; +import type { PXE } from '@aztec/stdlib/interfaces/client'; +import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys'; + +import { SingleKeyBaseAccountContract } from './account_contract.js'; + +/** + * Lazily loads the contract artifact + * @returns The contract artifact for the single key account contract + */ +export async function getSingleKeyAccountContractArtifact() { + const { default: schnorrAccountContractJson } = await import('../../artifacts/SchnorrAccount.json'); + return loadContractArtifact(schnorrAccountContractJson); +} + +/** + * Account contract that authenticates transactions using Schnorr signatures verified against + * the note encryption key, relying on a single private key for both encryption and authentication. + * Lazily loads the contract artifact + */ +export class SingleKeyAccountContract extends SingleKeyBaseAccountContract { + constructor(signingPrivateKey: GrumpkinScalar) { + super(signingPrivateKey); + } + + override getContractArtifact(): Promise { + return getSingleKeyAccountContractArtifact(); + } +} + +/** + * Creates an Account that uses the same Grumpkin key for encryption and authentication. + * @param pxe - An PXE server instance. + * @param secretKey - Secret key used to derive all the keystore keys (in this case also used to get signing key). + * @param salt - Deployment salt. + * @returns An account manager initialized with the account contract and its deployment params + */ +export function getUnsafeSchnorrAccount(pxe: PXE, secretKey: Fr, salt?: Salt) { + const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey(secretKey); + return AccountManager.create(pxe, secretKey, new SingleKeyAccountContract(encryptionPrivateKey), salt); +} + +/** + * Gets a wallet for an already registered account using Schnorr signatures with a single key for encryption and authentication. + * @param pxe - An PXE server instance. + * @param address - Address for the account. + * @param signingPrivateKey - Grumpkin key used for note encryption and signing transactions. + * @returns A wallet for this account that can be used to interact with a contract instance. + */ +export function getUnsafeSchnorrWallet( + pxe: PXE, + address: AztecAddress, + signingPrivateKey: GrumpkinScalar, +): Promise { + return getWallet(pxe, address, new SingleKeyAccountContract(signingPrivateKey)); +} diff --git a/yarn-project/accounts/src/testing/configuration.ts b/yarn-project/accounts/src/testing/configuration.ts index 2688ce5c4956..9121e85fa7ea 100644 --- a/yarn-project/accounts/src/testing/configuration.ts +++ b/yarn-project/accounts/src/testing/configuration.ts @@ -1,15 +1,7 @@ -import type { PXE } from '@aztec/aztec.js'; -import type { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; -import { Fr, type GrumpkinScalar } from '@aztec/foundation/fields'; +import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import { deriveMasterIncomingViewingSecretKey } from '@aztec/stdlib/keys'; -import { - getSchnorrAccount, - getSchnorrAccountContractAddress, - getSchnorrWalletWithSecretKey, -} from '../schnorr/index.js'; - export const INITIAL_TEST_SECRET_KEYS = [ Fr.fromHexString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), Fr.fromHexString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), @@ -45,63 +37,3 @@ export interface InitialAccountData { */ address: AztecAddress; } - -/** - * Gets the basic information for initial test accounts. - */ -export function getInitialTestAccounts(): Promise { - return Promise.all( - INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({ - secret, - signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i], - salt: INITIAL_TEST_ACCOUNT_SALTS[i], - address: await getSchnorrAccountContractAddress( - secret, - INITIAL_TEST_ACCOUNT_SALTS[i], - INITIAL_TEST_SIGNING_KEYS[i], - ), - })), - ); -} - -/** - * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment. - * @param pxe - PXE instance. - * @returns A set of AccountWallet implementations for each of the initial accounts. - */ -export function getInitialTestAccountsWallets(pxe: PXE): Promise { - return Promise.all( - INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => { - const account = await getSchnorrAccount( - pxe, - encryptionKey!, - INITIAL_TEST_SIGNING_KEYS[i]!, - INITIAL_TEST_ACCOUNT_SALTS[i], - ); - return account.getWallet(); - }), - ); -} - -/** - * Queries a PXE for it's registered accounts. - * @param pxe - PXE instance. - * @returns A set of key data for each of the initial accounts. - */ -export async function getDeployedTestAccounts(pxe: PXE): Promise { - const registeredAccounts = await pxe.getRegisteredAccounts(); - const testAccounts = await getInitialTestAccounts(); - return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address))); -} - -/** - * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts. - * @param pxe - PXE instance. - * @returns A set of AccountWallet implementations for each of the initial accounts. - */ -export async function getDeployedTestAccountsWallets(pxe: PXE): Promise { - const testAccounts = await getDeployedTestAccounts(pxe); - return Promise.all( - testAccounts.map(({ secret, signingKey, salt }) => getSchnorrWalletWithSecretKey(pxe, secret, signingKey, salt)), - ); -} diff --git a/yarn-project/accounts/src/testing/create_account.ts b/yarn-project/accounts/src/testing/create_account.ts index 99324738d196..fffb848c0d3f 100644 --- a/yarn-project/accounts/src/testing/create_account.ts +++ b/yarn-project/accounts/src/testing/create_account.ts @@ -2,8 +2,7 @@ import { type AccountManager, FeeJuicePaymentMethod, type PXE, type WaitOpts } f import { Fr } from '@aztec/foundation/fields'; import { deriveSigningKey } from '@aztec/stdlib/keys'; -import { getSchnorrAccountContractAddress } from '../schnorr/account_contract.js'; -import { getSchnorrAccount } from '../schnorr/index.js'; +import { getSchnorrAccount, getSchnorrAccountContractAddress } from '../schnorr/index.js'; import type { InitialAccountData } from './configuration.js'; /** diff --git a/yarn-project/accounts/src/testing/index.ts b/yarn-project/accounts/src/testing/index.ts index 8ef6dcf5b433..8eb7c0a3535a 100644 --- a/yarn-project/accounts/src/testing/index.ts +++ b/yarn-project/accounts/src/testing/index.ts @@ -1,11 +1,92 @@ /** * The `@aztec/accounts/testing` export provides utility methods for testing, in particular in a Sandbox environment. * - * Use the {@link generateSchnorrAccounts} and {@link deployFundedSchnorrAccounts} methods to create new sample accounts for testing, - * or use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts. + * Use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts. * * @packageDocumentation */ +import type { PXE } from '@aztec/aztec.js'; +import type { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; -export * from './create_account.js'; -export * from './configuration.js'; +import { + getSchnorrAccount, + getSchnorrAccountContractAddress, + getSchnorrWalletWithSecretKey, +} from '../schnorr/index.js'; +import type { InitialAccountData } from './configuration.js'; +import { + INITIAL_TEST_ACCOUNT_SALTS, + INITIAL_TEST_ENCRYPTION_KEYS, + INITIAL_TEST_SECRET_KEYS, + INITIAL_TEST_SIGNING_KEYS, +} from './configuration.js'; + +export { + type InitialAccountData, + INITIAL_TEST_ACCOUNT_SALTS, + INITIAL_TEST_ENCRYPTION_KEYS, + INITIAL_TEST_SECRET_KEYS, + INITIAL_TEST_SIGNING_KEYS, +} from './configuration.js'; + +/** + * Gets the basic information for initial test accounts. + */ +export function getInitialTestAccounts(): Promise { + return Promise.all( + INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({ + secret, + signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i], + salt: INITIAL_TEST_ACCOUNT_SALTS[i], + address: await getSchnorrAccountContractAddress( + secret, + INITIAL_TEST_ACCOUNT_SALTS[i], + INITIAL_TEST_SIGNING_KEYS[i], + ), + })), + ); +} + +/** + * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export function getInitialTestAccountsWallets(pxe: PXE): Promise { + return Promise.all( + INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => { + const account = await getSchnorrAccount( + pxe, + encryptionKey!, + INITIAL_TEST_SIGNING_KEYS[i]!, + INITIAL_TEST_ACCOUNT_SALTS[i], + ); + return account.getWallet(); + }), + ); +} + +/** + * Queries a PXE for it's registered accounts. + * @param pxe - PXE instance. + * @returns A set of key data for each of the initial accounts. + */ +export async function getDeployedTestAccounts(pxe: PXE): Promise { + const registeredAccounts = await pxe.getRegisteredAccounts(); + const testAccounts = await getInitialTestAccounts(); + return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address))); +} + +/** + * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export async function getDeployedTestAccountsWallets(pxe: PXE): Promise { + const testAccounts = await getDeployedTestAccounts(pxe); + return Promise.all( + testAccounts.map(({ secret, signingKey, salt }) => getSchnorrWalletWithSecretKey(pxe, secret, signingKey, salt)), + ); +} + +export { deployFundedSchnorrAccount, deployFundedSchnorrAccounts, generateSchnorrAccounts } from './create_account.js'; diff --git a/yarn-project/accounts/src/testing/lazy.ts b/yarn-project/accounts/src/testing/lazy.ts new file mode 100644 index 000000000000..76b5d74b8d53 --- /dev/null +++ b/yarn-project/accounts/src/testing/lazy.ts @@ -0,0 +1,86 @@ +/** + * The `@aztec/accounts/testing/lazy` export provides utility methods for testing, in particular in a Sandbox environment. + * + * Use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts. + * + * @packageDocumentation + */ +import type { PXE } from '@aztec/aztec.js'; +import type { AccountWalletWithSecretKey } from '@aztec/aztec.js/wallet'; + +import { getSchnorrAccount, getSchnorrAccountContractAddress, getSchnorrWalletWithSecretKey } from '../schnorr/lazy.js'; +import { + INITIAL_TEST_ACCOUNT_SALTS, + INITIAL_TEST_ENCRYPTION_KEYS, + INITIAL_TEST_SECRET_KEYS, + INITIAL_TEST_SIGNING_KEYS, + type InitialAccountData, +} from './configuration.js'; + +export { + type InitialAccountData, + INITIAL_TEST_ACCOUNT_SALTS, + INITIAL_TEST_ENCRYPTION_KEYS, + INITIAL_TEST_SECRET_KEYS, + INITIAL_TEST_SIGNING_KEYS, +} from './configuration.js'; + +/** + * Gets the basic information for initial test accounts. + */ +export function getInitialTestAccounts(): Promise { + return Promise.all( + INITIAL_TEST_SECRET_KEYS.map(async (secret, i) => ({ + secret, + signingKey: INITIAL_TEST_ENCRYPTION_KEYS[i], + salt: INITIAL_TEST_ACCOUNT_SALTS[i], + address: await getSchnorrAccountContractAddress( + secret, + INITIAL_TEST_ACCOUNT_SALTS[i], + INITIAL_TEST_SIGNING_KEYS[i], + ), + })), + ); +} + +/** + * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export function getInitialTestAccountsWallets(pxe: PXE): Promise { + return Promise.all( + INITIAL_TEST_SECRET_KEYS.map(async (encryptionKey, i) => { + const account = await getSchnorrAccount( + pxe, + encryptionKey!, + INITIAL_TEST_SIGNING_KEYS[i]!, + INITIAL_TEST_ACCOUNT_SALTS[i], + ); + return account.getWallet(); + }), + ); +} + +/** + * Queries a PXE for it's registered accounts. + * @param pxe - PXE instance. + * @returns A set of key data for each of the initial accounts. + */ +export async function getDeployedTestAccounts(pxe: PXE): Promise { + const registeredAccounts = await pxe.getRegisteredAccounts(); + const testAccounts = await getInitialTestAccounts(); + return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address))); +} + +/** + * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export async function getDeployedTestAccountsWallets(pxe: PXE): Promise { + const testAccounts = await getDeployedTestAccounts(pxe); + return Promise.all( + testAccounts.map(({ secret, signingKey, salt }) => getSchnorrWalletWithSecretKey(pxe, secret, signingKey, salt)), + ); +} diff --git a/yarn-project/archiver/src/factory.ts b/yarn-project/archiver/src/factory.ts index c790a261be80..299654fc31f4 100644 --- a/yarn-project/archiver/src/factory.ts +++ b/yarn-project/archiver/src/factory.ts @@ -5,9 +5,9 @@ import type { DataStoreConfig } from '@aztec/kv-store/config'; import { createStore } from '@aztec/kv-store/lmdb-v2'; import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; import { TokenBridgeContractArtifact } from '@aztec/noir-contracts.js/TokenBridge'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractNames, protocolContractTreeRoot } from '@aztec/protocol-contracts'; -import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; +import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle'; import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi'; import { type ContractClassPublic, @@ -46,7 +46,8 @@ export async function createArchiver( async function registerProtocolContracts(store: KVArchiverDataStore) { const blockNumber = 0; for (const name of protocolContractNames) { - const contract = await getCanonicalProtocolContract(name); + const provider = new BundledProtocolContractsProvider(); + const contract = await provider.getProtocolContractArtifact(name); const contractClassPublic: ContractClassPublic = { ...contract.contractClass, privateFunctions: [], diff --git a/yarn-project/aztec.js/src/account/contract.ts b/yarn-project/aztec.js/src/account/contract.ts index 735e389bce33..63df16c3746d 100644 --- a/yarn-project/aztec.js/src/account/contract.ts +++ b/yarn-project/aztec.js/src/account/contract.ts @@ -15,7 +15,7 @@ export interface AccountContract { /** * Returns the artifact of this account contract. */ - getContractArtifact(): ContractArtifact; + getContractArtifact(): Promise; /** * Returns the deployment arguments for this instance, or undefined if this contract does not require deployment. @@ -46,7 +46,8 @@ export interface AccountContract { export async function getAccountContractAddress(accountContract: AccountContract, secret: Fr, salt: Fr) { const { publicKeys } = await deriveKeys(secret); const constructorArgs = await accountContract.getDeploymentArgs(); - const instance = await getContractInstanceFromDeployParams(accountContract.getContractArtifact(), { + const artifact = await accountContract.getContractArtifact(); + const instance = await getContractInstanceFromDeployParams(artifact, { constructorArgs, salt, publicKeys, diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 59a9e50cdffd..5f52856fc10f 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -48,7 +48,8 @@ export class AccountManager { const { publicKeys } = await deriveKeys(secretKey); salt = salt !== undefined ? new Fr(salt) : Fr.random(); - const instance = await getContractInstanceFromDeployParams(accountContract.getContractArtifact(), { + const artifact = await accountContract.getContractArtifact(); + const instance = await getContractInstanceFromDeployParams(artifact, { constructorArgs: await accountContract.getDeploymentArgs(), salt: salt, publicKeys, @@ -121,7 +122,7 @@ export class AccountManager { */ public async register(): Promise { await this.pxe.registerContract({ - artifact: this.accountContract.getContractArtifact(), + artifact: await this.accountContract.getContractArtifact(), instance: this.getInstance(), }); @@ -138,18 +139,16 @@ export class AccountManager { * @returns A DeployMethod instance that deploys this account contract. */ public async getDeployMethod(deployWallet?: Wallet) { + const artifact = await this.accountContract.getContractArtifact(); + if (!(await this.isDeployable())) { - throw new Error( - `Account contract ${this.accountContract.getContractArtifact().name} does not require deployment.`, - ); + throw new Error(`Account contract ${artifact.name} does not require deployment.`); } const completeAddress = await this.getCompleteAddress(); await this.pxe.registerAccount(this.secretKey, completeAddress.partialAddress); - const artifact = this.accountContract.getContractArtifact(); - const args = (await this.accountContract.getDeploymentArgs()) ?? []; if (deployWallet) { diff --git a/yarn-project/aztec.js/src/api/account.ts b/yarn-project/aztec.js/src/api/account.ts index 7721431215c3..9e745d3e9379 100644 --- a/yarn-project/aztec.js/src/api/account.ts +++ b/yarn-project/aztec.js/src/api/account.ts @@ -4,8 +4,7 @@ export { type AuthWitnessProvider, type Salt, type Wallet, + getAccountContractAddress, } from '../account/index.js'; export { AccountManager } from '../account_manager/index.js'; - -export { CompleteAddress } from '@aztec/stdlib/contract'; diff --git a/yarn-project/aztec.js/src/deployment/protocol_contracts.ts b/yarn-project/aztec.js/src/deployment/protocol_contracts.ts index 476168fc5e5f..e5149cc2091a 100644 --- a/yarn-project/aztec.js/src/deployment/protocol_contracts.ts +++ b/yarn-project/aztec.js/src/deployment/protocol_contracts.ts @@ -1,17 +1,25 @@ -import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer'; -import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer'; +import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import { UnsafeContract } from '../contract/unsafe_contract.js'; import type { Wallet } from '../wallet/index.js'; /** Returns a Contract wrapper for the class registerer. */ export async function getRegistererContract(wallet: Wallet) { - const { artifact, instance } = await getCanonicalClassRegisterer(); - return new UnsafeContract(instance, artifact, wallet); + const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractClassRegisterer); + if (!contractInstance) { + throw new Error("ContractClassRegisterer is not registered in this wallet's instance"); + } + const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true); + + return new UnsafeContract(contractInstance!, artifact!, wallet); } /** Returns a Contract wrapper for the instance deployer. */ export async function getDeployerContract(wallet: Wallet) { - const { artifact, instance } = await getCanonicalInstanceDeployer(); - return new UnsafeContract(instance, artifact, wallet); + const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractInstanceDeployer); + if (!contractInstance) { + throw new Error("ContractInstanceDeployer is not registered in this wallet's instance"); + } + const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true); + return new UnsafeContract(contractInstance!, artifact!, wallet); } diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index f5b7ae020065..8dd6aaee2675 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -1,6 +1,6 @@ import { Fr } from '@aztec/foundation/fields'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; -import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice'; +import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice/lazy'; import type { FunctionCall } from '@aztec/stdlib/abi'; import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index f54e53cac902..51f8de848755 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -26,12 +26,9 @@ export { NoteSelector } from '@aztec/stdlib/abi'; export { createCompatibleClient, createPXEClient } from './rpc_clients/index.js'; -export { type AuthWitnessProvider } from './account/index.js'; +export { type DeployAccountOptions } from './account_manager/index.js'; -export { type AccountContract, getAccountContractAddress } from './account/index.js'; -export { AccountManager, type DeployAccountOptions } from './account_manager/index.js'; - -export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, type Wallet } from './wallet/index.js'; +export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet } from './wallet/index.js'; export { EthAddress } from '@aztec/foundation/eth-address'; @@ -103,6 +100,7 @@ export { fileURLToPath } from '@aztec/foundation/url'; // Here you *can* do `export *` as the granular api defacto exports things explicitly. // This entire index file will be deprecated at some point after we're satisfied. export * from './api/abi.js'; +export * from './api/account.js'; export * from './api/addresses.js'; export * from './api/cheat_codes.js'; export * from './api/ethereum/index.js'; diff --git a/yarn-project/aztec/src/cli/versioning.ts b/yarn-project/aztec/src/cli/versioning.ts index 73699106a95f..61137039c4dd 100644 --- a/yarn-project/aztec/src/cli/versioning.ts +++ b/yarn-project/aztec/src/cli/versioning.ts @@ -1,4 +1,4 @@ -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import type { ChainConfig } from '@aztec/stdlib/config'; import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning'; diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index 71291a888f72..c652fdf17477 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -17,7 +17,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type LogFn, createLogger } from '@aztec/foundation/log'; import { FPCContract } from '@aztec/noir-contracts.js/FPC'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts index a8ee1cacb4e2..5e016e9c63c6 100644 --- a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts @@ -15,7 +15,6 @@ import { updateResetCircuitSampleInputs, } from '@aztec/noir-protocol-circuits-types/client'; import type { ArtifactProvider, ClientProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types'; -import { ClientCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; import type { SimulationProvider } from '@aztec/simulator/client'; import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client'; import type { @@ -216,7 +215,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver { outputSize: output.toBuffer().length, } satisfies CircuitWitnessGenerationStats); - const verificationKey = ClientCircuitVks[circuitType].keyAsFields; + const verificationKey = (await this.artifactProvider.getCircuitVkByName(circuitType)).keyAsFields; const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64'); const kernelOutput: PrivateKernelSimulateOutput = { @@ -228,12 +227,12 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver { return kernelOutput; } - public makeEmptyKernelSimulateOutput< + public async makeEmptyKernelSimulateOutput< PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs, >(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) { const kernelProofOutput: PrivateKernelSimulateOutput = { publicInputs, - verificationKey: ClientCircuitVks[circuitType].keyAsFields, + verificationKey: (await this.artifactProvider.getCircuitVkByName(circuitType)).keyAsFields, outputWitness: new Map(), bytecode: Buffer.from([]), }; diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index be346ecd48b5..5808004e81d4 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -37,7 +37,7 @@ import { convertSingleTxBlockRootRollupInputsToWitnessMap, convertSingleTxBlockRootRollupOutputsFromWitnessMap, } from '@aztec/noir-protocol-circuits-types/server'; -import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; +import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks'; import { NativeACVMSimulator } from '@aztec/simulator/server'; import type { AvmCircuitInputs } from '@aztec/stdlib/avm'; import { ProvingError } from '@aztec/stdlib/errors'; diff --git a/yarn-project/bb-prover/src/test/test_circuit_prover.ts b/yarn-project/bb-prover/src/test/test_circuit_prover.ts index a682fd97734c..9b9873401b74 100644 --- a/yarn-project/bb-prover/src/test/test_circuit_prover.ts +++ b/yarn-project/bb-prover/src/test/test_circuit_prover.ts @@ -33,7 +33,7 @@ import { convertSimulatedSingleTxBlockRootRollupInputsToWitnessMap, convertSimulatedSingleTxBlockRootRollupOutputsFromWitnessMap, } from '@aztec/noir-protocol-circuits-types/server'; -import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; +import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks'; import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server'; import type { AvmCircuitInputs } from '@aztec/stdlib/avm'; import { diff --git a/yarn-project/bb-prover/src/verifier/bb_verifier.ts b/yarn-project/bb-prover/src/verifier/bb_verifier.ts index 83bdb8876cfa..af85978051c5 100644 --- a/yarn-project/bb-prover/src/verifier/bb_verifier.ts +++ b/yarn-project/bb-prover/src/verifier/bb_verifier.ts @@ -1,7 +1,7 @@ import { runInDirectory } from '@aztec/foundation/fs'; import { type Logger, createLogger } from '@aztec/foundation/log'; +import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks'; import type { ClientProtocolArtifact, ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types'; -import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server'; import type { Proof } from '@aztec/stdlib/proofs'; import type { CircuitVerificationStats } from '@aztec/stdlib/stats'; diff --git a/yarn-project/bot/src/config.ts b/yarn-project/bot/src/config.ts index 2cd88730f607..eefecc624e4b 100644 --- a/yarn-project/bot/src/config.ts +++ b/yarn-project/bot/src/config.ts @@ -7,7 +7,7 @@ import { optionalNumberConfigHelper, } from '@aztec/foundation/config'; import { Fr } from '@aztec/foundation/fields'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type ZodFor, schemas } from '@aztec/stdlib/schemas'; import type { ComponentsVersions } from '@aztec/stdlib/versioning'; diff --git a/yarn-project/cli/src/utils/aztec.ts b/yarn-project/cli/src/utils/aztec.ts index 144452470712..0fdb5bdb1a7b 100644 --- a/yarn-project/cli/src/utils/aztec.ts +++ b/yarn-project/cli/src/utils/aztec.ts @@ -56,7 +56,7 @@ export async function deployAztecContracts( : privateKeyToAccount(`${privateKey.startsWith('0x') ? '' : '0x'}${privateKey}` as `0x${string}`); const chain = createEthereumChain(rpcUrl, chainId); - const { getVKTreeRoot } = await import('@aztec/noir-protocol-circuits-types/vks'); + const { getVKTreeRoot } = await import('@aztec/noir-protocol-circuits-types/vk-tree'); return await deployL1Contracts( chain.rpcUrl, diff --git a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts index 5100d5c3e96f..162ef7a5ab6a 100644 --- a/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/composed/integration_l1_publisher.test.ts @@ -22,7 +22,7 @@ import { TestDateProvider } from '@aztec/foundation/timer'; import { openTmpStore } from '@aztec/kv-store/lmdb'; import { ForwarderAbi, OutboxAbi, RollupAbi } from '@aztec/l1-artifacts'; import { SHA256Trunc, StandardTree } from '@aztec/merkle-tree'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { LightweightBlockBuilder } from '@aztec/prover-client/block-builder'; import { SequencerPublisher } from '@aztec/sequencer-client'; diff --git a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts index 7874ef13924a..b14e2d045f70 100644 --- a/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts +++ b/yarn-project/end-to-end/src/fixtures/setup_l1_contracts.ts @@ -1,6 +1,6 @@ import { type Logger, deployL1Contracts } from '@aztec/aztec.js'; import type { DeployL1ContractsArgs, L1ContractsConfig } from '@aztec/ethereum'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import type { HDAccount, PrivateKeyAccount } from 'viem'; diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 2d07494be8f4..4e9dda9c1c13 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -50,7 +50,7 @@ import { Fr } from '@aztec/foundation/fields'; import { retryUntil } from '@aztec/foundation/retry'; import { TestDateProvider } from '@aztec/foundation/timer'; import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec/prover-node'; import { type PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index ca75c9d25e48..dbac8775c7c2 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -4,6 +4,7 @@ import { AuthWitness, type AuthWitnessProvider, type CompleteAddress, + type ContractArtifact, Fr, GrumpkinScalar, Schnorr, @@ -19,7 +20,11 @@ const PRIVATE_KEY = GrumpkinScalar.fromHexString('0xd35d743ac0dfe3d6dbe6be8c877c /** Account contract implementation that authenticates txs using Schnorr signatures. */ class SchnorrHardcodedKeyAccountContract extends DefaultAccountContract { constructor(private privateKey = PRIVATE_KEY) { - super(SchnorrHardcodedAccountContractArtifact); + super(); + } + + override getContractArtifact(): Promise { + return Promise.resolve(SchnorrHardcodedAccountContractArtifact); } getDeploymentArgs() { diff --git a/yarn-project/noir-protocol-circuits-types/package.json b/yarn-project/noir-protocol-circuits-types/package.json index 10d9723a4a56..d4e527602349 100644 --- a/yarn-project/noir-protocol-circuits-types/package.json +++ b/yarn-project/noir-protocol-circuits-types/package.json @@ -3,12 +3,13 @@ "version": "0.1.0", "type": "module", "exports": { - "./server": "./dest/entrypoint/server.js", + "./server": "./dest/entrypoint/server/artifacts.js", + "./server/vks": "./dest/entrypoint/server/vks.js", "./client": "./dest/entrypoint/client/common.js", "./client/bundle": "./dest/entrypoint/client/bundle.js", "./client/lazy": "./dest/entrypoint/client/lazy.js", - "./types": "./dest/types/index.js", - "./vks": "./dest/entrypoint/vks.js" + "./vk-tree": "./dest/entrypoint/vk-tree.js", + "./types": "./dest/types/index.js" }, "inherits": [ "../package.common.json", diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/client/bundle.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/client/bundle.ts index 210980cb25e5..ea2c0f56e7b2 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/client/bundle.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/client/bundle.ts @@ -1,4 +1,5 @@ import type { NoirCompiledCircuit } from '@aztec/stdlib/noir'; +import type { VerificationKeyData } from '@aztec/stdlib/vks'; import PrivateKernelInitJson from '../../../artifacts/private_kernel_init.json' assert { type: 'json' }; import PrivateKernelInitSimulatedJson from '../../../artifacts/private_kernel_init_simulated.json' assert { type: 'json' }; @@ -10,6 +11,7 @@ import PrivateKernelTailToPublicJson from '../../../artifacts/private_kernel_tai import PrivateKernelTailToPublicSimulatedJson from '../../../artifacts/private_kernel_tail_to_public_simulated.json' assert { type: 'json' }; import { PrivateKernelResetArtifacts, PrivateKernelResetSimulatedArtifacts } from '../../private_kernel_reset_data.js'; import type { ArtifactProvider, ClientProtocolArtifact } from '../types.js'; +import { ClientCircuitVks } from '../vks/client.js'; export const ClientCircuitArtifacts: Record = { PrivateKernelInitArtifact: PrivateKernelInitJson as NoirCompiledCircuit, @@ -35,4 +37,8 @@ export class BundleArtifactProvider implements ArtifactProvider { getSimulatedClientCircuitArtifactByName(artifact: ClientProtocolArtifact): Promise { return Promise.resolve(SimulatedClientCircuitArtifacts[artifact]); } + + getCircuitVkByName(artifact: ClientProtocolArtifact): Promise { + return Promise.resolve(ClientCircuitVks[artifact]); + } } diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/client/lazy.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/client/lazy.ts index a1a4b4eac303..ee0e7869485e 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/client/lazy.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/client/lazy.ts @@ -1,6 +1,11 @@ import type { NoirCompiledCircuit } from '@aztec/stdlib/noir'; +import type { VerificationKeyData } from '@aztec/stdlib/vks'; -import { ClientCircuitArtifactNames, getClientCircuitArtifact } from '../../client_artifacts_helper.js'; +import { + ClientCircuitArtifactNames, + getClientCircuitArtifact, + getClientCircuitVkData, +} from '../../client_artifacts_helper.js'; import type { ArtifactProvider, ClientProtocolArtifact } from '../types.js'; export class LazyArtifactProvider implements ArtifactProvider { @@ -11,4 +16,8 @@ export class LazyArtifactProvider implements ArtifactProvider { getSimulatedClientCircuitArtifactByName(artifact: ClientProtocolArtifact): Promise { return getClientCircuitArtifact(ClientCircuitArtifactNames[artifact], true); } + + getCircuitVkByName(artifact: ClientProtocolArtifact): Promise { + return getClientCircuitVkData(ClientCircuitArtifactNames[artifact]); + } } diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/types.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/types.ts index a8127d667e14..81c2d78e7611 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/types.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/types.ts @@ -1,4 +1,5 @@ import type { NoirCompiledCircuit } from '@aztec/stdlib/noir'; +import type { VerificationKeyData } from '@aztec/stdlib/vks'; import type { PrivateResetArtifact } from '../private_kernel_reset_types.js'; @@ -27,4 +28,5 @@ export type ProtocolArtifact = ServerProtocolArtifact | ClientProtocolArtifact; export interface ArtifactProvider { getClientCircuitArtifactByName(artifact: ClientProtocolArtifact): Promise; getSimulatedClientCircuitArtifactByName(artifact: ClientProtocolArtifact): Promise; + getCircuitVkByName(artifact: ClientProtocolArtifact): Promise; } diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/vks.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks.ts deleted file mode 100644 index 1f8e5a041a44..000000000000 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/vks.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { - BASE_PARITY_INDEX, - BLOCK_MERGE_ROLLUP_INDEX, - BLOCK_ROOT_ROLLUP_EMPTY_INDEX, - BLOCK_ROOT_ROLLUP_INDEX, - BLOCK_ROOT_ROLLUP_SINGLE_TX_INDEX, - MERGE_ROLLUP_INDEX, - PRIVATE_BASE_ROLLUP_VK_INDEX, - PRIVATE_KERNEL_INIT_INDEX, - PRIVATE_KERNEL_INNER_INDEX, - PRIVATE_KERNEL_TAIL_INDEX, - PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - PUBLIC_BASE_ROLLUP_VK_INDEX, - ROOT_PARITY_INDEX, - ROOT_ROLLUP_INDEX, -} from '@aztec/constants'; -import type { VerificationKeyData } from '@aztec/stdlib/vks'; - -import BaseParityVkJson from '../../artifacts/keys/parity_base.vk.data.json' assert { type: 'json' }; -import RootParityVkJson from '../../artifacts/keys/parity_root.vk.data.json' assert { type: 'json' }; -import PrivateKernelInitVkJson from '../../artifacts/keys/private_kernel_init.vk.data.json' assert { type: 'json' }; -import PrivateKernelInnerVkJson from '../../artifacts/keys/private_kernel_inner.vk.data.json' assert { type: 'json' }; -import PrivateKernelTailVkJson from '../../artifacts/keys/private_kernel_tail.vk.data.json' assert { type: 'json' }; -import PrivateKernelTailToPublicVkJson from '../../artifacts/keys/private_kernel_tail_to_public.vk.data.json' assert { type: 'json' }; -import PrivateBaseRollupVkJson from '../../artifacts/keys/rollup_base_private.vk.data.json' assert { type: 'json' }; -import PublicBaseRollupVkJson from '../../artifacts/keys/rollup_base_public.vk.data.json' assert { type: 'json' }; -import BlockMergeRollupVkJson from '../../artifacts/keys/rollup_block_merge.vk.data.json' assert { type: 'json' }; -import BlockRootRollupVkJson from '../../artifacts/keys/rollup_block_root.vk.data.json' assert { type: 'json' }; -import EmptyBlockRootRollupVkJson from '../../artifacts/keys/rollup_block_root_empty.vk.data.json' assert { type: 'json' }; -import SingleTxBlockRootRollupVkJson from '../../artifacts/keys/rollup_block_root_single_tx.vk.data.json' assert { type: 'json' }; -import MergeRollupVkJson from '../../artifacts/keys/rollup_merge.vk.data.json' assert { type: 'json' }; -import RootRollupVkJson from '../../artifacts/keys/rollup_root.vk.data.json' assert { type: 'json' }; -import TubeVkJson from '../../artifacts/keys/tube.vk.data.json' assert { type: 'json' }; -import { PrivateKernelResetVkIndexes, PrivateKernelResetVks } from '../private_kernel_reset_vks.js'; -import { keyJsonToVKData } from '../utils/vk_json.js'; -import type { ClientProtocolArtifact, ProtocolArtifact, ServerProtocolArtifact } from './types.js'; - -// TODO Include this in the normal maps when the tube is implemented in noir -export const TubeVk = keyJsonToVKData(TubeVkJson); - -export const ServerCircuitVks: Record = { - BaseParityArtifact: keyJsonToVKData(BaseParityVkJson), - RootParityArtifact: keyJsonToVKData(RootParityVkJson), - PrivateBaseRollupArtifact: keyJsonToVKData(PrivateBaseRollupVkJson), - PublicBaseRollupArtifact: keyJsonToVKData(PublicBaseRollupVkJson), - MergeRollupArtifact: keyJsonToVKData(MergeRollupVkJson), - BlockRootRollupArtifact: keyJsonToVKData(BlockRootRollupVkJson), - SingleTxBlockRootRollupArtifact: keyJsonToVKData(SingleTxBlockRootRollupVkJson), - EmptyBlockRootRollupArtifact: keyJsonToVKData(EmptyBlockRootRollupVkJson), - BlockMergeRollupArtifact: keyJsonToVKData(BlockMergeRollupVkJson), - RootRollupArtifact: keyJsonToVKData(RootRollupVkJson), -}; - -export const ClientCircuitVks: Record = { - PrivateKernelInitArtifact: keyJsonToVKData(PrivateKernelInitVkJson), - PrivateKernelInnerArtifact: keyJsonToVKData(PrivateKernelInnerVkJson), - PrivateKernelTailArtifact: keyJsonToVKData(PrivateKernelTailVkJson), - PrivateKernelTailToPublicArtifact: keyJsonToVKData(PrivateKernelTailToPublicVkJson), - ...PrivateKernelResetVks, -}; - -export const ProtocolCircuitVks: Record = { - ...ClientCircuitVks, - ...ServerCircuitVks, -}; - -export const ProtocolCircuitVkIndexes: Record = { - PrivateKernelInitArtifact: PRIVATE_KERNEL_INIT_INDEX, - PrivateKernelInnerArtifact: PRIVATE_KERNEL_INNER_INDEX, - PrivateKernelTailArtifact: PRIVATE_KERNEL_TAIL_INDEX, - PrivateKernelTailToPublicArtifact: PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, - BaseParityArtifact: BASE_PARITY_INDEX, - RootParityArtifact: ROOT_PARITY_INDEX, - PrivateBaseRollupArtifact: PRIVATE_BASE_ROLLUP_VK_INDEX, - PublicBaseRollupArtifact: PUBLIC_BASE_ROLLUP_VK_INDEX, - MergeRollupArtifact: MERGE_ROLLUP_INDEX, - BlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_INDEX, - SingleTxBlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_SINGLE_TX_INDEX, - EmptyBlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_EMPTY_INDEX, - BlockMergeRollupArtifact: BLOCK_MERGE_ROLLUP_INDEX, - RootRollupArtifact: ROOT_ROLLUP_INDEX, - ...PrivateKernelResetVkIndexes, -}; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/client.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/client.ts new file mode 100644 index 000000000000..2ac2e408e41d --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/client.ts @@ -0,0 +1,17 @@ +import type { VerificationKeyData } from '@aztec/stdlib/vks'; + +import PrivateKernelInitVkJson from '../../../artifacts/keys/private_kernel_init.vk.data.json' assert { type: 'json' }; +import PrivateKernelInnerVkJson from '../../../artifacts/keys/private_kernel_inner.vk.data.json' assert { type: 'json' }; +import PrivateKernelTailVkJson from '../../../artifacts/keys/private_kernel_tail.vk.data.json' assert { type: 'json' }; +import PrivateKernelTailToPublicVkJson from '../../../artifacts/keys/private_kernel_tail_to_public.vk.data.json' assert { type: 'json' }; +import { PrivateKernelResetVks } from '../../private_kernel_reset_vks.js'; +import { keyJsonToVKData } from '../../utils/vk_json.js'; +import type { ClientProtocolArtifact } from '../types.js'; + +export const ClientCircuitVks: Record = { + PrivateKernelInitArtifact: keyJsonToVKData(PrivateKernelInitVkJson), + PrivateKernelInnerArtifact: keyJsonToVKData(PrivateKernelInnerVkJson), + PrivateKernelTailArtifact: keyJsonToVKData(PrivateKernelTailVkJson), + PrivateKernelTailToPublicArtifact: keyJsonToVKData(PrivateKernelTailToPublicVkJson), + ...PrivateKernelResetVks, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/server.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/server.ts new file mode 100644 index 000000000000..f93e8dc43433 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/server.ts @@ -0,0 +1,66 @@ +import { + BASE_PARITY_INDEX, + BLOCK_MERGE_ROLLUP_INDEX, + BLOCK_ROOT_ROLLUP_EMPTY_INDEX, + BLOCK_ROOT_ROLLUP_INDEX, + BLOCK_ROOT_ROLLUP_SINGLE_TX_INDEX, + MERGE_ROLLUP_INDEX, + PRIVATE_BASE_ROLLUP_VK_INDEX, + PRIVATE_KERNEL_INIT_INDEX, + PRIVATE_KERNEL_INNER_INDEX, + PRIVATE_KERNEL_TAIL_INDEX, + PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, + PUBLIC_BASE_ROLLUP_VK_INDEX, + ROOT_PARITY_INDEX, + ROOT_ROLLUP_INDEX, +} from '@aztec/constants'; +import { VerificationKeyData } from '@aztec/stdlib/vks'; + +import BaseParityVkJson from '../../../artifacts/keys/parity_base.vk.data.json' assert { type: 'json' }; +import RootParityVkJson from '../../../artifacts/keys/parity_root.vk.data.json' assert { type: 'json' }; +import PrivateBaseRollupVkJson from '../../../artifacts/keys/rollup_base_private.vk.data.json' assert { type: 'json' }; +import PublicBaseRollupVkJson from '../../../artifacts/keys/rollup_base_public.vk.data.json' assert { type: 'json' }; +import BlockMergeRollupVkJson from '../../../artifacts/keys/rollup_block_merge.vk.data.json' assert { type: 'json' }; +import BlockRootRollupVkJson from '../../../artifacts/keys/rollup_block_root.vk.data.json' assert { type: 'json' }; +import EmptyBlockRootRollupVkJson from '../../../artifacts/keys/rollup_block_root_empty.vk.data.json' assert { type: 'json' }; +import SingleTxBlockRootRollupVkJson from '../../../artifacts/keys/rollup_block_root_single_tx.vk.data.json' assert { type: 'json' }; +import MergeRollupVkJson from '../../../artifacts/keys/rollup_merge.vk.data.json' assert { type: 'json' }; +import RootRollupVkJson from '../../../artifacts/keys/rollup_root.vk.data.json' assert { type: 'json' }; +import TubeVkJson from '../../../artifacts/keys/tube.vk.data.json' assert { type: 'json' }; +import { PrivateKernelResetVkIndexes } from '../../private_kernel_reset_vks.js'; +import { keyJsonToVKData } from '../../utils/vk_json.js'; +import type { ProtocolArtifact, ServerProtocolArtifact } from '../types.js'; + +// TODO Include this in the normal maps when the tube is implemented in noir +export const TubeVk = keyJsonToVKData(TubeVkJson); + +export const ServerCircuitVks: Record = { + BaseParityArtifact: keyJsonToVKData(BaseParityVkJson), + RootParityArtifact: keyJsonToVKData(RootParityVkJson), + PrivateBaseRollupArtifact: keyJsonToVKData(PrivateBaseRollupVkJson), + PublicBaseRollupArtifact: keyJsonToVKData(PublicBaseRollupVkJson), + MergeRollupArtifact: keyJsonToVKData(MergeRollupVkJson), + BlockRootRollupArtifact: keyJsonToVKData(BlockRootRollupVkJson), + SingleTxBlockRootRollupArtifact: keyJsonToVKData(SingleTxBlockRootRollupVkJson), + EmptyBlockRootRollupArtifact: keyJsonToVKData(EmptyBlockRootRollupVkJson), + BlockMergeRollupArtifact: keyJsonToVKData(BlockMergeRollupVkJson), + RootRollupArtifact: keyJsonToVKData(RootRollupVkJson), +}; + +export const ProtocolCircuitVkIndexes: Record = { + PrivateKernelInitArtifact: PRIVATE_KERNEL_INIT_INDEX, + PrivateKernelInnerArtifact: PRIVATE_KERNEL_INNER_INDEX, + PrivateKernelTailArtifact: PRIVATE_KERNEL_TAIL_INDEX, + PrivateKernelTailToPublicArtifact: PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX, + BaseParityArtifact: BASE_PARITY_INDEX, + RootParityArtifact: ROOT_PARITY_INDEX, + PrivateBaseRollupArtifact: PRIVATE_BASE_ROLLUP_VK_INDEX, + PublicBaseRollupArtifact: PUBLIC_BASE_ROLLUP_VK_INDEX, + MergeRollupArtifact: MERGE_ROLLUP_INDEX, + BlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_INDEX, + SingleTxBlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_SINGLE_TX_INDEX, + EmptyBlockRootRollupArtifact: BLOCK_ROOT_ROLLUP_EMPTY_INDEX, + BlockMergeRollupArtifact: BLOCK_MERGE_ROLLUP_INDEX, + RootRollupArtifact: ROOT_ROLLUP_INDEX, + ...PrivateKernelResetVkIndexes, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/entrypoint/vks.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/tree.ts similarity index 93% rename from yarn-project/noir-protocol-circuits-types/src/entrypoint/vks.ts rename to yarn-project/noir-protocol-circuits-types/src/artifacts/vks/tree.ts index 7adce69e83ba..c3e8843d7526 100644 --- a/yarn-project/noir-protocol-circuits-types/src/entrypoint/vks.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/vks/tree.ts @@ -4,9 +4,7 @@ import { assertLength } from '@aztec/foundation/serialize'; import type { MerkleTree } from '@aztec/foundation/trees'; import { VerificationKeyAsFields, VerificationKeyData } from '@aztec/stdlib/vks'; -import { vkTree } from '../vk_tree.js'; - -export * from '../artifacts/vks.js'; +import { vkTree } from '../../vk_tree.js'; export function getVKTree(): MerkleTree { return vkTree; diff --git a/yarn-project/noir-protocol-circuits-types/src/entrypoint/server.ts b/yarn-project/noir-protocol-circuits-types/src/entrypoint/server.ts deleted file mode 100644 index b8c031654a22..000000000000 --- a/yarn-project/noir-protocol-circuits-types/src/entrypoint/server.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from '../artifacts/server.js'; -export * from '../execution/server.js'; - -export { type ServerProtocolArtifact } from '../artifacts/types.js'; - -export { foreignCallHandler } from '../utils/server/foreign_call_handler.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/artifacts.ts b/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/artifacts.ts new file mode 100644 index 000000000000..d3360990c620 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/artifacts.ts @@ -0,0 +1,6 @@ +export * from '../../artifacts/server.js'; +export * from '../../execution/server.js'; + +export { type ServerProtocolArtifact } from '../../artifacts/types.js'; + +export { foreignCallHandler } from '../../utils/server/foreign_call_handler.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/vks.ts b/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/vks.ts new file mode 100644 index 000000000000..4cc055eb7a3f --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/entrypoint/server/vks.ts @@ -0,0 +1,13 @@ +import type { VerificationKeyData } from '@aztec/stdlib/vks'; + +import type { ProtocolArtifact } from '../../artifacts/types.js'; +import { ClientCircuitVks } from '../../artifacts/vks/client.js'; +import { ServerCircuitVks } from '../../artifacts/vks/server.js'; + +export { ServerCircuitVks, ProtocolCircuitVkIndexes, TubeVk } from '../../artifacts/vks/server.js'; +export { ClientCircuitVks } from '../../artifacts/vks/client.js'; + +export const ProtocolCircuitVks: Record = { + ...ClientCircuitVks, + ...ServerCircuitVks, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/entrypoint/vk-tree.ts b/yarn-project/noir-protocol-circuits-types/src/entrypoint/vk-tree.ts new file mode 100644 index 000000000000..9e6b3a6332db --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/entrypoint/vk-tree.ts @@ -0,0 +1 @@ +export { getVKTreeRoot, getVKSiblingPath, getVKIndex, getVKTree } from '../artifacts/vks/tree.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_client_artifacts_helper.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_client_artifacts_helper.ts index b012b8f22484..d73e13e112d1 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_client_artifacts_helper.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_client_artifacts_helper.ts @@ -21,6 +21,8 @@ function generateImports() { return ` import type { NoirCompiledCircuit } from '@aztec/stdlib/noir'; import type { ClientProtocolArtifact } from './artifacts/types.js'; + import { VerificationKeyData } from '@aztec/stdlib/vks'; + import { keyJsonToVKData } from './utils/vk_json.js'; `; } @@ -35,7 +37,7 @@ function generateArtifactNames() { `; } -function generateImportFunction() { +function generateCircuitArtifactImportFunction() { const cases = Object.values(ClientCircuitArtifactNames) .flatMap(artifactName => { const isReset = artifactName.includes('private_kernel_reset'); @@ -65,6 +67,24 @@ function generateImportFunction() { `; } +function generateVkImportFunction() { + const cases = Object.values(ClientCircuitArtifactNames).map(artifactName => { + return `case '${artifactName}': { + const { default: keyData } = await import(\"../artifacts/keys/${artifactName}.vk.data.json\"); + return keyJsonToVKData(keyData); + }`; + }); + + return ` + export async function getClientCircuitVkData(artifactName: string): Promise { + switch(artifactName) { + ${cases.join('\n')} + default: throw new Error(\`Unknown artifact: \${artifactName}\`); + } + } + `; +} + const main = async () => { const content = ` /* eslint-disable camelcase */ @@ -74,7 +94,9 @@ const main = async () => { ${generateArtifactNames()} - ${generateImportFunction()} + ${generateCircuitArtifactImportFunction()} + + ${generateVkImportFunction()} `; diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_tree.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_tree.ts index bcd7b580bf2a..b14813993969 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_tree.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_tree.ts @@ -7,7 +7,7 @@ import { fileURLToPath } from '@aztec/foundation/url'; import { promises as fs } from 'fs'; import type { ProtocolArtifact } from '../artifacts/types.js'; -import { ProtocolCircuitVkIndexes, ProtocolCircuitVks, TubeVk } from '../artifacts/vks.js'; +import { ProtocolCircuitVkIndexes, ProtocolCircuitVks, TubeVk } from '../entrypoint/server/vks.js'; const log = createConsoleLogger('autogenerate'); diff --git a/yarn-project/p2p/src/versioning.ts b/yarn-project/p2p/src/versioning.ts index 2123098c2250..3d1d638163a2 100644 --- a/yarn-project/p2p/src/versioning.ts +++ b/yarn-project/p2p/src/versioning.ts @@ -1,5 +1,5 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import type { ChainConfig } from '@aztec/stdlib/config'; import { diff --git a/yarn-project/protocol-contracts/package.json b/yarn-project/protocol-contracts/package.json index 1d7ba85a4003..510d5ac679e3 100644 --- a/yarn-project/protocol-contracts/package.json +++ b/yarn-project/protocol-contracts/package.json @@ -6,8 +6,10 @@ "type": "module", "exports": { ".": "./dest/index.js", - "./bundle": "./dest/bundle/index.js", - "./*": "./dest/*/index.js" + "./providers/bundle": "./dest/provider/bundle.js", + "./providers/lazy": "./dest/provider/lazy.js", + "./*": "./dest/*/index.js", + "./*/lazy": "./dest/*/lazy.js" }, "typedocOptions": { "entryPoints": [ diff --git a/yarn-project/protocol-contracts/src/auth-registry/lazy.ts b/yarn-project/protocol-contracts/src/auth-registry/lazy.ts new file mode 100644 index 000000000000..078e72f498c2 --- /dev/null +++ b/yarn-project/protocol-contracts/src/auth-registry/lazy.ts @@ -0,0 +1,24 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getAuthRegistryArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: authRegistryJson } = await import('../../artifacts/AuthRegistry.json'); + protocolContractArtifact = loadContractArtifact(authRegistryJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalAuthRegistry(): Promise { + if (!protocolContract) { + const authRegistryArtifact = await getAuthRegistryArtifact(); + protocolContract = await makeProtocolContract('AuthRegistry', authRegistryArtifact); + } + return protocolContract; +} diff --git a/yarn-project/protocol-contracts/src/class-registerer/lazy.ts b/yarn-project/protocol-contracts/src/class-registerer/lazy.ts new file mode 100644 index 000000000000..587b8b8ad0e8 --- /dev/null +++ b/yarn-project/protocol-contracts/src/class-registerer/lazy.ts @@ -0,0 +1,28 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +export * from './contract_class_registered_event.js'; +export * from './private_function_broadcasted_event.js'; +export * from './unconstrained_function_broadcasted_event.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getContractClassRegistererArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: contractClassRegistererJson } = await import('../../artifacts/ContractClassRegisterer.json'); + protocolContractArtifact = loadContractArtifact(contractClassRegistererJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalClassRegisterer(): Promise { + if (!protocolContract) { + const contractClassRegistererArtifact = await getContractClassRegistererArtifact(); + protocolContract = await makeProtocolContract('ContractClassRegisterer', contractClassRegistererArtifact); + } + return protocolContract; +} diff --git a/yarn-project/protocol-contracts/src/fee-juice/lazy.ts b/yarn-project/protocol-contracts/src/fee-juice/lazy.ts new file mode 100644 index 000000000000..fbd54d05bcd4 --- /dev/null +++ b/yarn-project/protocol-contracts/src/fee-juice/lazy.ts @@ -0,0 +1,24 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getFeeJuiceArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: feeJuiceJson } = await import('../../artifacts/FeeJuice.json'); + protocolContractArtifact = loadContractArtifact(feeJuiceJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalFeeJuice(): Promise { + if (!protocolContract) { + const feeJuiceArtifact = await getFeeJuiceArtifact(); + protocolContract = await makeProtocolContract('FeeJuice', feeJuiceArtifact); + } + return protocolContract; +} diff --git a/yarn-project/protocol-contracts/src/instance-deployer/lazy.ts b/yarn-project/protocol-contracts/src/instance-deployer/lazy.ts new file mode 100644 index 000000000000..aaf768a39124 --- /dev/null +++ b/yarn-project/protocol-contracts/src/instance-deployer/lazy.ts @@ -0,0 +1,27 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +export * from './contract_instance_deployed_event.js'; +export * from './contract_instance_updated_event.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getContractInstanceDeployerArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: contractInstanceDeployerJson } = await import('../../artifacts/ContractInstanceDeployer.json'); + protocolContractArtifact = loadContractArtifact(contractInstanceDeployerJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalInstanceDeployer(): Promise { + if (!protocolContract) { + const contractInstanceDeployerArtifact = await getContractInstanceDeployerArtifact(); + protocolContract = await makeProtocolContract('ContractInstanceDeployer', contractInstanceDeployerArtifact); + } + return protocolContract; +} diff --git a/yarn-project/protocol-contracts/src/multi-call-entrypoint/lazy.ts b/yarn-project/protocol-contracts/src/multi-call-entrypoint/lazy.ts new file mode 100644 index 000000000000..29088195a2d2 --- /dev/null +++ b/yarn-project/protocol-contracts/src/multi-call-entrypoint/lazy.ts @@ -0,0 +1,24 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getMultiCallEntrypointArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: multiCallEntrypointJson } = await import('../../artifacts/MultiCallEntrypoint.json'); + protocolContractArtifact = loadContractArtifact(multiCallEntrypointJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalMultiCallEntrypoint(): Promise { + if (!protocolContract) { + const multiCallEntrypointArtifact = await getMultiCallEntrypointArtifact(); + protocolContract = await makeProtocolContract('MultiCallEntrypoint', multiCallEntrypointArtifact); + } + return protocolContract; +} diff --git a/yarn-project/protocol-contracts/src/protocol_contract.ts b/yarn-project/protocol-contracts/src/protocol_contract.ts index 7df0fcccaafb..6544cdab1209 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract.ts @@ -19,3 +19,5 @@ export interface ProtocolContract { export function isProtocolContract(address: AztecAddress) { return Object.values(ProtocolContractAddress).some(a => a.equals(address)); } + +export { type ProtocolContractsProvider } from './provider/protocol_contracts_provider.js'; diff --git a/yarn-project/protocol-contracts/src/bundle/index.ts b/yarn-project/protocol-contracts/src/provider/bundle.ts similarity index 51% rename from yarn-project/protocol-contracts/src/bundle/index.ts rename to yarn-project/protocol-contracts/src/provider/bundle.ts index a91830414b35..9db1e3912bdc 100644 --- a/yarn-project/protocol-contracts/src/bundle/index.ts +++ b/yarn-project/protocol-contracts/src/provider/bundle.ts @@ -1,30 +1,15 @@ import type { ContractArtifact } from '@aztec/stdlib/abi'; -import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/stdlib/contract'; import { AuthRegistryArtifact } from '../auth-registry/index.js'; import { ContractClassRegistererArtifact } from '../class-registerer/index.js'; import { FeeJuiceArtifact } from '../fee-juice/index.js'; import { ContractInstanceDeployerArtifact } from '../instance-deployer/index.js'; +import { makeProtocolContract } from '../make_protocol_contract.js'; import { MultiCallEntrypointArtifact } from '../multi-call-entrypoint/index.js'; import type { ProtocolContract } from '../protocol_contract.js'; -import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from '../protocol_contract_data.js'; +import type { ProtocolContractName } from '../protocol_contract_data.js'; import { RouterArtifact } from '../router/index.js'; - -/** Returns the canonical deployment a given artifact. */ -export async function getCanonicalProtocolContract(name: ProtocolContractName): Promise { - const artifact = ProtocolContractArtifact[name]; - const address = ProtocolContractAddress[name]; - const salt = ProtocolContractSalt[name]; - // TODO(@spalladino): This computes the contract class from the artifact twice. - const contractClass = await getContractClassFromArtifact(artifact); - const instance = await getContractInstanceFromDeployParams(artifact, { salt }); - return { - instance: { ...instance, address }, - contractClass, - artifact, - address, - }; -} +import type { ProtocolContractsProvider } from './protocol_contracts_provider.js'; export const ProtocolContractArtifact: Record = { AuthRegistry: AuthRegistryArtifact, @@ -34,3 +19,9 @@ export const ProtocolContractArtifact: Record { + return makeProtocolContract(name, ProtocolContractArtifact[name]); + } +} diff --git a/yarn-project/protocol-contracts/src/provider/lazy.ts b/yarn-project/protocol-contracts/src/provider/lazy.ts new file mode 100644 index 000000000000..4007d45bf695 --- /dev/null +++ b/yarn-project/protocol-contracts/src/provider/lazy.ts @@ -0,0 +1,30 @@ +import { getCanonicalAuthRegistry } from '../auth-registry/lazy.js'; +import { getCanonicalClassRegisterer } from '../class-registerer/lazy.js'; +import { getCanonicalFeeJuice } from '../fee-juice/lazy.js'; +import { getCanonicalInstanceDeployer } from '../instance-deployer/lazy.js'; +import { getCanonicalMultiCallEntrypoint } from '../multi-call-entrypoint/lazy.js'; +import type { ProtocolContract } from '../protocol_contract.js'; +import type { ProtocolContractName } from '../protocol_contract_data.js'; +import { getCanonicalRouter } from '../router/lazy.js'; +import type { ProtocolContractsProvider } from './protocol_contracts_provider.js'; + +export class LazyProtocolContractsProvider implements ProtocolContractsProvider { + getProtocolContractArtifact(name: ProtocolContractName): Promise { + switch (name) { + case 'AuthRegistry': + return getCanonicalAuthRegistry(); + case 'ContractInstanceDeployer': + return getCanonicalInstanceDeployer(); + case 'ContractClassRegisterer': + return getCanonicalClassRegisterer(); + case 'MultiCallEntrypoint': + return getCanonicalMultiCallEntrypoint(); + case 'FeeJuice': + return getCanonicalFeeJuice(); + case 'Router': + return getCanonicalRouter(); + default: + throw new Error(`Unknown protocol contract name: ${name}`); + } + } +} diff --git a/yarn-project/protocol-contracts/src/provider/protocol_contracts_provider.ts b/yarn-project/protocol-contracts/src/provider/protocol_contracts_provider.ts new file mode 100644 index 000000000000..291bd6fe0bf2 --- /dev/null +++ b/yarn-project/protocol-contracts/src/provider/protocol_contracts_provider.ts @@ -0,0 +1,7 @@ +import type { ProtocolContract } from '../protocol_contract.js'; +import type { ProtocolContractName } from '../protocol_contract_data.js'; + +/** Returns the canonical deployment of a given artifact. */ +export interface ProtocolContractsProvider { + getProtocolContractArtifact(name: ProtocolContractName): Promise; +} diff --git a/yarn-project/protocol-contracts/src/router/lazy.ts b/yarn-project/protocol-contracts/src/router/lazy.ts new file mode 100644 index 000000000000..3dbcbcb88172 --- /dev/null +++ b/yarn-project/protocol-contracts/src/router/lazy.ts @@ -0,0 +1,24 @@ +import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; + +import { makeProtocolContract } from '../make_protocol_contract.js'; +import type { ProtocolContract } from '../protocol_contract.js'; + +let protocolContract: ProtocolContract; +let protocolContractArtifact: ContractArtifact; + +export async function getRouterArtifact(): Promise { + if (!protocolContractArtifact) { + const { default: routerJson } = await import('../../artifacts/Router.json'); + protocolContractArtifact = loadContractArtifact(routerJson); + } + return protocolContractArtifact; +} + +/** Returns the canonical deployment of the auth registry. */ +export async function getCanonicalRouter(): Promise { + if (!protocolContract) { + const routerArtifact = await getRouterArtifact(); + protocolContract = await makeProtocolContract('Router', routerArtifact); + } + return protocolContract; +} diff --git a/yarn-project/prover-client/src/block_builder/light.test.ts b/yarn-project/prover-client/src/block_builder/light.test.ts index 455c36ad63dd..950363b374dd 100644 --- a/yarn-project/prover-client/src/block_builder/light.test.ts +++ b/yarn-project/prover-client/src/block_builder/light.test.ts @@ -18,13 +18,8 @@ import { Fr } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { type Tuple, assertLength } from '@aztec/foundation/serialize'; import { MembershipWitness } from '@aztec/foundation/trees'; -import { - ProtocolCircuitVks, - TubeVk, - getVKIndex, - getVKSiblingPath, - getVKTreeRoot, -} from '@aztec/noir-protocol-circuits-types/vks'; +import { ProtocolCircuitVks, TubeVk } from '@aztec/noir-protocol-circuits-types/server/vks'; +import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice'; import { PublicDataWrite } from '@aztec/stdlib/avm'; diff --git a/yarn-project/prover-client/src/mocks/test_context.ts b/yarn-project/prover-client/src/mocks/test_context.ts index 72b0b119475f..57083d1b2468 100644 --- a/yarn-project/prover-client/src/mocks/test_context.ts +++ b/yarn-project/prover-client/src/mocks/test_context.ts @@ -3,7 +3,7 @@ import { times, timesParallel } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import type { Logger } from '@aztec/foundation/log'; import { TestDateProvider } from '@aztec/foundation/timer'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice'; import { diff --git a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts index 3e1e30c178f7..9e9f919f1bed 100644 --- a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts +++ b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts @@ -18,7 +18,7 @@ import { Fr } from '@aztec/foundation/fields'; import type { Logger } from '@aztec/foundation/log'; import { type Tuple, assertLength, serializeToBuffer, toFriendlyJSON } from '@aztec/foundation/serialize'; import { MembershipWitness, MerkleTreeCalculator, computeUnbalancedMerkleRoot } from '@aztec/foundation/trees'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice'; import { PublicDataHint } from '@aztec/stdlib/avm'; diff --git a/yarn-project/prover-client/src/orchestrator/block-proving-state.ts b/yarn-project/prover-client/src/orchestrator/block-proving-state.ts index cdc3fa92c8e5..5ef59db92b2c 100644 --- a/yarn-project/prover-client/src/orchestrator/block-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/block-proving-state.ts @@ -14,7 +14,7 @@ import { Fr } from '@aztec/foundation/fields'; import type { Logger } from '@aztec/foundation/log'; import type { Tuple } from '@aztec/foundation/serialize'; import { MembershipWitness, type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees'; -import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import type { L2Block } from '@aztec/stdlib/block'; import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server'; diff --git a/yarn-project/prover-client/src/orchestrator/epoch-proving-state.ts b/yarn-project/prover-client/src/orchestrator/epoch-proving-state.ts index c260e1cd93d9..ee3f626e4207 100644 --- a/yarn-project/prover-client/src/orchestrator/epoch-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/epoch-proving-state.ts @@ -8,7 +8,7 @@ import { import type { Fr } from '@aztec/foundation/fields'; import type { Tuple } from '@aztec/foundation/serialize'; import { MembershipWitness, type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees'; -import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree'; import type { ProofAndVerificationKey, PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server'; import type { Proof } from '@aztec/stdlib/proofs'; import { diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 9a1317a9b00e..a21afe660035 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -16,7 +16,7 @@ import { assertLength } from '@aztec/foundation/serialize'; import { pushTestData } from '@aztec/foundation/testing'; import { elapsed } from '@aztec/foundation/timer'; import type { TreeNodeLocation } from '@aztec/foundation/trees'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { L2Block } from '@aztec/stdlib/block'; import type { EpochProver, diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts index de1199da1203..712f23510469 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_multi_public_functions.test.ts @@ -2,7 +2,7 @@ import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants'; import { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import type { TestEnqueuedCall } from '@aztec/simulator/public/fixtures'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts index a79f95b3d8a7..d42ff5cb59e1 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_public_functions.test.ts @@ -1,7 +1,7 @@ import { createLogger } from '@aztec/foundation/log'; import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing'; import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing/files'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { mockTx } from '@aztec/stdlib/testing'; diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts b/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts index f217482dded9..1bb035e227f0 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator_workflow.test.ts @@ -3,7 +3,7 @@ import { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { sleep } from '@aztec/foundation/sleep'; -import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks'; +import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks'; import { type PublicInputsAndRecursiveProof, type ServerCircuitProver, diff --git a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts index 01185ee9f6a8..ceb1368b5223 100644 --- a/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts +++ b/yarn-project/prover-client/src/orchestrator/tx-proving-state.ts @@ -1,5 +1,5 @@ import { type AVM_PROOF_LENGTH_IN_FIELDS, AVM_VK_INDEX, type TUBE_PROOF_LENGTH, TUBE_VK_INDEX } from '@aztec/constants'; -import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree'; import type { AvmCircuitInputs } from '@aztec/stdlib/avm'; import type { ProofAndVerificationKey } from '@aztec/stdlib/interfaces/server'; import { diff --git a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts index a0229c89880a..212fff378ac5 100644 --- a/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_full_rollup.test.ts @@ -6,7 +6,7 @@ import { Fr } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing'; import { writeTestData } from '@aztec/foundation/testing/files'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { mockTx } from '@aztec/stdlib/testing'; import { getTelemetryClient } from '@aztec/telemetry-client'; diff --git a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts index a044d08861a3..bcbeb80f469e 100644 --- a/yarn-project/prover-client/src/test/bb_prover_parity.test.ts +++ b/yarn-project/prover-client/src/test/bb_prover_parity.test.ts @@ -8,12 +8,8 @@ import { makeTuple } from '@aztec/foundation/array'; import { randomBytes } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { createLogger } from '@aztec/foundation/log'; -import { - ProtocolCircuitVkIndexes, - ServerCircuitVks, - getVKSiblingPath, - getVKTreeRoot, -} from '@aztec/noir-protocol-circuits-types/vks'; +import { ProtocolCircuitVkIndexes, ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/server/vks'; +import { getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { BaseParityInputs, ParityPublicInputs, RootParityInput, RootParityInputs } from '@aztec/stdlib/parity'; import { makeRecursiveProof } from '@aztec/stdlib/proofs'; import { VerificationKeyAsFields } from '@aztec/stdlib/vks'; diff --git a/yarn-project/prover-node/src/prover-coordination/factory.ts b/yarn-project/prover-node/src/prover-coordination/factory.ts index ae2d793bda4b..7f0c22084ecd 100644 --- a/yarn-project/prover-node/src/prover-coordination/factory.ts +++ b/yarn-project/prover-node/src/prover-coordination/factory.ts @@ -3,7 +3,7 @@ import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover'; import type { EpochCache } from '@aztec/epoch-cache'; import { createLogger } from '@aztec/foundation/log'; import type { DataStoreConfig } from '@aztec/kv-store/config'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { createP2PClient } from '@aztec/p2p'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { createAztecNodeClient } from '@aztec/stdlib/interfaces/client'; diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index 3d4a105c860f..00c9409b7977 100644 --- a/yarn-project/pxe/src/kernel_oracle/index.ts +++ b/yarn-project/pxe/src/kernel_oracle/index.ts @@ -4,7 +4,7 @@ import { createLogger } from '@aztec/foundation/log'; import type { Tuple } from '@aztec/foundation/serialize'; import { MembershipWitness } from '@aztec/foundation/trees'; import type { KeyStore } from '@aztec/key-store'; -import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { ProtocolContractAddress } from '@aztec/protocol-contracts'; import type { FunctionSelector } from '@aztec/stdlib/abi'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 4fb97a61791c..3191a7e17890 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -5,7 +5,7 @@ import { createLogger } from '@aztec/foundation/log'; import { assertLength } from '@aztec/foundation/serialize'; import { pushTestData } from '@aztec/foundation/testing'; import { Timer } from '@aztec/foundation/timer'; -import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree'; import { getProtocolContractLeafAndMembershipWitness, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { AztecAddress } from '@aztec/stdlib/aztec-address'; import { computeContractAddressFromInstance } from '@aztec/stdlib/contract'; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index ac8949f178b1..731582230c2e 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -5,8 +5,11 @@ import { Timer } from '@aztec/foundation/timer'; import type { SiblingPath } from '@aztec/foundation/trees'; import type { KeyStore } from '@aztec/key-store'; import type { L2TipsStore } from '@aztec/kv-store/stores'; -import { ProtocolContractAddress, protocolContractNames } from '@aztec/protocol-contracts'; -import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; +import { + ProtocolContractAddress, + type ProtocolContractsProvider, + protocolContractNames, +} from '@aztec/protocol-contracts'; import { type AcirSimulator, type SimulationProvider, readCurrentClassId } from '@aztec/simulator/client'; import { type AbiDecoded, @@ -90,6 +93,7 @@ export class PXEService implements PXE { tipsStore: L2TipsStore, private proofCreator: PrivateKernelProver, private simulationProvider: SimulationProvider, + private protocolContractsProvider: ProtocolContractsProvider, config: PXEServiceConfig, loggerOrSuffix?: string | Logger, ) { @@ -609,7 +613,8 @@ export class PXEService implements PXE { async #registerProtocolContracts() { const registered: Record = {}; for (const name of protocolContractNames) { - const { address, contractClass, instance, artifact } = await getCanonicalProtocolContract(name); + const { address, contractClass, instance, artifact } = + await this.protocolContractsProvider.getProtocolContractArtifact(name); await this.db.addContractArtifact(contractClass.id, artifact); await this.db.addContractInstance(instance); registered[name] = address.toString(); diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts index 61439d9ca06f..363a97696b89 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts @@ -5,6 +5,8 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { KeyStore } from '@aztec/key-store'; import { openTmpStore } from '@aztec/kv-store/lmdb-v2'; import { L2TipsStore } from '@aztec/kv-store/stores'; +import type { ProtocolContractsProvider } from '@aztec/protocol-contracts'; +import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle'; import { type SimulationProvider, WASMSimulator } from '@aztec/simulator/client'; import { randomInBlock } from '@aztec/stdlib/block'; import type { AztecNode, PXE, PrivateKernelProver } from '@aztec/stdlib/interfaces/client'; @@ -27,6 +29,7 @@ async function createPXEService(): Promise { const simulationProvider = new WASMSimulator(); const kernelProver = new BBWASMBundlePrivateKernelProver(simulationProvider); const tips = new L2TipsStore(kvStore, 'pxe'); + const protocolContractsProvider = new BundledProtocolContractsProvider(); const config: PXEServiceConfig = { l2StartingBlock: INITIAL_L2_BLOCK_NUM, dataDirectory: undefined, @@ -56,7 +59,9 @@ async function createPXEService(): Promise { }; node.getL1ContractAddresses.mockResolvedValue(mockedContracts); - return Promise.resolve(new PXEService(keyStore, node, db, tips, kernelProver, simulationProvider, config)); + return Promise.resolve( + new PXEService(keyStore, node, db, tips, kernelProver, simulationProvider, protocolContractsProvider, config), + ); } pxeTestSuite('PXEService', createPXEService); @@ -69,6 +74,7 @@ describe('PXEService', () => { let kernelProver: PrivateKernelProver; let config: PXEServiceConfig; let tips: L2TipsStore; + let protocolContractsProvider: ProtocolContractsProvider; beforeEach(async () => { const kvStore = await openTmpStore('test'); @@ -78,6 +84,7 @@ describe('PXEService', () => { db = await KVPxeDatabase.create(kvStore); simulationProvider = new WASMSimulator(); kernelProver = new BBWASMBundlePrivateKernelProver(simulationProvider); + protocolContractsProvider = new BundledProtocolContractsProvider(); config = { l2StartingBlock: INITIAL_L2_BLOCK_NUM, @@ -96,7 +103,16 @@ describe('PXEService', () => { node.getTxEffect.mockResolvedValue(randomInBlock(settledTx)); - const pxe = new PXEService(keyStore, node, db, tips, kernelProver, simulationProvider, config); + const pxe = new PXEService( + keyStore, + node, + db, + tips, + kernelProver, + simulationProvider, + protocolContractsProvider, + config, + ); await expect(pxe.sendTx(duplicateTx)).rejects.toThrow(/A settled tx with equal hash/); }); }); diff --git a/yarn-project/pxe/src/utils/create_pxe_service.ts b/yarn-project/pxe/src/utils/create_pxe_service.ts index 57ed1f431a4c..546d1a5cc36d 100644 --- a/yarn-project/pxe/src/utils/create_pxe_service.ts +++ b/yarn-project/pxe/src/utils/create_pxe_service.ts @@ -5,6 +5,7 @@ import { createLogger } from '@aztec/foundation/log'; import { KeyStore } from '@aztec/key-store'; import { createStore } from '@aztec/kv-store/lmdb-v2'; import { L2TipsStore } from '@aztec/kv-store/stores'; +import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle'; import { type SimulationProvider, WASMSimulator } from '@aztec/simulator/client'; import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client'; @@ -48,7 +49,18 @@ export async function createPXEService( const tips = new L2TipsStore(store, 'pxe'); const simulationProvider = new WASMSimulator(); const prover = proofCreator ?? (await createProver(config, simulationProvider, logSuffix)); - const pxe = new PXEService(keyStore, aztecNode, db, tips, prover, simulationProvider, config, logSuffix); + const protocolContractsProvider = new BundledProtocolContractsProvider(); + const pxe = new PXEService( + keyStore, + aztecNode, + db, + tips, + prover, + simulationProvider, + protocolContractsProvider, + config, + logSuffix, + ); await pxe.init(); return pxe; } diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 4f96fb899251..2bd9fa2ccd55 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -4,7 +4,7 @@ import type { Logger } from '@aztec/foundation/log'; import { KeyStore } from '@aztec/key-store'; import { openTmpStore } from '@aztec/kv-store/lmdb-v2'; import { protocolContractNames } from '@aztec/protocol-contracts'; -import { getCanonicalProtocolContract } from '@aztec/protocol-contracts/bundle'; +import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle'; import { enrichPublicSimulationError } from '@aztec/pxe'; import type { TypedOracle } from '@aztec/simulator/client'; import { HashedValuesCache } from '@aztec/simulator/server'; @@ -46,8 +46,9 @@ export class TXEService { const keyStore = new KeyStore(store); const txeDatabase = new TXEDatabase(store); // Register protocol contracts. + const provider = new BundledProtocolContractsProvider(); for (const name of protocolContractNames) { - const { contractClass, instance, artifact } = await getCanonicalProtocolContract(name); + const { contractClass, instance, artifact } = await provider.getProtocolContractArtifact(name); await txeDatabase.addContractArtifact(contractClass.id, artifact); await txeDatabase.addContractInstance(instance); }