From e0be78b90e605f3f724ebae8676e637e2778d60e Mon Sep 17 00:00:00 2001 From: Cody Date: Thu, 5 Dec 2024 18:20:16 +0000 Subject: [PATCH 01/57] Playwright ReferenceError --- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 80 ++++++++++++++++++- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 11 ++- barretenberg/ts/src/barretenberg/backend.ts | 10 +++ barretenberg/ts/src/barretenberg_api/index.ts | 25 ++++++ .../browser_client_ivc_integration.test.ts | 38 ++------- yarn-project/ivc-integration/src/index.ts | 47 +++++++++++ yarn-project/ivc-integration/src/serve.ts | 3 +- 7 files changed, 177 insertions(+), 37 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 6e045c395c5d..cf09e9ef1485 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -10,7 +10,7 @@ #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" #include "barretenberg/serialize/msgpack.hpp" -#include "barretenberg/srs/global_crs.hpp" +#include "barretenberg/srs/global_crs.hpp" // WORKTODO: unused? #include "honk_contract.hpp" #include #include @@ -274,6 +274,84 @@ WASM_EXPORT void acir_prove_and_verify_aztec_client(uint8_t const* acir_stack, *verified = result; } +WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, + uint8_t const* witness_stack, + uint8_t** out_proof, + uint8_t** out_vk) +{ + using Program = acir_format::AcirProgram; + + std::vector> witnesses = from_buffer>>(witness_stack); + std::vector> acirs = from_buffer>>(acir_stack); + std::vector folding_stack; + + for (auto [bincode, wit] : zip_view(acirs, witnesses)) { + acir_format::WitnessVector witness = acir_format::witness_buf_to_witness_data(wit); + acir_format::AcirFormat constraints = + acir_format::circuit_buf_to_acir_format(bincode, /*honk_recursion=*/false); + folding_stack.push_back(Program{ constraints, witness }); + } + // TODO(#7371) dedupe this with the rest of the similar code + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1101): remove use of auto_verify_mode + ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE }, /*auto_verify_mode=*/true }; + + // Accumulate the entire program stack into the IVC + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1116): remove manual setting of is_kernel once databus + // has been integrated into noir kernel programs + bool is_kernel = false; + auto start = std::chrono::steady_clock::now(); + for (Program& program : folding_stack) { + // Construct a bberg circuit from the acir representation then accumulate it into the IVC + vinfo("constructing circuit..."); + auto circuit = acir_format::create_circuit( + program.constraints, false, 0, program.witness, false, ivc.goblin.op_queue); + + // Set the internal is_kernel flag based on the local mechanism only if it has not already been set to true + if (!circuit.databus_propagation_data.is_kernel) { + circuit.databus_propagation_data.is_kernel = is_kernel; + } + is_kernel = !is_kernel; + + vinfo("done constructing circuit. calling ivc.accumulate..."); + ivc.accumulate(circuit); + vinfo("done accumulating."); + } + auto end = std::chrono::steady_clock::now(); + auto diff = std::chrono::duration_cast(end - start); + vinfo("time to construct and accumulate all circuits: ", diff.count()); + + vinfo("calling ivc.prove ..."); + ClientIVC::Proof proof = ivc.prove(); + + end = std::chrono::steady_clock::now(); + diff = std::chrono::duration_cast(end - start); + vinfo("time to construct, accumulate, prove all circuits: ", diff.count()); + + *out_proof = to_heap_buffer(to_buffer(proof)); // WORKTODO: include size? + + auto eccvm_vk = std::make_shared(ivc.goblin.get_eccvm_proving_key()); + auto translator_vk = std::make_shared(ivc.goblin.get_translator_proving_key()); + *out_vk = to_heap_buffer(to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); +} + +WASM_EXPORT void acir_verify_client_ivc(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) +{ + // // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163): Set these dynamically + // init_bn254_crs(1); + // init_grumpkin_crs(1 << 15); + + const auto proof = from_buffer(from_buffer>(proof_buf)); + const auto vk = from_buffer(vk_buf); + + vk.mega->pcs_verification_key = std::make_shared>(); + vk.eccvm->pcs_verification_key = + std::make_shared>(vk.eccvm->circuit_size + 1); + vk.translator->pcs_verification_key = std::make_shared>(); + + const bool verified = ClientIVC::verify(proof, vk); + *result = verified; +} + WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, bool const* recursive, uint8_t const* witness_vec, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index 64197459b27b..ab2b5061d8c0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -41,8 +41,8 @@ WASM_EXPORT void acir_prove_and_verify_ultra_honk(uint8_t const* constraint_syst bool* result); /** - * @brief Construct and verify a MegaHonk proof - * + * @brief Construct and verify a ClientIVC proof + * @deprecated */ WASM_EXPORT void acir_prove_and_verify_mega_honk(uint8_t const* constraint_system_buf, bool const* recursive, @@ -53,6 +53,13 @@ WASM_EXPORT void acir_prove_and_verify_aztec_client(uint8_t const* constraint_sy uint8_t const* witness_buf, bool* result); +WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, + uint8_t const* witness_stack, + uint8_t** out_proof, + uint8_t** out_vk); + +WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result); + /** * @brief Fold and verify a set of circuits using ClientIvc * diff --git a/barretenberg/ts/src/barretenberg/backend.ts b/barretenberg/ts/src/barretenberg/backend.ts index db292c1a9268..2815d1282587 100644 --- a/barretenberg/ts/src/barretenberg/backend.ts +++ b/barretenberg/ts/src/barretenberg/backend.ts @@ -292,6 +292,16 @@ export class AztecClientBackend { } } + async prove(witnessMsgpack: Uint8Array[]): Promise<[Uint8Array, Uint8Array]> { + await this.instantiate(); + return this.api.acirProveAztecClient(this.acirMsgpack, witnessMsgpack); + } + + // async verify(proof: Uint8Array): Promise { + // await this.instantiate(); + // return this.api.acirVerifyAztecClient(proof, vk); + // } + async proveAndVerify(witnessMsgpack: Uint8Array[]): Promise { await this.instantiate(); return this.api.acirProveAndVerifyAztecClient(this.acirMsgpack, witnessMsgpack); diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 02cfcf5bf100..330ed1727a20 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -557,6 +557,31 @@ export class BarretenbergApi { return out[0]; } + async acirProveAztecClient(acirVec: Uint8Array[], witnessVec: Uint8Array[]): Promise<[Uint8Array, Uint8Array]> { + const inArgs = [acirVec, witnessVec].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_prove_aztec_client', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + // console.log(`number of things in out: ${out.length}`); + return [out[0], out[1]]; + } + + // async acirVerifyAztecClient(proofBuf: Uint8Array, vkBuf: Uint8Array): Promise { + // const inArgs = [proofBuf, vkBuf].map(serializeBufferable); + // const outTypes: OutputType[] = [BoolDeserializer()]; + // const result = await this.wasm.callWasmExport( + // 'acir_verify_aztec_client', + // inArgs, + // outTypes.map(t => t.SIZE_IN_BYTES), + // ); + // const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + // return out[0]; + // } + async acirProveUltraHonk(acirVec: Uint8Array, recursive: boolean, witnessVec: Uint8Array): Promise { const inArgs = [acirVec, recursive, witnessVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; diff --git a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts index 2c9332bc4918..3074b00d8fa2 100644 --- a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts @@ -1,18 +1,9 @@ import { jest } from '@jest/globals'; import chalk from 'chalk'; import createDebug from 'debug'; -import { - type Browser, - type Page, - chromium, - /* firefox, webkit */ -} from 'playwright'; +import { type Browser, type Page, chromium } from 'playwright'; -import { - generate3FunctionTestingIVCStack, - generate6FunctionTestingIVCStack, - proveAndVerifyAztecClient, -} from './index.js'; +import { generate3FunctionTestingIVCStack, proveThenVerifyAztecClient } from './index.js'; /* eslint-disable camelcase */ @@ -72,27 +63,8 @@ describe('Client IVC Integration', () => { it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { const [bytecodes, witnessStack] = await generate3FunctionTestingIVCStack(); - logger(`calling prove and verify...`); - const verifyResult = await proveAndVerifyAztecClient(page, bytecodes, witnessStack); - logger(`generated and verified proof. result: ${verifyResult}`); - - expect(verifyResult).toEqual(true); - }); - - // This test will verify a client IVC proof of a more complex tx: - // 1. Run a mock app that creates two commitments - // 2. Run the init kernel to process the app run - // 3. Run a mock app that reads one of those commitments - // 4. Run the inner kernel to process the second app run - // 5. Run the reset kernel to process the read request emitted by the reader app - // 6. Run the tail kernel to finish the client IVC chain - it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { - const [bytecodes, witnessStack] = await generate6FunctionTestingIVCStack(); - - logger(`calling prove and verify...`); - const verifyResult = await proveAndVerifyAztecClient(page, bytecodes, witnessStack); - logger(`generated and verified proof. result: ${verifyResult}`); - - expect(verifyResult).toEqual(true); + logger(`calling prove then verify...`); + const result = await proveThenVerifyAztecClient(page, bytecodes, witnessStack); + expect(result).toEqual(true); }); }); diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index dab8804a187e..4367efb5e311 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -252,6 +252,30 @@ export async function proveAndVerifyBrowser(bytecodes: string[], witnessStack: U return verified; } +export async function proveBrowser( + bytecodes: string[], + witnessStack: Uint8Array[], + threads?: number, +): Promise<[Uint8Array, Uint8Array]> { + const { AztecClientBackend } = await import('@aztec/bb.js'); + const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); + const backend = new AztecClientBackend(preparedBytecodes, { threads }); + const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); + + await backend.destroy(); // WORKTODO: share backend? + return [proof, vk]; +} + +// export async function verifyBrowser(proof: Uint8Array, threads?: number): Promise { +// const { AztecClientBackend } = await import('@aztec/bb.js'); +// const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); +// const backend = new AztecClientBackend(preparedBytecodes, { threads }); +// const verified = await backend.verify(proof); + +// await backend.destroy(); // WORKTODO: share backend +// return proof; +// } + export async function proveAndVerifyAztecClient( page: Page, bytecodes: string[], @@ -269,3 +293,26 @@ export async function proveAndVerifyAztecClient( return result; } + +// WORKTODO: This functions will construct a proof using the `prove` flow, then verify +// the proof using the accompanying vk using the `verify` flow. proveAndVerify instead just +// receives a boolean signal via a single call to a backend function. +export async function proveThenVerifyAztecClient( + page: Page, + bytecodes: string[], + witnessStack: Uint8Array[], +): Promise { + const threads = 16; + + const result: boolean = await page.evaluate( + ([acir, witness, numThreads]) => { + console.log('trying to assign proveBrowser'); + (window as any).proveBrowser = proveBrowser; + const _proof = (window as any).proveBrowser(acir, witness, numThreads); + return true; + }, + [bytecodes, witnessStack, threads], + ); + + return result; +} diff --git a/yarn-project/ivc-integration/src/serve.ts b/yarn-project/ivc-integration/src/serve.ts index b16a125a05cb..edbd44b71376 100644 --- a/yarn-project/ivc-integration/src/serve.ts +++ b/yarn-project/ivc-integration/src/serve.ts @@ -1,6 +1,6 @@ import createDebug from 'debug'; -import { generate3FunctionTestingIVCStack, proveAndVerifyBrowser } from './index.js'; +import { generate3FunctionTestingIVCStack, proveAndVerifyBrowser, proveBrowser } from './index.js'; createDebug.enable('*'); const logger = createDebug('aztec:ivc-test'); @@ -79,6 +79,7 @@ function setupConsoleOutput() { } (window as any).proveAndVerifyBrowser = proveAndVerifyBrowser; +(window as any).proveBroswer = proveBrowser; document.addEventListener('DOMContentLoaded', function () { setupConsoleOutput(); // Initialize console output capture From 6ac7cc577b3254019a18ee7c0024f3806c8a4e83 Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 6 Dec 2024 21:03:47 +0000 Subject: [PATCH 02/57] Prove flow executes --- barretenberg/ts/src/barretenberg_api/index.ts | 5 ++- yarn-project/ivc-integration/package.json | 2 +- .../browser_client_ivc_integration.test.ts | 4 +- yarn-project/ivc-integration/src/index.ts | 42 ++----------------- yarn-project/ivc-integration/src/serve.ts | 3 +- yarn-project/yarn.lock | 28 ++++++++++++- 6 files changed, 36 insertions(+), 48 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 330ed1727a20..853e1549ad19 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -559,14 +559,15 @@ export class BarretenbergApi { async acirProveAztecClient(acirVec: Uint8Array[], witnessVec: Uint8Array[]): Promise<[Uint8Array, Uint8Array]> { const inArgs = [acirVec, witnessVec].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; + const outTypes: OutputType[] = [BufferDeserializer(), BufferDeserializer()]; const result = await this.wasm.callWasmExport( 'acir_prove_aztec_client', inArgs, outTypes.map(t => t.SIZE_IN_BYTES), ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - // console.log(`number of things in out: ${out.length}`); + console.log(`number of things in outTypes: ${outTypes.length}`); + console.log(`number of things in out: ${out.length}`); return [out[0], out[1]]; } diff --git a/yarn-project/ivc-integration/package.json b/yarn-project/ivc-integration/package.json index 54c7f4097123..4389ae09ede2 100644 --- a/yarn-project/ivc-integration/package.json +++ b/yarn-project/ivc-integration/package.json @@ -72,7 +72,7 @@ "chalk": "^5.3.0", "change-case": "^5.4.4", "pako": "^2.1.0", - "playwright": "^1.48.2", + "playwright": "^1.49.0", "puppeteer": "^22.4.1", "tslib": "^2.4.0" }, diff --git a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts index 3074b00d8fa2..41e1e8b356cb 100644 --- a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; import createDebug from 'debug'; import { type Browser, type Page, chromium } from 'playwright'; -import { generate3FunctionTestingIVCStack, proveThenVerifyAztecClient } from './index.js'; +import { generate3FunctionTestingIVCStack, proveAndVerifyAztecClient } from './index.js'; /* eslint-disable camelcase */ @@ -64,7 +64,7 @@ describe('Client IVC Integration', () => { const [bytecodes, witnessStack] = await generate3FunctionTestingIVCStack(); logger(`calling prove then verify...`); - const result = await proveThenVerifyAztecClient(page, bytecodes, witnessStack); + const result = await proveAndVerifyAztecClient(page, bytecodes, witnessStack); expect(result).toEqual(true); }); }); diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index 4367efb5e311..ccc0be0670aa 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -243,27 +243,14 @@ function base64ToUint8Array(base64: string): Uint8Array { } export async function proveAndVerifyBrowser(bytecodes: string[], witnessStack: Uint8Array[], threads?: number) { - const { AztecClientBackend } = await import('@aztec/bb.js'); - const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); - const backend = new AztecClientBackend(preparedBytecodes, { threads }); - const verified = await backend.proveAndVerify(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - - await backend.destroy(); - return verified; -} - -export async function proveBrowser( - bytecodes: string[], - witnessStack: Uint8Array[], - threads?: number, -): Promise<[Uint8Array, Uint8Array]> { const { AztecClientBackend } = await import('@aztec/bb.js'); const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); const backend = new AztecClientBackend(preparedBytecodes, { threads }); const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - + logger(`proof length: ${proof.length}`); + logger(`vk length: ${vk.length}`); await backend.destroy(); // WORKTODO: share backend? - return [proof, vk]; + return true; } // export async function verifyBrowser(proof: Uint8Array, threads?: number): Promise { @@ -293,26 +280,3 @@ export async function proveAndVerifyAztecClient( return result; } - -// WORKTODO: This functions will construct a proof using the `prove` flow, then verify -// the proof using the accompanying vk using the `verify` flow. proveAndVerify instead just -// receives a boolean signal via a single call to a backend function. -export async function proveThenVerifyAztecClient( - page: Page, - bytecodes: string[], - witnessStack: Uint8Array[], -): Promise { - const threads = 16; - - const result: boolean = await page.evaluate( - ([acir, witness, numThreads]) => { - console.log('trying to assign proveBrowser'); - (window as any).proveBrowser = proveBrowser; - const _proof = (window as any).proveBrowser(acir, witness, numThreads); - return true; - }, - [bytecodes, witnessStack, threads], - ); - - return result; -} diff --git a/yarn-project/ivc-integration/src/serve.ts b/yarn-project/ivc-integration/src/serve.ts index edbd44b71376..b16a125a05cb 100644 --- a/yarn-project/ivc-integration/src/serve.ts +++ b/yarn-project/ivc-integration/src/serve.ts @@ -1,6 +1,6 @@ import createDebug from 'debug'; -import { generate3FunctionTestingIVCStack, proveAndVerifyBrowser, proveBrowser } from './index.js'; +import { generate3FunctionTestingIVCStack, proveAndVerifyBrowser } from './index.js'; createDebug.enable('*'); const logger = createDebug('aztec:ivc-test'); @@ -79,7 +79,6 @@ function setupConsoleOutput() { } (window as any).proveAndVerifyBrowser = proveAndVerifyBrowser; -(window as any).proveBroswer = proveBrowser; document.addEventListener('DOMContentLoaded', function () { setupConsoleOutput(); // Initialize console output capture diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index c53310ab30d3..7bdbf0feb0b0 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -730,7 +730,7 @@ __metadata: levelup: ^5.1.1 memdown: ^6.1.1 pako: ^2.1.0 - playwright: ^1.48.2 + playwright: ^1.49.0 puppeteer: ^22.4.1 resolve-typescript-plugin: ^2.0.1 serve: ^14.2.1 @@ -14827,7 +14827,16 @@ __metadata: languageName: node linkType: hard -"playwright@npm:1.48.2, playwright@npm:^1.48.2": +"playwright-core@npm:1.49.0": + version: 1.49.0 + resolution: "playwright-core@npm:1.49.0" + bin: + playwright-core: cli.js + checksum: d8423ad0cab2e672856529bf6b98b406e7e605da098b847b9b54ee8ebd8d716ed8880a9afff4b38f0a2e3f59b95661c74589116ce3ff2b5e0ae3561507086c94 + languageName: node + linkType: hard + +"playwright@npm:1.48.2": version: 1.48.2 resolution: "playwright@npm:1.48.2" dependencies: @@ -14842,6 +14851,21 @@ __metadata: languageName: node linkType: hard +"playwright@npm:^1.49.0": + version: 1.49.0 + resolution: "playwright@npm:1.49.0" + dependencies: + fsevents: 2.3.2 + playwright-core: 1.49.0 + dependenciesMeta: + fsevents: + optional: true + bin: + playwright: cli.js + checksum: f1bfb2fff65cad2ce996edab74ec231dfd21aeb5961554b765ce1eaec27efb87eaba37b00e91ecd27727b82861e5d8c230abe4960e93f6ada8be5ad1020df306 + languageName: node + linkType: hard + "pluralize@npm:^8.0.0": version: 8.0.0 resolution: "pluralize@npm:8.0.0" From f0194b05a1733ff7c776a3c40f5e9d5a0ef79b8e Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 6 Dec 2024 21:32:58 +0000 Subject: [PATCH 03/57] Verify flow fails, proof size read into bb is long 140B --- barretenberg/cpp/scripts/gzip-wasm.sh | 2 +- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 4 +++- barretenberg/ts/scripts/build_wasm.sh | 6 ++--- barretenberg/ts/src/barretenberg/backend.ts | 8 +++---- barretenberg/ts/src/barretenberg_api/index.ts | 22 +++++++++---------- yarn-project/ivc-integration/src/index.ts | 15 +++---------- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/barretenberg/cpp/scripts/gzip-wasm.sh b/barretenberg/cpp/scripts/gzip-wasm.sh index e5dd2ed1ea0e..fa52390df1c2 100755 --- a/barretenberg/cpp/scripts/gzip-wasm.sh +++ b/barretenberg/cpp/scripts/gzip-wasm.sh @@ -1,3 +1,3 @@ #!/bin/sh (cd ./build-wasm/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) -(cd ./build-wasm-threads/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) +(cd ./build-wasm-threads-assert/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index cf09e9ef1485..0189698ba4dd 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -334,14 +334,16 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, *out_vk = to_heap_buffer(to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); } -WASM_EXPORT void acir_verify_client_ivc(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) +WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) { // // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163): Set these dynamically // init_bn254_crs(1); // init_grumpkin_crs(1 << 15); const auto proof = from_buffer(from_buffer>(proof_buf)); + vinfo("proof size : ", proof.size()); const auto vk = from_buffer(vk_buf); + vinfo("vk.mega log size : ", vk.mega->log_circuit_size); vk.mega->pcs_verification_key = std::make_shared>(); vk.eccvm->pcs_verification_key = diff --git a/barretenberg/ts/scripts/build_wasm.sh b/barretenberg/ts/scripts/build_wasm.sh index e0e283a20f27..6d1b07f6f0fe 100755 --- a/barretenberg/ts/scripts/build_wasm.sh +++ b/barretenberg/ts/scripts/build_wasm.sh @@ -4,7 +4,7 @@ set -e if [ -z "$SKIP_CPP_BUILD" ]; then # Build the wasms and strip debug symbols. cd ../cpp - cmake --preset wasm-threads -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm-threads + cmake --preset wasm-threads-assert -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm-threads-assert if [ -z "$SKIP_ST_BUILD" ]; then cmake --preset wasm -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm fi @@ -20,5 +20,5 @@ fi # When building the browser bundle, both wasms are inlined directly. mkdir -p ./dest/node/barretenberg_wasm mkdir -p ./dest/node-cjs/barretenberg_wasm -cp ../cpp/build-wasm-threads/bin/barretenberg.wasm.gz ./dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz -cp ../cpp/build-wasm-threads/bin/barretenberg.wasm.gz ./dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +cp ../cpp/build-wasm-threads-assert/bin/barretenberg.wasm.gz ./dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +cp ../cpp/build-wasm-threads-assert/bin/barretenberg.wasm.gz ./dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz diff --git a/barretenberg/ts/src/barretenberg/backend.ts b/barretenberg/ts/src/barretenberg/backend.ts index 2815d1282587..424b011fa5b8 100644 --- a/barretenberg/ts/src/barretenberg/backend.ts +++ b/barretenberg/ts/src/barretenberg/backend.ts @@ -297,10 +297,10 @@ export class AztecClientBackend { return this.api.acirProveAztecClient(this.acirMsgpack, witnessMsgpack); } - // async verify(proof: Uint8Array): Promise { - // await this.instantiate(); - // return this.api.acirVerifyAztecClient(proof, vk); - // } + async verify(proof: Uint8Array, vk: Uint8Array): Promise { + await this.instantiate(); + return this.api.acirVerifyAztecClient(proof, vk); + } async proveAndVerify(witnessMsgpack: Uint8Array[]): Promise { await this.instantiate(); diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 853e1549ad19..4f1750fdf468 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -571,17 +571,17 @@ export class BarretenbergApi { return [out[0], out[1]]; } - // async acirVerifyAztecClient(proofBuf: Uint8Array, vkBuf: Uint8Array): Promise { - // const inArgs = [proofBuf, vkBuf].map(serializeBufferable); - // const outTypes: OutputType[] = [BoolDeserializer()]; - // const result = await this.wasm.callWasmExport( - // 'acir_verify_aztec_client', - // inArgs, - // outTypes.map(t => t.SIZE_IN_BYTES), - // ); - // const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - // return out[0]; - // } + async acirVerifyAztecClient(proofBuf: Uint8Array, vkBuf: Uint8Array): Promise { + const inArgs = [proofBuf, vkBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_verify_aztec_client', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } async acirProveUltraHonk(acirVec: Uint8Array, recursive: boolean, witnessVec: Uint8Array): Promise { const inArgs = [acirVec, recursive, witnessVec].map(serializeBufferable); diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index ccc0be0670aa..c854a8b8438a 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -249,20 +249,11 @@ export async function proveAndVerifyBrowser(bytecodes: string[], witnessStack: U const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); logger(`proof length: ${proof.length}`); logger(`vk length: ${vk.length}`); - await backend.destroy(); // WORKTODO: share backend? - return true; + const verified = await backend.verify(proof, vk); + await backend.destroy(); + return verified; } -// export async function verifyBrowser(proof: Uint8Array, threads?: number): Promise { -// const { AztecClientBackend } = await import('@aztec/bb.js'); -// const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); -// const backend = new AztecClientBackend(preparedBytecodes, { threads }); -// const verified = await backend.verify(proof); - -// await backend.destroy(); // WORKTODO: share backend -// return proof; -// } - export async function proveAndVerifyAztecClient( page: Page, bytecodes: string[], From 6597f6c0f9fe78c8cda3a0e5ce41330964c6840d Mon Sep 17 00:00:00 2001 From: Cody Date: Fri, 6 Dec 2024 23:29:27 +0000 Subject: [PATCH 04/57] Verify failing, logs not printing(..?) --- barretenberg/cpp/scripts/strip-wasm.sh | 2 +- .../cpp/src/barretenberg/common/serialize.hpp | 16 ++++++++++++++++ .../src/barretenberg/dsl/acir_proofs/c_bind.cpp | 10 ++++++++-- barretenberg/ts/scripts/build_wasm.sh | 6 +++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/scripts/strip-wasm.sh b/barretenberg/cpp/scripts/strip-wasm.sh index 502bccb6d32a..7f5f0efcc650 100755 --- a/barretenberg/cpp/scripts/strip-wasm.sh +++ b/barretenberg/cpp/scripts/strip-wasm.sh @@ -1,3 +1,3 @@ #!/bin/sh /opt/wasi-sdk/bin/llvm-strip ./build-wasm/bin/barretenberg.wasm -/opt/wasi-sdk/bin/llvm-strip ./build-wasm-threads/bin/barretenberg.wasm +/opt/wasi-sdk/bin/llvm-strip ./build-wasm-threads-assert/bin/barretenberg.wasm diff --git a/barretenberg/cpp/src/barretenberg/common/serialize.hpp b/barretenberg/cpp/src/barretenberg/common/serialize.hpp index ac68aa702bf9..3894d69120c8 100644 --- a/barretenberg/cpp/src/barretenberg/common/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/common/serialize.hpp @@ -477,6 +477,22 @@ template std::vector to_buffer( return buf; } +// By default, if calling to_buffer on a vector of types, we don't prefix the vector size. +template std::vector to_buffer_with_size(T const& value) +{ + using serialize::write; + std::vector buf{ 0, 0, 0, 0 }; + write(buf, value); + uint32_t size = static_cast(buf.size()) - 4; + std::vector size_buf; + write(size_buf, size); + buf[0] = size_buf[0]; + buf[1] = size_buf[1]; + buf[2] = size_buf[2]; + buf[3] = size_buf[3]; + return buf; +} + // Some types to describe fixed size buffers for c_bind arguments. using in_buf32 = uint8_t const*; using out_buf32 = uint8_t*; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 0189698ba4dd..a03b21723122 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -327,11 +327,17 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, diff = std::chrono::duration_cast(end - start); vinfo("time to construct, accumulate, prove all circuits: ", diff.count()); - *out_proof = to_heap_buffer(to_buffer(proof)); // WORKTODO: include size? + auto buf = to_buffer_with_size(proof); + vinfo("first four bytes", buf[0], buf[1], buf[2], buf[3]); + *out_proof = to_heap_buffer(buf); // WORKTODO: include size? auto eccvm_vk = std::make_shared(ivc.goblin.get_eccvm_proving_key()); auto translator_vk = std::make_shared(ivc.goblin.get_translator_proving_key()); - *out_vk = to_heap_buffer(to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); + + buf = to_buffer_with_size(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk }); + vinfo(buf[0], buf[1], buf[2], buf[3]); + vinfo("first four bytes", buf[0], buf[1], buf[2], buf[3]); + *out_vk = to_heap_buffer(buf); } WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) diff --git a/barretenberg/ts/scripts/build_wasm.sh b/barretenberg/ts/scripts/build_wasm.sh index 6d1b07f6f0fe..e0e283a20f27 100755 --- a/barretenberg/ts/scripts/build_wasm.sh +++ b/barretenberg/ts/scripts/build_wasm.sh @@ -4,7 +4,7 @@ set -e if [ -z "$SKIP_CPP_BUILD" ]; then # Build the wasms and strip debug symbols. cd ../cpp - cmake --preset wasm-threads-assert -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm-threads-assert + cmake --preset wasm-threads -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm-threads if [ -z "$SKIP_ST_BUILD" ]; then cmake --preset wasm -DCMAKE_MESSAGE_LOG_LEVEL=Warning && cmake --build --preset wasm fi @@ -20,5 +20,5 @@ fi # When building the browser bundle, both wasms are inlined directly. mkdir -p ./dest/node/barretenberg_wasm mkdir -p ./dest/node-cjs/barretenberg_wasm -cp ../cpp/build-wasm-threads-assert/bin/barretenberg.wasm.gz ./dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz -cp ../cpp/build-wasm-threads-assert/bin/barretenberg.wasm.gz ./dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +cp ../cpp/build-wasm-threads/bin/barretenberg.wasm.gz ./dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +cp ../cpp/build-wasm-threads/bin/barretenberg.wasm.gz ./dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz From 74420bb0415940a772092ef1d9e8a9a6248e3a5a Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 16:37:54 +0000 Subject: [PATCH 05/57] wait for pxe to synch before checking balances --- yarn-project/end-to-end/src/e2e_2_pxes.test.ts | 2 +- yarn-project/pxe/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index d3dded0788d4..db08c3bc0332 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -58,7 +58,7 @@ describe('e2e_2_pxes', () => { }); // TODO #10296 - it.skip('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { + it('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { const initialBalance = 987n; const transferAmount1 = 654n; const transferAmount2 = 323n; diff --git a/yarn-project/pxe/package.json b/yarn-project/pxe/package.json index 043184ef30cb..5d8768902c70 100644 --- a/yarn-project/pxe/package.json +++ b/yarn-project/pxe/package.json @@ -112,4 +112,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From 92ba76967a25231f5cdceb7a24109489cde8d86e Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 16:40:28 +0000 Subject: [PATCH 06/57] actually commit --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index f623bcf3d5da..0afbd12ba20b 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -1,5 +1,5 @@ // docs:start:token_utils -import { type AztecAddress, type DebugLogger, type Wallet } from '@aztec/aztec.js'; +import { type AztecAddress, type DebugLogger, type Wallet, retryUntil } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts.js'; export async function deployToken(adminWallet: Wallet, initialAdminBalance: bigint, logger: DebugLogger) { @@ -37,6 +37,17 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { + // Check if the wallet + const blockNumber = await wallet.getBlockNumber(); + await retryUntil( + async () => { + const status = await wallet.getSyncStatus(); + return blockNumber <= status.blocks; + }, + 'pxe synch', + 3600, + 1, + ); // Then check the balance const contractWithWallet = await TokenContract.at(token.address, wallet); const balance = await contractWithWallet.methods.balance_of_private(owner).simulate({ from: owner }); From 0337f73b2c2d49c7c4ee31b1374a2d21f395e039 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 17:04:00 +0000 Subject: [PATCH 07/57] comment --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index 0afbd12ba20b..320d3ef63472 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -37,7 +37,7 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { - // Check if the wallet + // Check if PXE has synced up to the latest block before checking the balances const blockNumber = await wallet.getBlockNumber(); await retryUntil( async () => { From a0483dbd86572d140af47c7604ba1b8100f5a7f9 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 17:35:37 +0000 Subject: [PATCH 08/57] fix --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 11 ----------- yarn-project/simulator/src/client/view_data_oracle.ts | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index 320d3ef63472..f69bb492fda1 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -37,17 +37,6 @@ export async function expectTokenBalance( expectedBalance: bigint, logger: DebugLogger, ) { - // Check if PXE has synced up to the latest block before checking the balances - const blockNumber = await wallet.getBlockNumber(); - await retryUntil( - async () => { - const status = await wallet.getSyncStatus(); - return blockNumber <= status.blocks; - }, - 'pxe synch', - 3600, - 1, - ); // Then check the balance const contractWithWallet = await TokenContract.at(token.address, wallet); const balance = await contractWithWallet.methods.balance_of_private(owner).simulate({ from: owner }); diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 67af9e77df39..bb69d8240c93 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -312,7 +312,7 @@ export class ViewDataOracle extends TypedOracle { public override async syncNotes() { const taggedLogsByRecipient = await this.db.syncTaggedLogs( this.contractAddress, - await this.aztecNode.getBlockNumber(), + await this.db.getBlockNumber(), this.scopes, ); for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { From 0fde995d8302a5555702f9eb4726db9341b321a5 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 9 Dec 2024 19:43:35 +0000 Subject: [PATCH 09/57] merge --- yarn-project/ethereum/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 0e34d8dcbf15..3300f21bba8c 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -91,4 +91,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From 0c6e72afc50a564feeed67f2434c994539281376 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 20:56:54 +0000 Subject: [PATCH 10/57] it works --- barretenberg/cpp/scripts/gzip-wasm.sh | 2 +- barretenberg/cpp/scripts/strip-wasm.sh | 2 +- .../cpp/src/barretenberg/common/serialize.hpp | 2 +- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 41 +++++++++++++++---- barretenberg/ts/src/barretenberg_api/index.ts | 4 +- barretenberg/ts/src/serialize/output_type.ts | 9 ++++ .../src/wasm_client_ivc_integration.test.ts | 11 +++-- 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/barretenberg/cpp/scripts/gzip-wasm.sh b/barretenberg/cpp/scripts/gzip-wasm.sh index fa52390df1c2..e5dd2ed1ea0e 100755 --- a/barretenberg/cpp/scripts/gzip-wasm.sh +++ b/barretenberg/cpp/scripts/gzip-wasm.sh @@ -1,3 +1,3 @@ #!/bin/sh (cd ./build-wasm/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) -(cd ./build-wasm-threads-assert/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) +(cd ./build-wasm-threads/bin && gzip barretenberg.wasm -c > barretenberg.wasm.gz) diff --git a/barretenberg/cpp/scripts/strip-wasm.sh b/barretenberg/cpp/scripts/strip-wasm.sh index 7f5f0efcc650..502bccb6d32a 100755 --- a/barretenberg/cpp/scripts/strip-wasm.sh +++ b/barretenberg/cpp/scripts/strip-wasm.sh @@ -1,3 +1,3 @@ #!/bin/sh /opt/wasi-sdk/bin/llvm-strip ./build-wasm/bin/barretenberg.wasm -/opt/wasi-sdk/bin/llvm-strip ./build-wasm-threads-assert/bin/barretenberg.wasm +/opt/wasi-sdk/bin/llvm-strip ./build-wasm-threads/bin/barretenberg.wasm diff --git a/barretenberg/cpp/src/barretenberg/common/serialize.hpp b/barretenberg/cpp/src/barretenberg/common/serialize.hpp index 3894d69120c8..500278d91f3f 100644 --- a/barretenberg/cpp/src/barretenberg/common/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/common/serialize.hpp @@ -483,7 +483,7 @@ template std::vector to_buffer_with_size(T const& value) using serialize::write; std::vector buf{ 0, 0, 0, 0 }; write(buf, value); - uint32_t size = static_cast(buf.size()) - 4; + uint32_t size = static_cast(buf.size() - 4); std::vector size_buf; write(size_buf, size); buf[0] = size_buf[0]; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index a03b21723122..5162181298d5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -15,6 +15,16 @@ #include #include +const auto print_buffer = [](const auto buf) { + std::cerr << std::showbase << std::hex; + std::cerr << static_cast(buf[0]) << static_cast(buf[1]) << static_cast(buf[2]) + << static_cast(buf[3]) << static_cast(buf[4]) << static_cast(buf[5]) + << static_cast(buf[6]) << static_cast(buf[7]) << static_cast(buf[8]) + << static_cast(buf[9]) << static_cast(buf[10]) << static_cast(buf[11]) + << static_cast(buf[12]) << static_cast(buf[13]) << static_cast(buf[14]) + << static_cast(buf[15]); +}; + WASM_EXPORT void acir_get_circuit_sizes( uint8_t const* acir_vec, bool const* recursive, bool const* honk_recursion, uint32_t* total, uint32_t* subgroup) { @@ -327,17 +337,24 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, diff = std::chrono::duration_cast(end - start); vinfo("time to construct, accumulate, prove all circuits: ", diff.count()); - auto buf = to_buffer_with_size(proof); - vinfo("first four bytes", buf[0], buf[1], buf[2], buf[3]); + vinfo("first 16 bytes of proof: "); + std::vector buf = to_buffer(proof); + print_buffer(buf); + + vinfo("first 16 bytes of heap buffer: "); *out_proof = to_heap_buffer(buf); // WORKTODO: include size? + print_buffer(*out_proof); auto eccvm_vk = std::make_shared(ivc.goblin.get_eccvm_proving_key()); auto translator_vk = std::make_shared(ivc.goblin.get_translator_proving_key()); - buf = to_buffer_with_size(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk }); - vinfo(buf[0], buf[1], buf[2], buf[3]); - vinfo("first four bytes", buf[0], buf[1], buf[2], buf[3]); + // vinfo("first entry of honk vk: ", ivc.honk_vk.get()[0]); + buf = to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk }); + vinfo("first 16 bytes of vk buffer: "); + print_buffer(buf); *out_vk = to_heap_buffer(buf); + vinfo("first 16 bytes of vk heap buffer: "); + print_buffer(*out_vk); } WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) @@ -345,10 +362,20 @@ WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t cons // // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163): Set these dynamically // init_bn254_crs(1); // init_grumpkin_crs(1 << 15); + auto proof_vec = from_buffer>(proof_buf); + vinfo("read proof_vec, first 16 bytes"); + print_buffer(proof_vec); - const auto proof = from_buffer(from_buffer>(proof_buf)); + const auto proof = from_buffer(proof_vec); vinfo("proof size : ", proof.size()); - const auto vk = from_buffer(vk_buf); + vinfo("read mega proofs, first entry"); + vinfo(proof.mega_proof[0]); + + auto vk_vec = from_buffer>(vk_buf); + vinfo("read vk_vec, first 16 bytes: "); + print_buffer(vk_vec); + const auto vk = from_buffer(vk_vec); + // info(*vk.mega); vinfo("vk.mega log size : ", vk.mega->log_circuit_size); vk.mega->pcs_verification_key = std::make_shared>(); diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 4f1750fdf468..1a91f02ff56e 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -566,8 +566,8 @@ export class BarretenbergApi { outTypes.map(t => t.SIZE_IN_BYTES), ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - console.log(`number of things in outTypes: ${outTypes.length}`); - console.log(`number of things in out: ${out.length}`); + // console.log(`number of things in outTypes: ${outTypes.length}`); + // console.log(`number of things in out: ${out.length}`); return [out[0], out[1]]; } diff --git a/barretenberg/ts/src/serialize/output_type.ts b/barretenberg/ts/src/serialize/output_type.ts index bb4f7778b402..dafedf63ffa0 100644 --- a/barretenberg/ts/src/serialize/output_type.ts +++ b/barretenberg/ts/src/serialize/output_type.ts @@ -51,3 +51,12 @@ export function StringDeserializer(): OutputType { }, }; } + +// export function MsgpackDeserializer(): OutputType { +// return { +// fromBuffer: (buf: Uint8Array | BufferReader) => { +// const reader = BufferReader.asReader(buf); +// return reader.readString(); +// }, +// }; +// } diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index 5f105b7f71ec..f894378f72cd 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -1,6 +1,7 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { jest } from '@jest/globals'; +import { writeFileSync } from 'fs'; import { ungzip } from 'pako'; import { @@ -55,8 +56,12 @@ describe('Client IVC Integration', () => { { threads }, ); - const verified = await backend.proveAndVerify(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - logger.debug(`finished running proveAndVerify ${verified}`); + const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); + writeFileSync('proof.bin', proof); + writeFileSync('vk.bin', vk); + logger.debug(`proof length: ${proof.length}`); + logger.debug(`vk length: ${vk.length}`); + const verified = await backend.verify(proof, vk); await backend.destroy(); return verified; } @@ -65,7 +70,7 @@ describe('Client IVC Integration', () => { // 1. Run a mock app that creates two commitments // 2. Run the init kernel to process the app run // 3. Run the tail kernel to finish the client IVC chain. - it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { + it.only('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { const tx = { number_of_calls: '0x1', }; From 589c402d729c3df39da48486d2b019a2756cf3c4 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 21:42:55 +0000 Subject: [PATCH 11/57] Clean up --- .../cpp/src/barretenberg/common/serialize.hpp | 16 ----- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 61 +++++-------------- barretenberg/ts/src/barretenberg_api/index.ts | 2 - barretenberg/ts/src/serialize/output_type.ts | 9 --- yarn-project/ivc-integration/src/index.ts | 2 - .../src/wasm_client_ivc_integration.test.ts | 5 -- 6 files changed, 14 insertions(+), 81 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/common/serialize.hpp b/barretenberg/cpp/src/barretenberg/common/serialize.hpp index 500278d91f3f..ac68aa702bf9 100644 --- a/barretenberg/cpp/src/barretenberg/common/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/common/serialize.hpp @@ -477,22 +477,6 @@ template std::vector to_buffer( return buf; } -// By default, if calling to_buffer on a vector of types, we don't prefix the vector size. -template std::vector to_buffer_with_size(T const& value) -{ - using serialize::write; - std::vector buf{ 0, 0, 0, 0 }; - write(buf, value); - uint32_t size = static_cast(buf.size() - 4); - std::vector size_buf; - write(size_buf, size); - buf[0] = size_buf[0]; - buf[1] = size_buf[1]; - buf[2] = size_buf[2]; - buf[3] = size_buf[3]; - return buf; -} - // Some types to describe fixed size buffers for c_bind arguments. using in_buf32 = uint8_t const*; using out_buf32 = uint8_t*; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 5162181298d5..3765f500fd64 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -10,21 +10,10 @@ #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" #include "barretenberg/serialize/msgpack.hpp" -#include "barretenberg/srs/global_crs.hpp" // WORKTODO: unused? #include "honk_contract.hpp" #include #include -const auto print_buffer = [](const auto buf) { - std::cerr << std::showbase << std::hex; - std::cerr << static_cast(buf[0]) << static_cast(buf[1]) << static_cast(buf[2]) - << static_cast(buf[3]) << static_cast(buf[4]) << static_cast(buf[5]) - << static_cast(buf[6]) << static_cast(buf[7]) << static_cast(buf[8]) - << static_cast(buf[9]) << static_cast(buf[10]) << static_cast(buf[11]) - << static_cast(buf[12]) << static_cast(buf[13]) << static_cast(buf[14]) - << static_cast(buf[15]); -}; - WASM_EXPORT void acir_get_circuit_sizes( uint8_t const* acir_vec, bool const* recursive, bool const* honk_recursion, uint32_t* total, uint32_t* subgroup) { @@ -332,59 +321,37 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, vinfo("calling ivc.prove ..."); ClientIVC::Proof proof = ivc.prove(); - end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); vinfo("time to construct, accumulate, prove all circuits: ", diff.count()); - vinfo("first 16 bytes of proof: "); - std::vector buf = to_buffer(proof); - print_buffer(buf); - - vinfo("first 16 bytes of heap buffer: "); - *out_proof = to_heap_buffer(buf); // WORKTODO: include size? - print_buffer(*out_proof); + start = std::chrono::steady_clock::now(); + *out_proof = to_heap_buffer(to_buffer(proof)); + end = std::chrono::steady_clock::now(); + diff = std::chrono::duration_cast(end - start); + vinfo("time to serialize proof: ", diff.count()); + start = std::chrono::steady_clock::now(); auto eccvm_vk = std::make_shared(ivc.goblin.get_eccvm_proving_key()); auto translator_vk = std::make_shared(ivc.goblin.get_translator_proving_key()); - - // vinfo("first entry of honk vk: ", ivc.honk_vk.get()[0]); - buf = to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk }); - vinfo("first 16 bytes of vk buffer: "); - print_buffer(buf); - *out_vk = to_heap_buffer(buf); - vinfo("first 16 bytes of vk heap buffer: "); - print_buffer(*out_vk); + *out_vk = to_heap_buffer(to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); + end = std::chrono::steady_clock::now(); + diff = std::chrono::duration_cast(end - start); + vinfo("time to serialize proof: ", diff.count()); } WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) { - // // TODO(https://github.com/AztecProtocol/barretenberg/issues/1163): Set these dynamically - // init_bn254_crs(1); - // init_grumpkin_crs(1 << 15); - auto proof_vec = from_buffer>(proof_buf); - vinfo("read proof_vec, first 16 bytes"); - print_buffer(proof_vec); - - const auto proof = from_buffer(proof_vec); - vinfo("proof size : ", proof.size()); - vinfo("read mega proofs, first entry"); - vinfo(proof.mega_proof[0]); - - auto vk_vec = from_buffer>(vk_buf); - vinfo("read vk_vec, first 16 bytes: "); - print_buffer(vk_vec); - const auto vk = from_buffer(vk_vec); - // info(*vk.mega); - vinfo("vk.mega log size : ", vk.mega->log_circuit_size); + + const auto proof = from_buffer(from_buffer>(proof_buf)); + const auto vk = from_buffer(from_buffer>(vk_buf)); vk.mega->pcs_verification_key = std::make_shared>(); vk.eccvm->pcs_verification_key = std::make_shared>(vk.eccvm->circuit_size + 1); vk.translator->pcs_verification_key = std::make_shared>(); - const bool verified = ClientIVC::verify(proof, vk); - *result = verified; + *result = ClientIVC::verify(proof, vk); } WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 1a91f02ff56e..1e642cec1743 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -566,8 +566,6 @@ export class BarretenbergApi { outTypes.map(t => t.SIZE_IN_BYTES), ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - // console.log(`number of things in outTypes: ${outTypes.length}`); - // console.log(`number of things in out: ${out.length}`); return [out[0], out[1]]; } diff --git a/barretenberg/ts/src/serialize/output_type.ts b/barretenberg/ts/src/serialize/output_type.ts index dafedf63ffa0..bb4f7778b402 100644 --- a/barretenberg/ts/src/serialize/output_type.ts +++ b/barretenberg/ts/src/serialize/output_type.ts @@ -51,12 +51,3 @@ export function StringDeserializer(): OutputType { }, }; } - -// export function MsgpackDeserializer(): OutputType { -// return { -// fromBuffer: (buf: Uint8Array | BufferReader) => { -// const reader = BufferReader.asReader(buf); -// return reader.readString(); -// }, -// }; -// } diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index c854a8b8438a..001809b2e8a1 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -247,8 +247,6 @@ export async function proveAndVerifyBrowser(bytecodes: string[], witnessStack: U const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); const backend = new AztecClientBackend(preparedBytecodes, { threads }); const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - logger(`proof length: ${proof.length}`); - logger(`vk length: ${vk.length}`); const verified = await backend.verify(proof, vk); await backend.destroy(); return verified; diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index f894378f72cd..0f47d5792665 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -1,7 +1,6 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { jest } from '@jest/globals'; -import { writeFileSync } from 'fs'; import { ungzip } from 'pako'; import { @@ -57,10 +56,6 @@ describe('Client IVC Integration', () => { ); const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - writeFileSync('proof.bin', proof); - writeFileSync('vk.bin', vk); - logger.debug(`proof length: ${proof.length}`); - logger.debug(`vk length: ${vk.length}`); const verified = await backend.verify(proof, vk); await backend.destroy(); return verified; From d445cb514480599a2170d5eef23dd49e7de36823 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 22:16:22 +0000 Subject: [PATCH 12/57] Rename and shuffle --- .../browser_client_ivc_integration.test.ts | 54 +++++++++++++++++-- yarn-project/ivc-integration/src/index.ts | 31 ++++------- yarn-project/ivc-integration/src/serve.ts | 6 +-- .../src/wasm_client_ivc_integration.test.ts | 35 ++---------- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts index 41e1e8b356cb..ada5bffd82b9 100644 --- a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts @@ -1,9 +1,18 @@ import { jest } from '@jest/globals'; import chalk from 'chalk'; import createDebug from 'debug'; -import { type Browser, type Page, chromium } from 'playwright'; +import { + type Browser, + type Page, + chromium, + /* firefox, webkit */ +} from 'playwright'; -import { generate3FunctionTestingIVCStack, proveAndVerifyAztecClient } from './index.js'; +import { + generate3FunctionTestingIVCStack, + generate6FunctionTestingIVCStack, + proveThenVerifyAztecClient, +} from './index.js'; /* eslint-disable camelcase */ @@ -40,6 +49,24 @@ function formatAndPrintLog(message: string): void { logger(formattedMessage); } +export async function proveThenVerifyAztecClientBrowser( + page: Page, + bytecodes: string[], + witnessStack: Uint8Array[], +): Promise { + const threads = 16; + + const result: boolean = await page.evaluate( + ([acir, witness, numThreads]) => { + (window as any).proveThenVerifyAztecClient = proveThenVerifyAztecClient; + return (window as any).proveThenVerifyAztecClient(acir, witness, numThreads); + }, + [bytecodes, witnessStack, threads], + ); + + return result; +} + describe('Client IVC Integration', () => { let page: Page; let browser: Browser; @@ -64,7 +91,26 @@ describe('Client IVC Integration', () => { const [bytecodes, witnessStack] = await generate3FunctionTestingIVCStack(); logger(`calling prove then verify...`); - const result = await proveAndVerifyAztecClient(page, bytecodes, witnessStack); - expect(result).toEqual(true); + const verifyResult = await proveThenVerifyAztecClientBrowser(page, bytecodes, witnessStack); + logger(`generated and verified proof. result: ${verifyResult}`); + + expect(verifyResult).toEqual(true); + }); + + // This test will verify a client IVC proof of a more complex tx: + // 1. Run a mock app that creates two commitments + // 2. Run the init kernel to process the app run + // 3. Run a mock app that reads one of those commitments + // 4. Run the inner kernel to process the second app run + // 5. Run the reset kernel to process the read request emitted by the reader app + // 6. Run the tail kernel to finish the client IVC chain + it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { + const [bytecodes, witnessStack] = await generate6FunctionTestingIVCStack(); + + logger(`calling prove and verify...`); + const verifyResult = await proveThenVerifyAztecClientBrowser(page, bytecodes, witnessStack); + logger(`generated and verified proof. result: ${verifyResult}`); + + expect(verifyResult).toEqual(true); }); }); diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index 001809b2e8a1..7a038b5b1e30 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -242,30 +242,19 @@ function base64ToUint8Array(base64: string): Uint8Array { return Uint8Array.from(atob(base64), c => c.charCodeAt(0)); } -export async function proveAndVerifyBrowser(bytecodes: string[], witnessStack: Uint8Array[], threads?: number) { - const { AztecClientBackend } = await import('@aztec/bb.js'); - const preparedBytecodes = bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)); - const backend = new AztecClientBackend(preparedBytecodes, { threads }); - const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - const verified = await backend.verify(proof, vk); - await backend.destroy(); - return verified; -} - -export async function proveAndVerifyAztecClient( - page: Page, +export async function proveThenVerifyAztecClient( bytecodes: string[], witnessStack: Uint8Array[], + threads?: number, ): Promise { - const threads = 16; - - const result: boolean = await page.evaluate( - ([acir, witness, numThreads]) => { - (window as any).proveAndVerifyBrowser = proveAndVerifyBrowser; - return (window as any).proveAndVerifyBrowser(acir, witness, numThreads); - }, - [bytecodes, witnessStack, threads], + const { AztecClientBackend } = await import('@aztec/bb.js'); + const backend = new AztecClientBackend( + bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)), + { threads }, ); - return result; + const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); + const verified = await backend.verify(proof, vk); + await backend.destroy(); + return verified; } diff --git a/yarn-project/ivc-integration/src/serve.ts b/yarn-project/ivc-integration/src/serve.ts index b16a125a05cb..be23f1055562 100644 --- a/yarn-project/ivc-integration/src/serve.ts +++ b/yarn-project/ivc-integration/src/serve.ts @@ -1,6 +1,6 @@ import createDebug from 'debug'; -import { generate3FunctionTestingIVCStack, proveAndVerifyBrowser } from './index.js'; +import { generate3FunctionTestingIVCStack, proveThenVerifyAztecClient } from './index.js'; createDebug.enable('*'); const logger = createDebug('aztec:ivc-test'); @@ -78,7 +78,7 @@ function setupConsoleOutput() { }; } -(window as any).proveAndVerifyBrowser = proveAndVerifyBrowser; +(window as any).proveThenVerifyAztecClient = proveThenVerifyAztecClient; document.addEventListener('DOMContentLoaded', function () { setupConsoleOutput(); // Initialize console output capture @@ -89,7 +89,7 @@ document.addEventListener('DOMContentLoaded', function () { logger(`generating circuit and witness...`); const [bytecodes, witnessStack] = await generate3FunctionTestingIVCStack(); logger(`done. proving and verifying...`); - const verified = await proveAndVerifyBrowser(bytecodes, witnessStack); + const verified = await proveThenVerifyAztecClient(bytecodes, witnessStack); logger(`verified? ${verified}`); }); document.body.appendChild(button); diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index 0f47d5792665..c55f27f274ac 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -1,7 +1,6 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { jest } from '@jest/globals'; -import { ungzip } from 'pako'; import { MOCK_MAX_COMMITMENTS_PER_TX, @@ -17,6 +16,7 @@ import { MockPrivateKernelResetVk, MockPrivateKernelTailCircuit, getVkAsFields, + proveThenVerifyAztecClient, witnessGenCreatorAppMockCircuit, witnessGenMockPrivateKernelInitCircuit, witnessGenMockPrivateKernelInnerCircuit, @@ -34,38 +34,11 @@ jest.setTimeout(120_000); describe('Client IVC Integration', () => { beforeEach(async () => {}); - function base64ToUint8Array(base64: string) { - const binaryString = atob(base64); - const len = binaryString.length; - const bytes = new Uint8Array(len); - for (let i = 0; i < len; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - return bytes; - } - - async function proveAndVerifyAztecClient( - witnessStack: Uint8Array[], - bytecodes: string[], - threads?: number, - ): Promise { - const { AztecClientBackend } = await import('@aztec/bb.js'); - const backend = new AztecClientBackend( - bytecodes.map(base64ToUint8Array).map((arr: Uint8Array) => ungzip(arr)), - { threads }, - ); - - const [proof, vk] = await backend.prove(witnessStack.map((arr: Uint8Array) => ungzip(arr))); - const verified = await backend.verify(proof, vk); - await backend.destroy(); - return verified; - } - // This test will verify a client IVC proof of a simple tx: // 1. Run a mock app that creates two commitments // 2. Run the init kernel to process the app run // 3. Run the tail kernel to finish the client IVC chain. - it.only('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { + it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { const tx = { number_of_calls: '0x1', }; @@ -96,7 +69,7 @@ describe('Client IVC Integration', () => { const witnessStack = [appWitnessGenResult.witness, initWitnessGenResult.witness, tailWitnessGenResult.witness]; logger.debug('built witness stack'); - const verifyResult = await proveAndVerifyAztecClient(witnessStack, bytecodes); + const verifyResult = await proveThenVerifyAztecClient(bytecodes, witnessStack); logger.debug(`generated and verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); @@ -163,7 +136,7 @@ describe('Client IVC Integration', () => { tailWitnessGenResult.witness, ]; - const verifyResult = await proveAndVerifyAztecClient(witnessStack, bytecodes); + const verifyResult = await proveThenVerifyAztecClient(bytecodes, witnessStack); logger.debug(`generated and verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); From 98ca403716a8cffc63453da2d2f9ac4250d48aa9 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 22:19:57 +0000 Subject: [PATCH 13/57] Tweak comments --- .../cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 2 +- .../src/browser_client_ivc_integration.test.ts | 6 +++--- .../ivc-integration/src/wasm_client_ivc_integration.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 3765f500fd64..6f856e9d4151 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -337,7 +337,7 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, *out_vk = to_heap_buffer(to_buffer(ClientIVC::VerificationKey{ ivc.honk_vk, eccvm_vk, translator_vk })); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); - vinfo("time to serialize proof: ", diff.count()); + vinfo("time to serialize vk: ", diff.count()); } WASM_EXPORT void acir_verify_aztec_client(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) diff --git a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts index ada5bffd82b9..74768e278b29 100644 --- a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts @@ -92,7 +92,7 @@ describe('Client IVC Integration', () => { logger(`calling prove then verify...`); const verifyResult = await proveThenVerifyAztecClientBrowser(page, bytecodes, witnessStack); - logger(`generated and verified proof. result: ${verifyResult}`); + logger(`generated then verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); }); @@ -107,9 +107,9 @@ describe('Client IVC Integration', () => { it('Should generate a verifiable client IVC proof from a simple mock tx via bb.js', async () => { const [bytecodes, witnessStack] = await generate6FunctionTestingIVCStack(); - logger(`calling prove and verify...`); + logger(`calling prove then verify...`); const verifyResult = await proveThenVerifyAztecClientBrowser(page, bytecodes, witnessStack); - logger(`generated and verified proof. result: ${verifyResult}`); + logger(`generated then verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); }); diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index c55f27f274ac..09611cae6058 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -70,7 +70,7 @@ describe('Client IVC Integration', () => { logger.debug('built witness stack'); const verifyResult = await proveThenVerifyAztecClient(bytecodes, witnessStack); - logger.debug(`generated and verified proof. result: ${verifyResult}`); + logger.debug(`generated then verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); }); @@ -137,7 +137,7 @@ describe('Client IVC Integration', () => { ]; const verifyResult = await proveThenVerifyAztecClient(bytecodes, witnessStack); - logger.debug(`generated and verified proof. result: ${verifyResult}`); + logger.debug(`generated then verified proof. result: ${verifyResult}`); expect(verifyResult).toEqual(true); }); From 99404856a51cbaa58f076c55a419b6cc8f6ea6a2 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 22:22:35 +0000 Subject: [PATCH 14/57] Revert playright version bump --- yarn-project/ivc-integration/package.json | 2 +- yarn-project/yarn.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/ivc-integration/package.json b/yarn-project/ivc-integration/package.json index 4389ae09ede2..54c7f4097123 100644 --- a/yarn-project/ivc-integration/package.json +++ b/yarn-project/ivc-integration/package.json @@ -72,7 +72,7 @@ "chalk": "^5.3.0", "change-case": "^5.4.4", "pako": "^2.1.0", - "playwright": "^1.49.0", + "playwright": "^1.48.2", "puppeteer": "^22.4.1", "tslib": "^2.4.0" }, diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 7bdbf0feb0b0..2a65a236703d 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -730,7 +730,7 @@ __metadata: levelup: ^5.1.1 memdown: ^6.1.1 pako: ^2.1.0 - playwright: ^1.49.0 + playwright: ^1.48.2 puppeteer: ^22.4.1 resolve-typescript-plugin: ^2.0.1 serve: ^14.2.1 From eb3bd8937a75584959e81c92e0373bd11f315533 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 22:24:11 +0000 Subject: [PATCH 15/57] Revert yarn.lock change --- yarn-project/yarn.lock | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 2a65a236703d..c53310ab30d3 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -14827,16 +14827,7 @@ __metadata: languageName: node linkType: hard -"playwright-core@npm:1.49.0": - version: 1.49.0 - resolution: "playwright-core@npm:1.49.0" - bin: - playwright-core: cli.js - checksum: d8423ad0cab2e672856529bf6b98b406e7e605da098b847b9b54ee8ebd8d716ed8880a9afff4b38f0a2e3f59b95661c74589116ce3ff2b5e0ae3561507086c94 - languageName: node - linkType: hard - -"playwright@npm:1.48.2": +"playwright@npm:1.48.2, playwright@npm:^1.48.2": version: 1.48.2 resolution: "playwright@npm:1.48.2" dependencies: @@ -14851,21 +14842,6 @@ __metadata: languageName: node linkType: hard -"playwright@npm:^1.49.0": - version: 1.49.0 - resolution: "playwright@npm:1.49.0" - dependencies: - fsevents: 2.3.2 - playwright-core: 1.49.0 - dependenciesMeta: - fsevents: - optional: true - bin: - playwright: cli.js - checksum: f1bfb2fff65cad2ce996edab74ec231dfd21aeb5961554b765ce1eaec27efb87eaba37b00e91ecd27727b82861e5d8c230abe4960e93f6ada8be5ad1020df306 - languageName: node - linkType: hard - "pluralize@npm:^8.0.0": version: 8.0.0 resolution: "pluralize@npm:8.0.0" From 65e3897db9d56d45f1f10fab5a2bce27025a9990 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 9 Dec 2024 23:16:57 +0000 Subject: [PATCH 16/57] Remove unused import --- yarn-project/ivc-integration/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/ivc-integration/src/index.ts b/yarn-project/ivc-integration/src/index.ts index 7a038b5b1e30..d3fc886bf437 100644 --- a/yarn-project/ivc-integration/src/index.ts +++ b/yarn-project/ivc-integration/src/index.ts @@ -3,7 +3,6 @@ import { type CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS } from '@aztec/circui import { type ForeignCallOutput, Noir } from '@noir-lang/noir_js'; import createDebug from 'debug'; import { ungzip } from 'pako'; -import { type Page } from 'playwright'; import MockAppCreatorCircuit from '../artifacts/app_creator.json' assert { type: 'json' }; import MockAppReaderCircuit from '../artifacts/app_reader.json' assert { type: 'json' }; From 2500fe29e858aa05b5b30a3f5bfddada60af727c Mon Sep 17 00:00:00 2001 From: Cody Date: Tue, 10 Dec 2024 02:34:16 +0000 Subject: [PATCH 17/57] Maybe Each is safer --- .../src/browser_client_ivc_integration.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts index 74768e278b29..7e6956cd10b6 100644 --- a/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/browser_client_ivc_integration.test.ts @@ -71,7 +71,7 @@ describe('Client IVC Integration', () => { let page: Page; let browser: Browser; - beforeAll(async () => { + beforeEach(async () => { browser = await chromium.launch({ headless: true }); const context = await browser.newContext(); page = await context.newPage(); @@ -79,7 +79,7 @@ describe('Client IVC Integration', () => { await page.goto('http://localhost:8080'); }); - afterAll(async () => { + afterEach(async () => { await browser.close(); }); From fe40d4fd92142bf2a34455ffc630369dc1a3ccbe Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 10 Dec 2024 05:48:49 +0000 Subject: [PATCH 18/57] fmt --- yarn-project/end-to-end/src/fixtures/token_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/end-to-end/src/fixtures/token_utils.ts b/yarn-project/end-to-end/src/fixtures/token_utils.ts index f69bb492fda1..f623bcf3d5da 100644 --- a/yarn-project/end-to-end/src/fixtures/token_utils.ts +++ b/yarn-project/end-to-end/src/fixtures/token_utils.ts @@ -1,5 +1,5 @@ // docs:start:token_utils -import { type AztecAddress, type DebugLogger, type Wallet, retryUntil } from '@aztec/aztec.js'; +import { type AztecAddress, type DebugLogger, type Wallet } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts.js'; export async function deployToken(adminWallet: Wallet, initialAdminBalance: bigint, logger: DebugLogger) { From 2028f3c081cdb35eda69e5bf281b8560d5db90fc Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 10 Dec 2024 11:37:39 +0000 Subject: [PATCH 19/57] initial approach --- barretenberg/ts/package.json | 2 +- barretenberg/ts/yarn.lock | 9 +- boxes/boxes/vite/package.json | 1 + boxes/boxes/vite/src/config.ts | 8 +- boxes/yarn.lock | 7 + noir/noir-repo/yarn.lock | 9 +- yarn-project/bb-prover/package.json | 2 + yarn-project/bb-prover/src/wasm/index.ts | 160 +++++++++++++++++++++ yarn-project/ethereum/package.json | 2 +- yarn-project/simulator/src/client/index.ts | 1 + yarn-project/yarn.lock | 3 +- 11 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 yarn-project/bb-prover/src/wasm/index.ts diff --git a/barretenberg/ts/package.json b/barretenberg/ts/package.json index d6995a1d921a..03f34be15758 100644 --- a/barretenberg/ts/package.json +++ b/barretenberg/ts/package.json @@ -53,7 +53,7 @@ }, "dependencies": { "comlink": "^4.4.1", - "commander": "^10.0.1", + "commander": "^12.1.0", "debug": "^4.3.4", "fflate": "^0.8.0", "pako": "^2.1.0", diff --git a/barretenberg/ts/yarn.lock b/barretenberg/ts/yarn.lock index d375496453c0..22aafa7eec42 100644 --- a/barretenberg/ts/yarn.lock +++ b/barretenberg/ts/yarn.lock @@ -38,7 +38,7 @@ __metadata: "@typescript-eslint/parser": ^5.54.1 buffer: ^6.0.3 comlink: ^4.4.1 - commander: ^10.0.1 + commander: ^12.1.0 copy-webpack-plugin: ^11.0.0 debug: ^4.3.4 eslint: ^8.35.0 @@ -2434,6 +2434,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^12.1.0": + version: 12.1.0 + resolution: "commander@npm:12.1.0" + checksum: 68e9818b00fc1ed9cdab9eb16905551c2b768a317ae69a5e3c43924c2b20ac9bb65b27e1cab36aeda7b6496376d4da908996ba2c0b5d79463e0fb1e77935d514 + languageName: node + linkType: hard + "commander@npm:^2.20.0": version: 2.20.3 resolution: "commander@npm:2.20.3" diff --git a/boxes/boxes/vite/package.json b/boxes/boxes/vite/package.json index cbc2f139190b..c91acd007561 100644 --- a/boxes/boxes/vite/package.json +++ b/boxes/boxes/vite/package.json @@ -16,6 +16,7 @@ "dependencies": { "@aztec/accounts": "portal:../../../yarn-project/accounts", "@aztec/aztec.js": "portal:../../../yarn-project/aztec.js", + "@aztec/bb-prover": "link:../../../yarn-project/bb-prover", "@aztec/circuit-types": "portal:../../../yarn-project/circuit-types", "@aztec/key-store": "link:../../../yarn-project/key-store", "@aztec/kv-store": "portal:../../../yarn-project/kv-store", diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index 0052072e235e..c7e0adcb9f83 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -1,7 +1,7 @@ import { AztecNode, Fr, - createDebugLogger, + createLogger, deriveMasterIncomingViewingSecretKey, } from "@aztec/aztec.js"; import { BoxReactContractArtifact } from "../artifacts/BoxReact"; @@ -11,7 +11,7 @@ import { createAztecNodeClient } from "@aztec/aztec.js"; import { PXEService } from "@aztec/pxe/service"; import { PXEServiceConfig, getPXEServiceConfig } from "@aztec/pxe/config"; import { KVPxeDatabase } from "@aztec/pxe/database"; -import { TestPrivateKernelProver } from "@aztec/pxe/kernel_prover"; +import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; import { KeyStore } from "@aztec/key-store"; import { PrivateKernelProver } from "@aztec/circuit-types"; import { L2TipsStore } from "@aztec/kv-store/stores"; @@ -33,7 +33,7 @@ export class PrivateEnv { const config = getPXEServiceConfig(); config.dataDirectory = "pxe"; const aztecNode = await createAztecNodeClient(this.nodeURL); - const proofCreator = new TestPrivateKernelProver(); + const proofCreator = new BBWasmPrivateKernelProver(); this.pxe = await this.createPXEService(aztecNode, config, proofCreator); const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey( this.secretKey, @@ -60,7 +60,7 @@ export class PrivateEnv { const store = await createStore( "pxe_data", configWithContracts, - createDebugLogger("aztec:pxe:data:indexeddb"), + createLogger("aztec:pxe:data:indexeddb"), ); const keyStore = new KeyStore(store); diff --git a/boxes/yarn.lock b/boxes/yarn.lock index 5be003018981..03288c2e13a6 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -27,6 +27,12 @@ __metadata: languageName: node linkType: soft +"@aztec/bb-prover@link:../../../yarn-project/bb-prover::locator=vite%40workspace%3Aboxes%2Fvite": + version: 0.0.0-use.local + resolution: "@aztec/bb-prover@link:../../../yarn-project/bb-prover::locator=vite%40workspace%3Aboxes%2Fvite" + languageName: node + linkType: soft + "@aztec/builder@npm:latest": version: 0.63.1 resolution: "@aztec/builder@npm:0.63.1" @@ -11434,6 +11440,7 @@ __metadata: dependencies: "@aztec/accounts": "portal:../../../yarn-project/accounts" "@aztec/aztec.js": "portal:../../../yarn-project/aztec.js" + "@aztec/bb-prover": "link:../../../yarn-project/bb-prover" "@aztec/circuit-types": "portal:../../../yarn-project/circuit-types" "@aztec/key-store": "link:../../../yarn-project/key-store" "@aztec/kv-store": "portal:../../../yarn-project/kv-store" diff --git a/noir/noir-repo/yarn.lock b/noir/noir-repo/yarn.lock index 3c8df2b1772b..07b6b677b621 100644 --- a/noir/noir-repo/yarn.lock +++ b/noir/noir-repo/yarn.lock @@ -226,7 +226,7 @@ __metadata: resolution: "@aztec/bb.js@portal:../../../../barretenberg/ts::locator=integration-tests%40workspace%3Acompiler%2Fintegration-tests" dependencies: comlink: ^4.4.1 - commander: ^10.0.1 + commander: ^12.1.0 debug: ^4.3.4 fflate: ^0.8.0 pako: ^2.1.0 @@ -9822,6 +9822,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^12.1.0": + version: 12.1.0 + resolution: "commander@npm:12.1.0" + checksum: 68e9818b00fc1ed9cdab9eb16905551c2b768a317ae69a5e3c43924c2b20ac9bb65b27e1cab36aeda7b6496376d4da908996ba2c0b5d79463e0fb1e77935d514 + languageName: node + linkType: hard + "commander@npm:^2.20.0": version: 2.20.3 resolution: "commander@npm:2.20.3" diff --git a/yarn-project/bb-prover/package.json b/yarn-project/bb-prover/package.json index 9ea893b29627..94309813903b 100644 --- a/yarn-project/bb-prover/package.json +++ b/yarn-project/bb-prover/package.json @@ -4,6 +4,7 @@ "type": "module", "exports": { ".": "./dest/index.js", + "./wasm": "./dest/wasm/index.js", "./prover": "./dest/prover/index.js", "./verifier": "./dest/verifier/index.js", "./test": "./dest/test/index.js" @@ -66,6 +67,7 @@ "testTimeout": 30000 }, "dependencies": { + "@aztec/bb.js": "portal:../../barretenberg/ts", "@aztec/circuit-types": "workspace:^", "@aztec/circuits.js": "workspace:^", "@aztec/foundation": "workspace:^", diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts new file mode 100644 index 000000000000..d5446fca9542 --- /dev/null +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -0,0 +1,160 @@ +import { AztecClientBackend } from '@aztec/bb.js'; +import { AppCircuitSimulateOutput, PrivateKernelProver, PrivateKernelSimulateOutput } from '@aztec/circuit-types'; +import { + CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, + ClientIvcProof, + PrivateKernelCircuitPublicInputs, + PrivateKernelInitCircuitPrivateInputs, + PrivateKernelInnerCircuitPrivateInputs, + PrivateKernelResetCircuitPrivateInputs, + PrivateKernelTailCircuitPrivateInputs, + PrivateKernelTailCircuitPublicInputs, + VerificationKeyAsFields, +} from '@aztec/circuits.js'; +import { createLogger } from '@aztec/foundation/log'; +import { Timer } from '@aztec/foundation/timer'; +import { + ClientCircuitArtifacts, + ClientCircuitVks, + ClientProtocolArtifact, + convertPrivateKernelInitInputsToWitnessMap, + convertPrivateKernelInitOutputsFromWitnessMap, + convertPrivateKernelInnerInputsToWitnessMap, + convertPrivateKernelInnerOutputsFromWitnessMap, + convertPrivateKernelResetInputsToWitnessMap, + convertPrivateKernelResetOutputsFromWitnessMap, + convertPrivateKernelTailForPublicOutputsFromWitnessMap, + convertPrivateKernelTailInputsToWitnessMap, + convertPrivateKernelTailOutputsFromWitnessMap, + convertPrivateKernelTailToPublicInputsToWitnessMap, + getPrivateKernelResetArtifactName, +} from '@aztec/noir-protocol-circuits-types'; +import { WASMSimulator } from '@aztec/simulator/client'; +import { NoirCompiledCircuit } from '@aztec/types/noir'; + +import { WitnessMap } from '@noir-lang/noir_js'; +import { serializeWitness } from '@noir-lang/noirc_abi'; +import { ungzip } from 'pako'; + +export class BBWasmPrivateKernelProver implements PrivateKernelProver { + private simulator = new WASMSimulator(); + + constructor(private log = createLogger('bb-prover:wasm')) {} + + public async simulateProofInit( + inputs: PrivateKernelInitCircuitPrivateInputs, + ): Promise> { + return await this.simulate( + inputs, + 'PrivateKernelInitArtifact', + convertPrivateKernelInitInputsToWitnessMap, + convertPrivateKernelInitOutputsFromWitnessMap, + ); + } + + public async simulateProofInner( + inputs: PrivateKernelInnerCircuitPrivateInputs, + ): Promise> { + return await this.simulate( + inputs, + 'PrivateKernelInnerArtifact', + convertPrivateKernelInnerInputsToWitnessMap, + convertPrivateKernelInnerOutputsFromWitnessMap, + ); + } + + public async simulateProofReset( + inputs: PrivateKernelResetCircuitPrivateInputs, + ): Promise> { + const variantInputs = inputs.trimToSizes(); + const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions); + return await this.simulate( + variantInputs, + artifactName, + variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName), + output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName), + ); + } + + public async simulateProofTail( + inputs: PrivateKernelTailCircuitPrivateInputs, + ): Promise> { + if (!inputs.isForPublic()) { + return await this.simulate( + inputs, + 'PrivateKernelTailArtifact', + convertPrivateKernelTailInputsToWitnessMap, + convertPrivateKernelTailOutputsFromWitnessMap, + ); + } + return await this.simulate( + inputs, + 'PrivateKernelTailToPublicArtifact', + convertPrivateKernelTailToPublicInputsToWitnessMap, + convertPrivateKernelTailForPublicOutputsFromWitnessMap, + ); + } + + private async simulate< + I extends { toBuffer: () => Buffer }, + O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs, + >( + inputs: I, + circuitType: ClientProtocolArtifact, + convertInputs: (inputs: I) => WitnessMap, + convertOutputs: (outputs: WitnessMap) => O, + ): Promise> { + this.log.debug(`Generating witness for ${circuitType}`); + const compiledCircuit: NoirCompiledCircuit = ClientCircuitArtifacts[circuitType]; + + const witnessMap = convertInputs(inputs); + const timer = new Timer(); + const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit); + const output = convertOutputs(outputWitness); + + this.log.debug(`Generated witness for ${circuitType}`, { + eventName: 'circuit-witness-generation', + circuitName: circuitType, + duration: timer.ms(), + inputSize: inputs.toBuffer().length, + outputSize: output.toBuffer().length, + }); + + const verificationKey = ClientCircuitVks[circuitType].keyAsFields; + const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64'); + + const kernelOutput: PrivateKernelSimulateOutput = { + publicInputs: output, + verificationKey, + outputWitness, + bytecode, + }; + return kernelOutput; + } + + async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise { + // TODO: ??? + const threads = 16; + const backend = new AztecClientBackend( + acirs.map(arr => ungzip(arr)), + { threads }, + ); + + const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => serializeWitness(witnessMap))); + return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk)); + } + + computeAppCircuitVerificationKey( + _bytecode: Buffer, + _appCircuitName?: string | undefined, + ): Promise { + const appCircuitProofOutput: AppCircuitSimulateOutput = { + verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), + }; + return Promise.resolve(appCircuitProofOutput); + } + + computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise { + return Promise.resolve(0); + } +} diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 0e34d8dcbf15..3300f21bba8c 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -91,4 +91,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} diff --git a/yarn-project/simulator/src/client/index.ts b/yarn-project/simulator/src/client/index.ts index 123138b079f9..3bff1cb6ec73 100644 --- a/yarn-project/simulator/src/client/index.ts +++ b/yarn-project/simulator/src/client/index.ts @@ -3,3 +3,4 @@ export * from './db_oracle.js'; export * from './pick_notes.js'; export * from './execution_note_cache.js'; export { extractPrivateCircuitPublicInputs } from './private_execution.js'; +export { WASMSimulator } from '../providers/acvm_wasm.js'; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index df1012b94986..1fb153f85601 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -281,6 +281,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/bb-prover@workspace:bb-prover" dependencies: + "@aztec/bb.js": "portal:../../barretenberg/ts" "@aztec/circuit-types": "workspace:^" "@aztec/circuits.js": "workspace:^" "@aztec/ethereum": "workspace:^" @@ -317,7 +318,7 @@ __metadata: resolution: "@aztec/bb.js@portal:../barretenberg/ts::locator=%40aztec%2Faztec3-packages%40workspace%3A." dependencies: comlink: ^4.4.1 - commander: ^10.0.1 + commander: ^12.1.0 debug: ^4.3.4 fflate: ^0.8.0 pako: ^2.1.0 From 5f963837c894afdc331c7994e465ce0664af518f Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 10 Dec 2024 14:05:08 +0000 Subject: [PATCH 20/57] working proving --- boxes/boxes/vite/src/config.ts | 8 ++++++-- boxes/boxes/vite/vite.config.ts | 8 +++++++- yarn-project/bb-prover/src/wasm/index.ts | 18 ++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index c7e0adcb9f83..e92dc0ed3b31 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -11,14 +11,18 @@ import { createAztecNodeClient } from "@aztec/aztec.js"; import { PXEService } from "@aztec/pxe/service"; import { PXEServiceConfig, getPXEServiceConfig } from "@aztec/pxe/config"; import { KVPxeDatabase } from "@aztec/pxe/database"; -import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; import { KeyStore } from "@aztec/key-store"; import { PrivateKernelProver } from "@aztec/circuit-types"; import { L2TipsStore } from "@aztec/kv-store/stores"; import { createStore } from "@aztec/kv-store/indexeddb"; +import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; + +import createDebug from "debug"; const SECRET_KEY = Fr.random(); +createDebug.enable("*"); + export class PrivateEnv { pxe; accountContract; @@ -33,7 +37,7 @@ export class PrivateEnv { const config = getPXEServiceConfig(); config.dataDirectory = "pxe"; const aztecNode = await createAztecNodeClient(this.nodeURL); - const proofCreator = new BBWasmPrivateKernelProver(); + const proofCreator = new BBWasmPrivateKernelProver(16); this.pxe = await this.createPXEService(aztecNode, config, proofCreator); const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey( this.secretKey, diff --git a/boxes/boxes/vite/vite.config.ts b/boxes/boxes/vite/vite.config.ts index eb101d8e821e..1eee22a8210e 100644 --- a/boxes/boxes/vite/vite.config.ts +++ b/boxes/boxes/vite/vite.config.ts @@ -23,6 +23,12 @@ const nodePolyfillsFix = (options?: PolyfillOptions | undefined): Plugin => { // https://vite.dev/config/ export default defineConfig({ + server: { + headers: { + "Cross-Origin-Opener-Policy": "same-origin", + "Cross-Origin-Embedder-Policy": "require-corp", + }, + }, plugins: [ react(), nodePolyfillsFix({ @@ -34,6 +40,6 @@ export default defineConfig({ topLevelAwait(), ], optimizeDeps: { - exclude: ["@noir-lang/acvm_js", "@noir-lang/noirc_abi"], + exclude: ["@noir-lang/acvm_js", "@noir-lang/noirc_abi", "@aztec/bb-prover"], }, }); diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts index d5446fca9542..9e9d5a251f52 100644 --- a/yarn-project/bb-prover/src/wasm/index.ts +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -39,7 +39,7 @@ import { ungzip } from 'pako'; export class BBWasmPrivateKernelProver implements PrivateKernelProver { private simulator = new WASMSimulator(); - constructor(private log = createLogger('bb-prover:wasm')) {} + constructor(private threads: number = 1, private log = createLogger('bb-prover:wasm')) {} public async simulateProofInit( inputs: PrivateKernelInitCircuitPrivateInputs, @@ -133,14 +133,20 @@ export class BBWasmPrivateKernelProver implements PrivateKernelProver { } async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise { - // TODO: ??? - const threads = 16; + const timer = new Timer(); + this.log.debug(`Generating ClientIVC proof...`); const backend = new AztecClientBackend( - acirs.map(arr => ungzip(arr)), - { threads }, + acirs.map(acir => ungzip(acir)), + { threads: this.threads }, ); - const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => serializeWitness(witnessMap))); + const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap)))); + this.log.debug(`Generated ClientIVC proof`, { + eventName: 'client-ivc-proof-generation', + duration: timer.ms(), + proofSize: proof.length, + vkSize: vk.length, + }); return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk)); } From d5a112669ce335c874431036483f59a51bac0d89 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 10 Dec 2024 17:39:18 +0000 Subject: [PATCH 21/57] wip --- boxes/boxes/vite/src/contracts/src/main.nr | 32 ++--- .../src/prover/bb_private_kernel_prover.ts | 119 +----------------- yarn-project/bb-prover/src/wasm/index.ts | 10 -- .../src/interfaces/private_kernel_prover.ts | 9 -- .../src/kernel_prover/kernel_prover.test.ts | 7 -- .../kernel_prover/test/test_circuit_prover.ts | 10 -- 6 files changed, 19 insertions(+), 168 deletions(-) diff --git a/boxes/boxes/vite/src/contracts/src/main.nr b/boxes/boxes/vite/src/contracts/src/main.nr index f4924981e8e4..8dbc05902f26 100644 --- a/boxes/boxes/vite/src/contracts/src/main.nr +++ b/boxes/boxes/vite/src/contracts/src/main.nr @@ -3,11 +3,11 @@ use dep::aztec::macros::aztec; #[aztec] contract BoxReact { use dep::aztec::{ - protocol_types::public_keys::OvpkM, - keys::getters::get_public_keys, - prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point}, encrypted_logs::encrypted_note_emission::encode_and_encrypt_note, - macros::{storage::storage, functions::{private, public, initializer}} + keys::getters::get_public_keys, + macros::{functions::{initializer, private}, storage::storage}, + prelude::{AztecAddress, Map, PrivateMutable}, + protocol_types::public_keys::OvpkM, }; use dep::value_note::value_note::ValueNote; @@ -18,27 +18,31 @@ contract BoxReact { #[private] #[initializer] - fn constructor( - number: Field, - owner: AztecAddress - ) { + fn constructor(number: Field, owner: AztecAddress) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner); let owner_ovpk_m = get_public_keys(owner).ovpk_m; - numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender())); + numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note( + &mut context, + owner_ovpk_m, + owner, + context.msg_sender(), + )); } #[private] - fn setNumber( - number: Field, - owner: AztecAddress - ) { + fn setNumber(number: Field, owner: AztecAddress) { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner); let owner_ovpk_m = get_public_keys(owner).ovpk_m; - numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner, context.msg_sender())); + numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note( + &mut context, + owner_ovpk_m, + owner, + context.msg_sender(), + )); } unconstrained fn getNumber(owner: AztecAddress) -> pub ValueNote { 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 53f18d20c2e0..7282df5980ac 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 @@ -48,15 +48,7 @@ import { type WitnessMap } from '@noir-lang/types'; import { promises as fs } from 'fs'; import path from 'path'; -import { - BB_RESULT, - PROOF_FIELDS_FILENAME, - PROOF_FILENAME, - computeGateCountForCircuit, - computeVerificationKey, - executeBbClientIvcProof, - verifyProof, -} from '../bb/execute.js'; +import { BB_RESULT, computeGateCountForCircuit, executeBbClientIvcProof, verifyProof } from '../bb/execute.js'; import { type BBConfig } from '../config.js'; import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js'; import { mapProtocolArtifactNameToCircuitName } from '../stats.js'; @@ -184,22 +176,6 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { ); } - public async computeAppCircuitVerificationKey( - bytecode: Buffer, - appCircuitName?: string, - ): Promise { - const operation = async (directory: string) => { - this.log.debug(`Proving app circuit`); - // App circuits are always recursive; the #[recursive] attribute used to be applied automatically - // by the `private` comptime macro in noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr - // Yet, inside `computeVerificationKey` the `mega_honk` flavor is used, which doesn't use the recursive flag. - const recursive = true; - return await this.computeVerificationKey(directory, bytecode, recursive, 'App', appCircuitName); - }; - - return await this.runInDirectory(operation); - } - /** * Verifies a proof, will generate the verification key if one is not cached internally * @param circuitType - The type of circuit whose proof is to be verified @@ -313,99 +289,6 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { return kernelOutput; } - private async computeVerificationKey( - directory: string, - bytecode: Buffer, - recursive: boolean, - circuitType: ClientProtocolArtifact | 'App', - appCircuitName?: string, - ): Promise<{ - verificationKey: VerificationKeyAsFields; - }> { - const dbgCircuitName = appCircuitName ? `(${appCircuitName})` : ''; - this.log.info(`Computing VK of ${circuitType}${dbgCircuitName} circuit...`); - - const timer = new Timer(); - - const vkResult = await computeVerificationKey( - this.bbBinaryPath, - directory, - circuitType, - bytecode, - recursive, - circuitType === 'App' ? 'mega_honk' : getUltraHonkFlavorForCircuit(circuitType), - this.log.debug, - ); - - if (vkResult.status === BB_RESULT.FAILURE) { - this.log.error(`Failed to generate verification key for ${circuitType}${dbgCircuitName}: ${vkResult.reason}`); - throw new Error(vkResult.reason); - } - - this.log.info(`Generated ${circuitType}${dbgCircuitName} VK in ${Math.ceil(timer.ms())} ms`); - - if (circuitType === 'App') { - const vkData = await extractVkData(directory); - - this.log.debug(`Computed verification key`, { - circuitName: 'app-circuit', - duration: vkResult.durationMs, - eventName: 'circuit-simulation', - inputSize: bytecode.length, - outputSize: vkData.keyAsBytes.length, - circuitSize: vkData.circuitSize, - numPublicInputs: vkData.numPublicInputs, - } as CircuitSimulationStats); - - return { verificationKey: vkData.keyAsFields }; - } - - const vkData = await this.updateVerificationKeyAfterSimulation(directory, circuitType); - - this.log.debug(`Computed verification key`, { - circuitName: mapProtocolArtifactNameToCircuitName(circuitType), - duration: vkResult.durationMs, - eventName: 'circuit-simulation', - inputSize: bytecode.length, - outputSize: vkData.keyAsBytes.length, - circuitSize: vkData.circuitSize, - numPublicInputs: vkData.numPublicInputs, - } as CircuitSimulationStats); - - return { verificationKey: vkData.keyAsFields }; - } - - /** - * Parses and returns the proof data stored at the specified directory - * @param filePath - The directory containing the proof data - * @param circuitType - The type of circuit proven - * @returns The proof - */ - private async readProofAsFields( - filePath: string, - circuitType: ClientProtocolArtifact | 'App', - vkData: VerificationKeyData, - ): Promise> { - const [binaryProof, proofString] = await Promise.all([ - fs.readFile(`${filePath}/${PROOF_FILENAME}`), - fs.readFile(`${filePath}/${PROOF_FIELDS_FILENAME}`, { encoding: 'utf-8' }), - ]); - const json = JSON.parse(proofString); - const fields = json.map(Fr.fromString); - const numPublicInputs = vkData.numPublicInputs - AGGREGATION_OBJECT_LENGTH; - const fieldsWithoutPublicInputs = fields.slice(numPublicInputs); - this.log.info( - `Circuit type: ${circuitType}, complete proof length: ${fields.length}, without public inputs: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}, is recursive: ${vkData.isRecursive}, raw length: ${binaryProof.length}`, - ); - const proof = new RecursiveProof( - fieldsWithoutPublicInputs, - new Proof(binaryProof, vkData.numPublicInputs), - true, - fieldsWithoutPublicInputs.length, - ); - return proof; - } - private runInDirectory(fn: (dir: string) => Promise) { const log = this.log; return runInDirectory( diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts index 9e9d5a251f52..369089d1f635 100644 --- a/yarn-project/bb-prover/src/wasm/index.ts +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -150,16 +150,6 @@ export class BBWasmPrivateKernelProver implements PrivateKernelProver { return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk)); } - computeAppCircuitVerificationKey( - _bytecode: Buffer, - _appCircuitName?: string | undefined, - ): Promise { - const appCircuitProofOutput: AppCircuitSimulateOutput = { - verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), - }; - return Promise.resolve(appCircuitProofOutput); - } - computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise { return Promise.resolve(0); } diff --git a/yarn-project/circuit-types/src/interfaces/private_kernel_prover.ts b/yarn-project/circuit-types/src/interfaces/private_kernel_prover.ts index 9dd399919ce7..f1ca3b8c0c62 100644 --- a/yarn-project/circuit-types/src/interfaces/private_kernel_prover.ts +++ b/yarn-project/circuit-types/src/interfaces/private_kernel_prover.ts @@ -98,15 +98,6 @@ export interface PrivateKernelProver { */ createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise; - /** - * Creates a proof for an app circuit. - * - * @param bytecode - The circuit bytecode in gzipped bincode format - * @param appCircuitName - Optionally specify the name of the app circuit - * @returns A Promise resolving to a Proof object - */ - computeAppCircuitVerificationKey(bytecode: Buffer, appCircuitName?: string): Promise; - /** * Compute the gate count for a given circuit. * @param bytecode - The circuit bytecode in gzipped bincode format diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index d7ae9401a9b5..7795a069f7e3 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -111,12 +111,6 @@ describe('Kernel Prover', () => { }; }; - const computeAppCircuitVerificationKeyOutput = () => { - return { - verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), - }; - }; - const expectExecution = (fns: string[]) => { const callStackItemsInit = proofCreator.simulateProofInit.mock.calls.map(args => String.fromCharCode(args[0].privateCall.publicInputs.callContext.functionSelector.value), @@ -157,7 +151,6 @@ describe('Kernel Prover', () => { proofCreator.simulateProofInner.mockResolvedValue(simulateProofOutput([])); proofCreator.simulateProofReset.mockResolvedValue(simulateProofOutput([])); proofCreator.simulateProofTail.mockResolvedValue(simulateProofOutputFinal([])); - proofCreator.computeAppCircuitVerificationKey.mockResolvedValue(computeAppCircuitVerificationKeyOutput()); prover = new KernelProver(oracle, proofCreator); }); diff --git a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts index deaa11cbd383..9f10f208dd5c 100644 --- a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts @@ -112,16 +112,6 @@ export class TestPrivateKernelProver implements PrivateKernelProver { return Promise.resolve(0); } - computeAppCircuitVerificationKey( - _bytecode: Buffer, - _appCircuitName?: string | undefined, - ): Promise { - const appCircuitProofOutput: AppCircuitSimulateOutput = { - verificationKey: VerificationKeyAsFields.makeEmpty(CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS), - }; - return Promise.resolve(appCircuitProofOutput); - } - private makeEmptyKernelSimulateOutput< PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs, >(publicInputs: PublicInputsType, circuitType: ProtocolArtifact) { From 4835dec5221f9aab18a2f334e8baf9390a62ff24 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 08:07:37 +0000 Subject: [PATCH 22/57] increased crs size --- barretenberg/ts/src/barretenberg/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 4cd972257b7d..688759c18bb5 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -68,8 +68,8 @@ export class Barretenberg extends BarretenbergApi { async initSRSClientIVC(): Promise { // crsPath can be undefined - const crs = await Crs.new(2 ** 19 + 1, this.options.crsPath); - const grumpkinCrs = await GrumpkinCrs.new(2 ** 14 + 1, this.options.crsPath); + const crs = await Crs.new(2 ** 20 + 1, this.options.crsPath); + const grumpkinCrs = await GrumpkinCrs.new(2 ** 15 + 1, this.options.crsPath); // Load CRS into wasm global CRS state. // TODO: Make RawBuffer be default behavior, and have a specific Vector type for when wanting length prefixed. From 2e16af9557aac66e8eb52f6373acd114ce1aa47e Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 08:54:45 +0000 Subject: [PATCH 23/57] updated contract --- boxes/boxes/vite/src/contracts/src/main.nr | 6 ------ 1 file changed, 6 deletions(-) diff --git a/boxes/boxes/vite/src/contracts/src/main.nr b/boxes/boxes/vite/src/contracts/src/main.nr index 8dbc05902f26..6955a87ecb4e 100644 --- a/boxes/boxes/vite/src/contracts/src/main.nr +++ b/boxes/boxes/vite/src/contracts/src/main.nr @@ -4,10 +4,8 @@ use dep::aztec::macros::aztec; contract BoxReact { use dep::aztec::{ encrypted_logs::encrypted_note_emission::encode_and_encrypt_note, - keys::getters::get_public_keys, macros::{functions::{initializer, private}, storage::storage}, prelude::{AztecAddress, Map, PrivateMutable}, - protocol_types::public_keys::OvpkM, }; use dep::value_note::value_note::ValueNote; @@ -22,10 +20,8 @@ contract BoxReact { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner); - let owner_ovpk_m = get_public_keys(owner).ovpk_m; numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note( &mut context, - owner_ovpk_m, owner, context.msg_sender(), )); @@ -36,10 +32,8 @@ contract BoxReact { let numbers = storage.numbers; let mut new_number = ValueNote::new(number, owner); - let owner_ovpk_m = get_public_keys(owner).ovpk_m; numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note( &mut context, - owner_ovpk_m, owner, context.msg_sender(), )); From 712f25e25cc6ba838aa0d48aeb2530c3e16e3117 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 11:47:59 +0000 Subject: [PATCH 24/57] synchronize on demand --- .../aztec.js/src/contract/sent_tx.test.ts | 14 ---- yarn-project/aztec.js/src/contract/sent_tx.ts | 11 +-- yarn-project/aztec.js/src/index.ts | 1 - .../aztec.js/src/wallet/base_wallet.ts | 7 -- yarn-project/bot/src/factory.ts | 11 --- .../circuit-types/src/interfaces/index.ts | 1 - .../circuit-types/src/interfaces/pxe.test.ts | 19 ------ .../circuit-types/src/interfaces/pxe.ts | 19 ------ .../src/interfaces/sync-status.ts | 13 ---- yarn-project/cli/src/cmds/pxe/get_block.ts | 23 +------ yarn-project/cli/src/cmds/pxe/index.ts | 3 +- .../benchmarks/bench_process_history.test.ts | 4 +- .../benchmarks/bench_publish_rollup.test.ts | 4 +- .../end-to-end/src/benchmarks/utils.ts | 7 +- .../end-to-end/src/e2e_2_pxes.test.ts | 12 ---- .../end-to-end/src/e2e_block_building.test.ts | 8 --- yarn-project/pxe/src/bin/index.ts | 2 +- .../pxe/src/database/kv_pxe_database.ts | 10 --- yarn-project/pxe/src/database/pxe_database.ts | 13 ---- yarn-project/pxe/src/index.ts | 1 - .../pxe/src/pxe_service/create_pxe_service.ts | 6 +- yarn-project/pxe/src/pxe_service/index.ts | 1 + .../pxe/src/pxe_service/pxe_service.ts | 26 ++----- .../src/pxe_service/test/pxe_test_suite.ts | 3 - yarn-project/pxe/src/simulator/index.ts | 3 + .../pxe/src/simulator_oracle/index.ts | 23 ++++++- .../simulator_oracle/simulator_oracle.test.ts | 5 +- .../pxe/src/synchronizer/synchronizer.ts | 64 ++---------------- yarn-project/pxe/src/utils/index.ts | 67 ------------------- .../simulator/src/client/db_oracle.ts | 8 +++ .../simulator/src/client/view_data_oracle.ts | 11 +-- 31 files changed, 64 insertions(+), 336 deletions(-) delete mode 100644 yarn-project/circuit-types/src/interfaces/sync-status.ts delete mode 100644 yarn-project/pxe/src/utils/index.ts diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts index c2bf65adb6a3..c0f7daf8a57b 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.test.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.test.ts @@ -23,22 +23,8 @@ describe('SentTx', () => { pxe.getTxReceipt.mockResolvedValue(txReceipt); }); - it('waits for all notes of the accounts to be available', async () => { - pxe.getSyncStatus.mockResolvedValueOnce({ blocks: 25 }).mockResolvedValueOnce({ blocks: 25 }); - - const actual = await sentTx.wait({ timeout: 1, interval: 0.4 }); - expect(actual).toEqual(txReceipt); - }); - - it('does not wait for notes sync', async () => { - pxe.getSyncStatus.mockResolvedValue({ blocks: 19 }); - const actual = await sentTx.wait({ timeout: 1, interval: 0.4, waitForNotesAvailable: false }); - expect(actual).toEqual(txReceipt); - }); - it('throws if tx is dropped', async () => { pxe.getTxReceipt.mockResolvedValue({ ...txReceipt, status: TxStatus.DROPPED } as TxReceipt); - pxe.getSyncStatus.mockResolvedValue({ blocks: 19 }); await expect(sentTx.wait({ timeout: 1, interval: 0.4, ignoreDroppedReceiptsFor: 0 })).rejects.toThrow(/dropped/); }); diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index b7803975b160..fb2d0e875496 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -124,16 +124,7 @@ export class SentTx { } return undefined; } - // If we don't care about waiting for notes to be synced, return the receipt - const waitForNotesAvailable = opts?.waitForNotesAvailable ?? DefaultWaitOpts.waitForNotesAvailable; - if (!waitForNotesAvailable) { - return txReceipt; - } - // Check if all sync blocks on the PXE Service are greater or equal than the block in which the tx was mined - const { blocks } = await this.pxe.getSyncStatus(); - const targetBlock = txReceipt.blockNumber!; - const areNotesAvailable = blocks >= targetBlock; - return areNotesAvailable ? txReceipt : undefined; + return txReceipt; }, 'isMined', opts?.timeout ?? DefaultWaitOpts.timeout, diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 4c42ac375de9..c4a15950273f 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -149,7 +149,6 @@ export { type PXE, type PartialAddress, type PublicKey, - type SyncStatus, } from '@aztec/circuit-types'; // TODO: These kinds of things have no place on our public api. diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 35694b490f5d..e455ee4c0be9 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -10,7 +10,6 @@ import { type PXEInfo, type PrivateExecutionResult, type SiblingPath, - type SyncStatus, type Tx, type TxExecutionRequest, type TxHash, @@ -170,12 +169,6 @@ export abstract class BaseWallet implements Wallet { getNodeInfo(): Promise { return this.pxe.getNodeInfo(); } - isGlobalStateSynchronized() { - return this.pxe.isGlobalStateSynchronized(); - } - getSyncStatus(): Promise { - return this.pxe.getSyncStatus(); - } addAuthWitness(authWitness: AuthWitness) { return this.pxe.addAuthWitness(authWitness); } diff --git a/yarn-project/bot/src/factory.ts b/yarn-project/bot/src/factory.ts index aac668476240..03098a3095cf 100644 --- a/yarn-project/bot/src/factory.ts +++ b/yarn-project/bot/src/factory.ts @@ -6,7 +6,6 @@ import { type DeployOptions, createLogger, createPXEClient, - retryUntil, } from '@aztec/aztec.js'; import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types'; import { Fr, deriveSigningKey } from '@aztec/circuits.js'; @@ -67,16 +66,6 @@ export class BotFactory { if (isInit) { this.log.info(`Account at ${account.getAddress().toString()} already initialized`); const wallet = await account.register(); - const blockNumber = await this.pxe.getBlockNumber(); - await retryUntil( - async () => { - const status = await this.pxe.getSyncStatus(); - return blockNumber <= status.blocks; - }, - 'pxe synch', - 3600, - 1, - ); return wallet; } else { this.log.info(`Initializing account at ${account.getAddress().toString()}`); diff --git a/yarn-project/circuit-types/src/interfaces/index.ts b/yarn-project/circuit-types/src/interfaces/index.ts index 3f05c960e1ba..2b880ad7550c 100644 --- a/yarn-project/circuit-types/src/interfaces/index.ts +++ b/yarn-project/circuit-types/src/interfaces/index.ts @@ -18,7 +18,6 @@ export * from './proving-job.js'; export * from './pxe.js'; export * from './server_circuit_prover.js'; export * from './service.js'; -export * from './sync-status.js'; export * from './world_state.js'; export * from './prover-broker.js'; export * from './p2p.js'; diff --git a/yarn-project/circuit-types/src/interfaces/pxe.test.ts b/yarn-project/circuit-types/src/interfaces/pxe.test.ts index 8530f731bd12..9bf3ca99f591 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -43,7 +43,6 @@ import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../t import { TxEffect } from '../tx_effect.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; import { type EventMetadataDefinition, type PXE, type PXEInfo, PXESchema } from './pxe.js'; -import { type SyncStatus } from './sync-status.js'; jest.setTimeout(12_000); @@ -258,16 +257,6 @@ describe('PXESchema', () => { expect(result).toEqual(await handler.getPXEInfo()); }); - it('isGlobalStateSynchronized', async () => { - const result = await context.client.isGlobalStateSynchronized(); - expect(result).toBe(true); - }); - - it('getSyncStatus', async () => { - const result = await context.client.getSyncStatus(); - expect(result).toEqual(await handler.getSyncStatus()); - }); - it('getContractInstance', async () => { const result = await context.client.getContractInstance(address); expect(result).toEqual(instance); @@ -502,14 +491,6 @@ class MockPXE implements PXE { pxeVersion: '1.0', }); } - isGlobalStateSynchronized(): Promise { - return Promise.resolve(true); - } - getSyncStatus(): Promise { - return Promise.resolve({ - blocks: 1, - }); - } getContractInstance(address: AztecAddress): Promise { expect(address).toEqual(this.address); return Promise.resolve(this.instance); diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 363511bad80c..62c99eb84baf 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -43,7 +43,6 @@ import { SiblingPath } from '../sibling_path/sibling_path.js'; import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../tx/index.js'; import { TxEffect } from '../tx_effect.js'; import { TxExecutionRequest } from '../tx_execution_request.js'; -import { type SyncStatus, SyncStatusSchema } from './sync-status.js'; // docs:start:pxe-interface /** @@ -351,22 +350,6 @@ export interface PXE { */ getPXEInfo(): Promise; - /** - * Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.). - * @returns True if there are no outstanding blocks to be synched. - * @remarks This indicates that blocks and transactions are synched even if notes are not. Compares local block number with the block number from aztec node. - * @deprecated Use `getSyncStatus` instead. - */ - isGlobalStateSynchronized(): Promise; - - /** - * Returns the latest block that has been synchronized globally and for each account. The global block number - * indicates whether global state has been updated up to that block, whereas each address indicates up to which - * block the private state has been synced for that account. - * @returns The latest block synchronized for blocks, and the latest block synched for notes for each public key being tracked. - */ - getSyncStatus(): Promise; - /** * Returns a Contract Instance given its address, which includes the contract class identifier, * initialization hash, deployment salt, and public keys hash. @@ -540,8 +523,6 @@ export const PXESchema: ApiSchemaFor = { getProvenBlockNumber: z.function().returns(z.number()), getNodeInfo: z.function().returns(NodeInfoSchema), getPXEInfo: z.function().returns(PXEInfoSchema), - isGlobalStateSynchronized: z.function().returns(z.boolean()), - getSyncStatus: z.function().returns(SyncStatusSchema), getContractInstance: z .function() .args(schemas.AztecAddress) diff --git a/yarn-project/circuit-types/src/interfaces/sync-status.ts b/yarn-project/circuit-types/src/interfaces/sync-status.ts deleted file mode 100644 index b85a13620d6b..000000000000 --- a/yarn-project/circuit-types/src/interfaces/sync-status.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { type ZodFor } from '@aztec/foundation/schemas'; - -import { z } from 'zod'; - -/** Provides up to which block has been synced by different components. */ -export type SyncStatus = { - /** Up to which block has been synched for blocks and txs. */ - blocks: number; -}; - -export const SyncStatusSchema = z.object({ - blocks: z.number(), -}) satisfies ZodFor; diff --git a/yarn-project/cli/src/cmds/pxe/get_block.ts b/yarn-project/cli/src/cmds/pxe/get_block.ts index d1584950ff19..f2951a9c8f6a 100644 --- a/yarn-project/cli/src/cmds/pxe/get_block.ts +++ b/yarn-project/cli/src/cmds/pxe/get_block.ts @@ -3,29 +3,8 @@ import { type LogFn, type Logger } from '@aztec/foundation/log'; import { inspectBlock } from '../../utils/inspect.js'; -export async function getBlock( - rpcUrl: string, - maybeBlockNumber: number | undefined, - follow: boolean, - debugLogger: Logger, - log: LogFn, -) { +export async function getBlock(rpcUrl: string, maybeBlockNumber: number | undefined, debugLogger: Logger, log: LogFn) { const client = await createCompatibleClient(rpcUrl, debugLogger); const blockNumber = maybeBlockNumber ?? (await client.getBlockNumber()); await inspectBlock(client, blockNumber, log, { showTxs: true }); - - if (follow) { - let lastBlock = blockNumber; - setInterval(async () => { - const newBlock = await client.getBlockNumber(); - if (newBlock > lastBlock) { - const { blocks } = await client.getSyncStatus(); - if (blocks >= newBlock) { - log(''); - await inspectBlock(client, newBlock, log, { showTxs: true }); - lastBlock = newBlock; - } - } - }, 1000); - } } diff --git a/yarn-project/cli/src/cmds/pxe/index.ts b/yarn-project/cli/src/cmds/pxe/index.ts index e6e1f8627259..dc8a7a4bb6a2 100644 --- a/yarn-project/cli/src/cmds/pxe/index.ts +++ b/yarn-project/cli/src/cmds/pxe/index.ts @@ -54,11 +54,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger .command('get-block') .description('Gets info for a given block or latest.') .argument('[blockNumber]', 'Block height', parseOptionalInteger) - .option('-f, --follow', 'Keep polling for new blocks') .addOption(pxeOption) .action(async (blockNumber, options) => { const { getBlock } = await import('./get_block.js'); - await getBlock(options.rpcUrl, blockNumber, options.follow, debugLogger, log); + await getBlock(options.rpcUrl, blockNumber, debugLogger, log); }); program diff --git a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts index adc29c28d637..d0b9c33de3e5 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts @@ -9,7 +9,7 @@ import { type BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking import { type SequencerClient } from '@aztec/sequencer-client'; import { type EndToEndContext } from '../fixtures/utils.js'; -import { benchmarkSetup, getFolderSize, makeDataDirectory, sendTxs, waitNewPXESynced } from './utils.js'; +import { benchmarkSetup, createNewPXE, getFolderSize, makeDataDirectory, sendTxs } from './utils.js'; const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE; const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS; @@ -69,7 +69,7 @@ describe('benchmarks/process_history', () => { // Create a new pxe and measure how much time it takes it to sync with failed and successful decryption // Skip the first two blocks used for setup (create account contract and deploy benchmarking contract) context.logger.info(`Starting new pxe`); - const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount); + const pxe = await createNewPXE(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount); // Register the owner account and wait until it's synced so we measure how much time it took context.logger.info(`Registering owner account on new pxe`); diff --git a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts index 21612ccbe85f..de9ecfd5797b 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts @@ -5,7 +5,7 @@ import { type BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking import { type SequencerClient } from '@aztec/sequencer-client'; import { type EndToEndContext } from '../fixtures/utils.js'; -import { benchmarkSetup, sendTxs, waitNewPXESynced } from './utils.js'; +import { benchmarkSetup, createNewPXE, sendTxs } from './utils.js'; describe('benchmarks/publish_rollup', () => { let context: EndToEndContext; @@ -41,7 +41,7 @@ describe('benchmarks/publish_rollup', () => { // Spin up a new pxe and sync it, we'll use it to test sync times of new accounts for the last block context.logger.info(`Starting new pxe`); - const pxe = await waitNewPXESynced(node, contract, blockNumber! - 1); + const pxe = await createNewPXE(node, contract, blockNumber! - 1); // Register the owner account and wait until it's synced so we measure how much time it took context.logger.info(`Registering owner account on new pxe`); diff --git a/yarn-project/end-to-end/src/benchmarks/utils.ts b/yarn-project/end-to-end/src/benchmarks/utils.ts index 5dbebfa26ce4..05c90892ae7c 100644 --- a/yarn-project/end-to-end/src/benchmarks/utils.ts +++ b/yarn-project/end-to-end/src/benchmarks/utils.ts @@ -1,5 +1,5 @@ import { type AztecNodeConfig, type AztecNodeService } from '@aztec/aztec-node'; -import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, retryUntil, sleep } from '@aztec/aztec.js'; +import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, sleep } from '@aztec/aztec.js'; import { times } from '@aztec/foundation/collection'; import { randomInt } from '@aztec/foundation/crypto'; import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking'; @@ -90,13 +90,13 @@ export async function sendTxs( } /** - * Creates a new PXE and awaits until it's synced with the node. + * Creates a new PXE * @param node - Node to connect the pxe to. * @param contract - Benchmark contract to add to the pxe. * @param startingBlock - First l2 block to process. * @returns The new PXE. */ -export async function waitNewPXESynced( +export async function createNewPXE( node: AztecNode, contract: BenchmarkingContract, startingBlock: number = INITIAL_L2_BLOCK_NUM, @@ -111,6 +111,5 @@ export async function waitNewPXESynced( } as PXEServiceConfig; const pxe = await createPXEService(node, pxeConfig); await pxe.registerContract(contract); - await retryUntil(() => pxe.isGlobalStateSynchronized(), 'pxe-global-sync'); return pxe; } diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 271d96b4b6ac..76a9fb47a39a 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -8,7 +8,6 @@ import { type Logger, type PXE, type Wallet, - retryUntil, sleep, } from '@aztec/aztec.js'; import { ChildContract, TestContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -103,21 +102,12 @@ describe('e2e_2_pxes', () => { return contract.instance; }; - const awaitServerSynchronized = async (server: PXE) => { - const isServerSynchronized = async () => { - return await server.isGlobalStateSynchronized(); - }; - await retryUntil(isServerSynchronized, 'server sync', 10); - }; - const getChildStoredValue = (child: { address: AztecAddress }, pxe: PXE) => pxe.getPublicStorageAt(child.address, new Fr(1)); it('user calls a public function on a contract deployed by a different user using a different PXE', async () => { const childCompleteAddress = await deployChildContractViaServerA(); - await awaitServerSynchronized(pxeA); - // Add Child to PXE B await pxeB.registerContract({ artifact: ChildContract.artifact, @@ -129,8 +119,6 @@ describe('e2e_2_pxes', () => { const childContractWithWalletB = await ChildContract.at(childCompleteAddress.address, walletB); await childContractWithWalletB.methods.pub_inc_value(newValueToSet).send().wait({ interval: 0.1 }); - await awaitServerSynchronized(pxeA); - const storedValueOnB = await getChildStoredValue(childCompleteAddress, pxeB); expect(storedValueOnB).toEqual(newValueToSet); diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 38ff8cce2e11..942e558d83e6 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -483,14 +483,6 @@ describe('e2e_block_building', () => { // PXE should have cleared out the 30-note from tx2, but reapplied the 20-note from tx1 expect(await contract.methods.summed_values(ownerAddress).simulate()).toEqual(21n); - // PXE should be synced to the block number on the new chain - await retryUntil( - async () => (await pxe.getSyncStatus()).blocks === newTx1Receipt.blockNumber, - 'wait for pxe block header sync', - 15, - 1, - ); - // And we should be able to send a new tx on the new chain logger.info('Sending new tx on reorgd chain'); const tx3 = await contract.methods.create_note(ownerAddress, ownerAddress, 10).send().wait(); diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 5ba7ce5aa0ea..d2c4c6d5cf3d 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -5,7 +5,7 @@ import { createLogger } from '@aztec/foundation/log'; import { getPXEServiceConfig } from '../config/index.js'; import { startPXEHttpServer } from '../pxe_http/index.js'; -import { createPXEService } from '../utils/index.js'; +import { createPXEService } from '../pxe_service/create_pxe_service.js'; const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env; diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index 866d2df92c78..5439afa717b9 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -46,7 +46,6 @@ export class KVPxeDatabase implements PxeDatabase { #nullifiedNotesByTxHash: AztecAsyncMultiMap; #nullifiedNotesByAddressPoint: AztecAsyncMultiMap; #nullifiedNotesByNullifier: AztecAsyncMap; - #syncedBlockPerPublicKey: AztecAsyncMap; #contractArtifacts: AztecAsyncMap; #contractInstances: AztecAsyncMap; #db: AztecAsyncKVStore; @@ -79,7 +78,6 @@ export class KVPxeDatabase implements PxeDatabase { this.#contractInstances = db.openMap('contracts_instances'); this.#synchronizedBlock = db.openSingleton('header'); - this.#syncedBlockPerPublicKey = db.openMap('synced_block_per_public_key'); this.#notes = db.openMap('notes'); this.#nullifiedNotes = db.openMap('nullified_notes'); @@ -564,14 +562,6 @@ export class KVPxeDatabase implements PxeDatabase { return true; } - getSynchedBlockNumberForAccount(account: AztecAddress): Promise { - return this.#syncedBlockPerPublicKey.getAsync(account.toString()); - } - - setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise { - return this.#syncedBlockPerPublicKey.set(account.toString(), blockNumber); - } - async estimateSize(): Promise { const incomingNotesSize = (await this.getIncomingNotes({})).reduce((sum, note) => sum + note.getSize(), 0); diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 0b24e77b99a2..4f2fd1557f29 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -160,19 +160,6 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD */ getCompleteAddresses(): Promise; - /** - * Updates up to which block number we have processed notes for a given public key. - * @param account - The account to set the synched block number for. - * @param blockNumber - The block number to set. - */ - setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise; - - /** - * Get the synched block number for a given public key. - * @param account - The account to get the synched block number for. - */ - getSynchedBlockNumberForAccount(account: AztecAddress): Promise; - /** * Returns the estimated size in bytes of this db. * @returns The estimated size in bytes of this db. diff --git a/yarn-project/pxe/src/index.ts b/yarn-project/pxe/src/index.ts index ae998668621e..d6e46f5ad840 100644 --- a/yarn-project/pxe/src/index.ts +++ b/yarn-project/pxe/src/index.ts @@ -10,6 +10,5 @@ export * from '@aztec/foundation/eth-address'; export * from '@aztec/foundation/aztec-address'; export * from '@aztec/key-store'; export * from './database/index.js'; -export * from './utils/index.js'; export { ContractDataOracle } from './contract_data_oracle/index.js'; export { PrivateFunctionsTree } from './contract_data_oracle/private_functions_tree.js'; diff --git a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts index bd168463788e..a8209e515041 100644 --- a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts @@ -47,9 +47,9 @@ export async function createPXEService( const tips = new L2TipsStore(store, 'pxe'); const prover = proofCreator ?? (await createProver(config, logSuffix)); - const server = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); - await server.start(); - return server; + const pxe = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); + await pxe.init(); + return pxe; } function createProver(config: PXEServiceConfig, logSuffix?: string) { diff --git a/yarn-project/pxe/src/pxe_service/index.ts b/yarn-project/pxe/src/pxe_service/index.ts index 66f9aae2adda..c9018d7ba8c8 100644 --- a/yarn-project/pxe/src/pxe_service/index.ts +++ b/yarn-project/pxe/src/pxe_service/index.ts @@ -1,3 +1,4 @@ export * from './pxe_service.js'; +export * from './create_pxe_service.js'; export { enrichPublicSimulationError } from './error_enriching.js'; export { pxeTestSuite } from './test/pxe_test_suite.js'; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 9f80b18ae396..3eccde42ec58 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -105,7 +105,7 @@ export class PXEService implements PXE { this.log = createLogger(logSuffix ? `pxe:service:${logSuffix}` : `pxe:service`); this.synchronizer = new Synchronizer(node, db, tipsStore, config, logSuffix); this.contractDataOracle = new ContractDataOracle(db); - this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); + this.simulator = getAcirSimulator(this.synchronizer, db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; this.jobQueue.start(); @@ -116,8 +116,7 @@ export class PXEService implements PXE { * * @returns A promise that resolves when the server has started successfully. */ - public async start() { - await this.synchronizer.start(); + public async init() { await this.#registerProtocolContracts(); const info = await this.getNodeInfo(); this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`); @@ -133,8 +132,6 @@ export class PXEService implements PXE { public async stop() { await this.jobQueue.cancel(); this.log.info('Cancelled Job Queue'); - await this.synchronizer.stop(); - this.log.info('Stopped Synchronizer'); } isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { @@ -513,6 +510,7 @@ export class PXEService implements PXE { ): Promise { return await this.jobQueue .put(async () => { + await this.synchronizer.trigger(); const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); let publicInputs: PrivateKernelTailCircuitPublicInputs; @@ -704,7 +702,7 @@ export class PXEService implements PXE { const { address, contractClass, instance, artifact } = getCanonicalProtocolContract(name); await this.db.addContractArtifact(contractClass.id, artifact); await this.db.addContractInstance(instance); - this.log.info(`Added protocol contract ${name} at ${address.toString()}`); + this.log.verbose(`Added protocol contract ${name} at ${address.toString()}`); } } @@ -821,11 +819,9 @@ export class PXEService implements PXE { } /** - * Simulate a transaction, generate a kernel proof, and create a private transaction object. - * The function takes in a transaction request, simulates it, and then generates a kernel proof - * using the simulation result. Finally, it creates a private - * transaction object with the generated proof and public inputs. If a new contract address is provided, - * the function will also include the new contract's public functions in the transaction object. + * Generate a kernel proof, and create a private kernel output. + * The function takes in a transaction execution request, and the result of private simulation + * and then generates a kernel proof. * * @param txExecutionRequest - The transaction request to be simulated and proved. * @param proofCreator - The proof creator to use for proving the execution. @@ -848,14 +844,6 @@ export class PXEService implements PXE { return await kernelProver.prove(txExecutionRequest.toTxRequest(), privateExecutionResult); } - public async isGlobalStateSynchronized() { - return await this.synchronizer.isGlobalStateSynchronized(); - } - - public getSyncStatus() { - return Promise.resolve(this.synchronizer.getSyncStatus()); - } - public async isContractClassPubliclyRegistered(id: Fr): Promise { return !!(await this.node.getContractClass(id)); } diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index c5fc6219e010..686c5b9f9a1a 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -115,8 +115,5 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => expect(typeof nodeInfo.l1ChainId).toEqual('number'); expect(nodeInfo.l1ContractAddresses.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/); }); - - // Note: Not testing `isGlobalStateSynchronized`, `isAccountStateSynchronized` and `getSyncStatus` as these methods - // only call synchronizer. }); }; diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index 8f41547a15e4..fe0f3458a07c 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -5,17 +5,20 @@ import { AcirSimulator } from '@aztec/simulator/client'; import { ContractDataOracle } from '../contract_data_oracle/index.js'; import { type PxeDatabase } from '../database/pxe_database.js'; import { SimulatorOracle } from '../simulator_oracle/index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * Helper method to create an instance of the acir simulator. */ export function getAcirSimulator( + synchronizer: Synchronizer, db: PxeDatabase, aztecNode: AztecNode, keyStore: KeyStore, contractDataOracle?: ContractDataOracle, ) { const simulatorOracle = new SimulatorOracle( + synchronizer, contractDataOracle ?? new ContractDataOracle(db), db, keyStore, diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 27b70628c2ba..7d04dca8e131 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -13,7 +13,7 @@ import { getNonNullifiedL1ToL2MessageWitness, } from '@aztec/circuit-types'; import { - type AztecAddress, + AztecAddress, type BlockHeader, type CompleteAddress, type ContractInstance, @@ -38,12 +38,14 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { produceNoteDaos } from '../note_decryption_utils/produce_note_daos.js'; import { getAcirSimulator } from '../simulator/index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * A data oracle that provides information needed for simulating a transaction. */ export class SimulatorOracle implements DBOracle { constructor( + private synchronizer: Synchronizer, private contractDataOracle: ContractDataOracle, private db: PxeDatabase, private keyStore: KeyStore, @@ -231,7 +233,7 @@ export class SimulatorOracle implements DBOracle { * @returns A Promise that resolves to a BlockHeader object. */ getBlockHeader(): Promise { - return Promise.resolve(this.db.getBlockHeader()); + return this.db.getBlockHeader(); } /** @@ -570,7 +572,8 @@ export class SimulatorOracle implements DBOracle { // I don't like this at all, but we need a simulator to run `computeNoteHashAndOptionallyANullifier`. This generates // a chicken-and-egg problem due to this oracle requiring a simulator, which in turn requires this oracle. Furthermore, since jest doesn't allow // mocking ESM exports, we have to pollute the method even more by providing a simulator parameter so tests can inject a fake one. - simulator ?? getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.contractDataOracle), + simulator ?? + getAcirSimulator(this.synchronizer, this.db, this.aztecNode, this.keyStore, this.contractDataOracle), this.db, incomingNotePayload ? recipient.toAddressPoint() : undefined, payload!, @@ -635,4 +638,18 @@ export class SimulatorOracle implements DBOracle { ); }); } + + /** + * Synchronizes the notes for a contract address, retrieving the logs from the node, + * decrypting them and storing them in the database. + * @param contractAddress - The contract address to synchronize notes for. + * @param scopes - The scopes allowed to synchronize. + */ + public async syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]) { + await this.synchronizer.trigger(); + const taggedLogsByRecipient = await this.syncTaggedLogs(contractAddress, await this.getBlockNumber(), scopes); + for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { + await this.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); + } + } } diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index 363da40fdf65..e28571138bd3 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -34,6 +34,7 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; import { ContractDataOracle } from '../index.js'; +import { type Synchronizer } from '../synchronizer/synchronizer.js'; import { SimulatorOracle } from './index.js'; const TXS_PER_BLOCK = 4; @@ -112,6 +113,7 @@ function computeSiloedTagForIndex( describe('Simulator oracle', () => { let aztecNode: MockProxy; let database: PxeDatabase; + let synchronizer: Synchronizer; let contractDataOracle: ContractDataOracle; let simulatorOracle: SimulatorOracle; let keyStore: KeyStore; @@ -122,11 +124,12 @@ describe('Simulator oracle', () => { beforeEach(async () => { const db = openTmpStore(); aztecNode = mock(); + synchronizer = mock(); database = await KVPxeDatabase.create(db); contractDataOracle = new ContractDataOracle(database); jest.spyOn(contractDataOracle, 'getDebugContractName').mockImplementation(() => Promise.resolve('TestContract')); keyStore = new KeyStore(db); - simulatorOracle = new SimulatorOracle(contractDataOracle, database, keyStore, aztecNode); + simulatorOracle = new SimulatorOracle(synchronizer, contractDataOracle, database, keyStore, aztecNode); // Set up contract address contractAddress = AztecAddress.random(); // Set up recipient account diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fe1c607e7daa..a89c90a2b712 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -15,8 +15,7 @@ import { type PxeDatabase } from '../database/index.js'; * The Synchronizer class manages the synchronization of note processors and interacts with the Aztec node * to obtain encrypted logs, blocks, and other necessary information for the accounts. * It provides methods to start or stop the synchronization process, add new accounts, retrieve account - * details, and fetch transactions by hash. The Synchronizer ensures that it maintains the note processors - * in sync with the blockchain while handling retries and errors gracefully. + * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { private running = false; @@ -65,18 +64,8 @@ export class Synchronizer implements L2BlockStreamEventHandler { } } - /** - * Starts the synchronization process by fetching encrypted logs and blocks from a specified position. - * Continuously processes the fetched data for all note processors until stopped. If there is no data - * available, it retries after a specified interval. - * - * @param limit - The maximum number of encrypted, unencrypted logs and blocks to fetch in each iteration. - * @param retryInterval - The time interval (in ms) to wait before retrying if no data is available. - */ - public async start() { - if (this.running) { - return; - } + /** Triggers a single run. */ + public async trigger() { this.running = true; let currentHeader; @@ -90,54 +79,11 @@ export class Synchronizer implements L2BlockStreamEventHandler { // REFACTOR: We should know the header of the genesis block without having to request it from the node. await this.db.setHeader(await this.node.getBlockHeader(0)); } - - await this.trigger(); - this.log.info('Initial sync complete'); - this.blockStream.start(); - this.log.debug('Started loop'); - } - - /** - * Stops the synchronizer gracefully, interrupting any ongoing sleep and waiting for the current - * iteration to complete before setting the running state to false. Once stopped, the synchronizer - * will no longer process blocks or encrypted logs and must be restarted using the start method. - * - * @returns A promise that resolves when the synchronizer has successfully stopped. - */ - public async stop() { - this.running = false; - await this.blockStream.stop(); - this.log.info('Stopped'); - } - - /** Triggers a single run. */ - public async trigger() { await this.blockStream.sync(); + this.running = false; } - private async getSynchedBlockNumber() { + public async getSynchedBlockNumber() { return (await this.db.getBlockNumber()) ?? this.initialSyncBlockNumber; } - - /** - * Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.). - * @returns True if there are no outstanding blocks to be synched. - * @remarks This indicates that blocks and transactions are synched even if notes are not. - * @remarks Compares local block number with the block number from aztec node. - */ - public async isGlobalStateSynchronized() { - const latest = await this.node.getBlockNumber(); - return latest <= (await this.getSynchedBlockNumber()); - } - - /** - * Returns the latest block that has been synchronized by the synchronizer and each account. - * @returns The latest block synchronized for blocks, and the latest block synched for notes for each public key being tracked. - */ - public async getSyncStatus() { - const lastBlockNumber = await this.getSynchedBlockNumber(); - return { - blocks: lastBlockNumber, - }; - } } diff --git a/yarn-project/pxe/src/utils/index.ts b/yarn-project/pxe/src/utils/index.ts deleted file mode 100644 index f971258aca0f..000000000000 --- a/yarn-project/pxe/src/utils/index.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { BBNativePrivateKernelProver } from '@aztec/bb-prover'; -import { type AztecNode, type PrivateKernelProver } from '@aztec/circuit-types'; -import { randomBytes } from '@aztec/foundation/crypto'; -import { createLogger } from '@aztec/foundation/log'; -import { KeyStore } from '@aztec/key-store'; -import { createStore } from '@aztec/kv-store/lmdb'; -import { L2TipsStore } from '@aztec/kv-store/stores'; - -import { type PXEServiceConfig } from '../config/index.js'; -import { KVPxeDatabase } from '../database/kv_pxe_database.js'; -import { TestPrivateKernelProver } from '../kernel_prover/test/test_circuit_prover.js'; -import { PXEService } from '../pxe_service/pxe_service.js'; - -/** - * Create and start an PXEService instance with the given AztecNode. - * If no keyStore or database is provided, it will use KeyStore and MemoryDB as default values. - * Returns a Promise that resolves to the started PXEService instance. - * - * @param aztecNode - The AztecNode instance to be used by the server. - * @param config - The PXE Service Config to use - * @param options - (Optional) Optional information for creating an PXEService. - * @param proofCreator - An optional proof creator to use in place of any other configuration - * @returns A Promise that resolves to the started PXEService instance. - */ -export async function createPXEService( - aztecNode: AztecNode, - config: PXEServiceConfig, - useLogSuffix: string | boolean | undefined = undefined, - proofCreator?: PrivateKernelProver, -) { - const logSuffix = - typeof useLogSuffix === 'boolean' ? (useLogSuffix ? randomBytes(3).toString('hex') : undefined) : useLogSuffix; - - const l1Contracts = await aztecNode.getL1ContractAddresses(); - const configWithContracts = { - ...config, - l1Contracts, - } as PXEServiceConfig; - - const keyStore = new KeyStore( - await createStore('pxe_key_store', configWithContracts, createLogger('pxe:keystore:lmdb')), - ); - - const store = await createStore('pxe_data', configWithContracts, createLogger('pxe:data:lmdb')); - - const db = await KVPxeDatabase.create(store); - const tips = new L2TipsStore(store, 'pxe'); - - const prover = proofCreator ?? (await createProver(config, logSuffix)); - const server = new PXEService(keyStore, aztecNode, db, tips, prover, config, logSuffix); - await server.start(); - return server; -} - -function createProver(config: PXEServiceConfig, logSuffix?: string) { - if (!config.proverEnabled) { - return new TestPrivateKernelProver(); - } - - // (@PhilWindle) Temporary validation until WASM is implemented - if (!config.bbBinaryPath || !config.bbWorkingDirectory) { - throw new Error(`Prover must be configured with binary path and working directory`); - } - const bbConfig = config as Required> & PXEServiceConfig; - const log = createLogger('pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')); - return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, log); -} diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 6702810c86a3..34a2b1317ed5 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -242,4 +242,12 @@ export interface DBOracle extends CommitmentsDB { * @param recipient - The recipient of the logs. */ processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise; + + /** + * Synchronizes the notes for a contract address, retrieving the logs from the node, + * decrypting them and storing them in the database. + * @param contractAddress - The contract address to synchronize notes for. + * @param scopes - The scopes allowed to synchronize. + */ + syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]): Promise; } diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index e138a3eef4f0..2e14b9b12f99 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -14,7 +14,7 @@ import { type KeyValidationRequest, } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/hash'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; @@ -310,13 +310,6 @@ export class ViewDataOracle extends TypedOracle { } public override async syncNotes() { - const taggedLogsByRecipient = await this.db.syncTaggedLogs( - this.contractAddress, - await this.db.getBlockNumber(), - this.scopes, - ); - for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { - await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); - } + return await this.db.syncNotes(this.contractAddress, this.scopes); } } From a120e995bf63629b8be48578f1a30a781d99dab4 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 12:57:54 +0000 Subject: [PATCH 25/57] improvements and comments --- spartan/aztec-network/templates/pxe.yaml | 2 +- yarn-project/end-to-end/src/e2e_2_pxes.test.ts | 1 - yarn-project/pxe/src/synchronizer/synchronizer.ts | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index d61df752190a..982fcdca872e 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -101,7 +101,7 @@ spec: - | curl -s -X POST -H 'content-type: application/json' \ -d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \ - 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"result":true' + 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1' initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }} timeoutSeconds: {{ .Values.pxe.readinessProbe.timeoutSeconds }} diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 76a9fb47a39a..eaa70fa10ff0 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -56,7 +56,6 @@ describe('e2e_2_pxes', () => { await teardownA(); }); - // TODO #10296 it('transfers funds from user A to B via PXE A followed by transfer from B to A via PXE B', async () => { const initialBalance = 987n; const transferAmount1 = 654n; diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index a89c90a2b712..b3bb416de321 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -12,9 +12,9 @@ import { type PXEConfig } from '../config/index.js'; import { type PxeDatabase } from '../database/index.js'; /** - * The Synchronizer class manages the synchronization of note processors and interacts with the Aztec node - * to obtain encrypted logs, blocks, and other necessary information for the accounts. - * It provides methods to start or stop the synchronization process, add new accounts, retrieve account + * The Synchronizer class manages the synchronization with the aztec node, allowing PXE to retrieve the + * latest block header and handle reorgs. + * It provides methods to trigger a sync and get the block number we are syncec to * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { From 5a2a6f7ee8815410d138c9d2e7e6de36873015cf Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 14:24:04 +0000 Subject: [PATCH 26/57] don't sync on note sync --- yarn-project/aztec.js/src/contract/sent_tx.ts | 6 ------ .../pxe/src/pxe_service/pxe_service.ts | 3 ++- yarn-project/pxe/src/simulator/index.ts | 2 -- yarn-project/pxe/src/simulator_oracle/index.ts | 18 +----------------- .../simulator_oracle/simulator_oracle.test.ts | 4 +--- yarn-project/simulator/src/client/db_oracle.ts | 8 -------- .../simulator/src/client/view_data_oracle.ts | 11 +++++++++-- 7 files changed, 13 insertions(+), 39 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index fb2d0e875496..99c4eec86500 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -14,11 +14,6 @@ export type WaitOpts = { interval?: number; /** Whether to wait for the tx to be proven. */ proven?: boolean; - /** - * Whether to wait for the node to notify that the block in which this tx was mined is available to fetch notes from. - * If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true. - **/ - waitForNotesAvailable?: boolean; /** Whether to include information useful for debugging/testing in the receipt. */ debug?: boolean; /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */ @@ -31,7 +26,6 @@ export const DefaultWaitOpts: WaitOpts = { provenTimeout: 600, interval: 1, debug: false, - waitForNotesAvailable: true, }; /** diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3eccde42ec58..fe90e47908ca 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -105,7 +105,7 @@ export class PXEService implements PXE { this.log = createLogger(logSuffix ? `pxe:service:${logSuffix}` : `pxe:service`); this.synchronizer = new Synchronizer(node, db, tipsStore, config, logSuffix); this.contractDataOracle = new ContractDataOracle(db); - this.simulator = getAcirSimulator(this.synchronizer, db, node, keyStore, this.contractDataOracle); + this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; this.jobQueue.start(); @@ -587,6 +587,7 @@ export class PXEService implements PXE { // all simulations must be serialized w.r.t. the synchronizer return await this.jobQueue .put(async () => { + await this.synchronizer.trigger(); // TODO - Should check if `from` has the permission to call the view function. const functionCall = await this.#getFunctionCall(functionName, args, to); const executionResult = await this.#simulateUnconstrained(functionCall, scopes); diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index fe0f3458a07c..cdb3ddf55ffb 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -11,14 +11,12 @@ import { type Synchronizer } from '../synchronizer/synchronizer.js'; * Helper method to create an instance of the acir simulator. */ export function getAcirSimulator( - synchronizer: Synchronizer, db: PxeDatabase, aztecNode: AztecNode, keyStore: KeyStore, contractDataOracle?: ContractDataOracle, ) { const simulatorOracle = new SimulatorOracle( - synchronizer, contractDataOracle ?? new ContractDataOracle(db), db, keyStore, diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 7d04dca8e131..bfb4db005d56 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -45,7 +45,6 @@ import { type Synchronizer } from '../synchronizer/synchronizer.js'; */ export class SimulatorOracle implements DBOracle { constructor( - private synchronizer: Synchronizer, private contractDataOracle: ContractDataOracle, private db: PxeDatabase, private keyStore: KeyStore, @@ -572,8 +571,7 @@ export class SimulatorOracle implements DBOracle { // I don't like this at all, but we need a simulator to run `computeNoteHashAndOptionallyANullifier`. This generates // a chicken-and-egg problem due to this oracle requiring a simulator, which in turn requires this oracle. Furthermore, since jest doesn't allow // mocking ESM exports, we have to pollute the method even more by providing a simulator parameter so tests can inject a fake one. - simulator ?? - getAcirSimulator(this.synchronizer, this.db, this.aztecNode, this.keyStore, this.contractDataOracle), + simulator ?? getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.contractDataOracle), this.db, incomingNotePayload ? recipient.toAddressPoint() : undefined, payload!, @@ -638,18 +636,4 @@ export class SimulatorOracle implements DBOracle { ); }); } - - /** - * Synchronizes the notes for a contract address, retrieving the logs from the node, - * decrypting them and storing them in the database. - * @param contractAddress - The contract address to synchronize notes for. - * @param scopes - The scopes allowed to synchronize. - */ - public async syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]) { - await this.synchronizer.trigger(); - const taggedLogsByRecipient = await this.syncTaggedLogs(contractAddress, await this.getBlockNumber(), scopes); - for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { - await this.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); - } - } } diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index e28571138bd3..978b2598bdf5 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -113,7 +113,6 @@ function computeSiloedTagForIndex( describe('Simulator oracle', () => { let aztecNode: MockProxy; let database: PxeDatabase; - let synchronizer: Synchronizer; let contractDataOracle: ContractDataOracle; let simulatorOracle: SimulatorOracle; let keyStore: KeyStore; @@ -124,12 +123,11 @@ describe('Simulator oracle', () => { beforeEach(async () => { const db = openTmpStore(); aztecNode = mock(); - synchronizer = mock(); database = await KVPxeDatabase.create(db); contractDataOracle = new ContractDataOracle(database); jest.spyOn(contractDataOracle, 'getDebugContractName').mockImplementation(() => Promise.resolve('TestContract')); keyStore = new KeyStore(db); - simulatorOracle = new SimulatorOracle(synchronizer, contractDataOracle, database, keyStore, aztecNode); + simulatorOracle = new SimulatorOracle(contractDataOracle, database, keyStore, aztecNode); // Set up contract address contractAddress = AztecAddress.random(); // Set up recipient account diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index 34a2b1317ed5..6702810c86a3 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -242,12 +242,4 @@ export interface DBOracle extends CommitmentsDB { * @param recipient - The recipient of the logs. */ processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise; - - /** - * Synchronizes the notes for a contract address, retrieving the logs from the node, - * decrypting them and storing them in the database. - * @param contractAddress - The contract address to synchronize notes for. - * @param scopes - The scopes allowed to synchronize. - */ - syncNotes(contractAddress: AztecAddress, scopes?: AztecAddress[]): Promise; } diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 2e14b9b12f99..de71ba38b813 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -14,7 +14,7 @@ import { type KeyValidationRequest, } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/hash'; -import { type AztecAddress } from '@aztec/foundation/aztec-address'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; @@ -310,6 +310,13 @@ export class ViewDataOracle extends TypedOracle { } public override async syncNotes() { - return await this.db.syncNotes(this.contractAddress, this.scopes); + const taggedLogsByRecipient = await this.db.syncTaggedLogs( + this.contractAddress, + await this.aztecNode.getBlockNumber(), + this.scopes, + ); + for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) { + await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient)); + } } } From 0673191d9a47229cbdec933e837aeaed84afdf46 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 11 Dec 2024 15:31:16 +0000 Subject: [PATCH 27/57] remove auto verify in cbind ivc prove --- barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 817e772ade1b..d4045e636e6f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -298,7 +298,7 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack, } // TODO(https://github.com/AztecProtocol/barretenberg/issues/1101): remove use of auto_verify_mode TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE }; - auto ivc = std::make_shared(trace_settings, /*auto_verify_mode=*/true); + auto ivc = std::make_shared(trace_settings); const acir_format::ProgramMetadata metadata{ ivc }; From 13ff2a62048923253ef4c3b007a93406d6175bd7 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 15:50:29 +0000 Subject: [PATCH 28/57] fmt --- yarn-project/pxe/src/simulator/index.ts | 1 - yarn-project/pxe/src/simulator_oracle/index.ts | 3 +-- yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/yarn-project/pxe/src/simulator/index.ts b/yarn-project/pxe/src/simulator/index.ts index cdb3ddf55ffb..8f41547a15e4 100644 --- a/yarn-project/pxe/src/simulator/index.ts +++ b/yarn-project/pxe/src/simulator/index.ts @@ -5,7 +5,6 @@ import { AcirSimulator } from '@aztec/simulator/client'; import { ContractDataOracle } from '../contract_data_oracle/index.js'; import { type PxeDatabase } from '../database/pxe_database.js'; import { SimulatorOracle } from '../simulator_oracle/index.js'; -import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * Helper method to create an instance of the acir simulator. diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index bfb4db005d56..beef6c7d4688 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -13,7 +13,7 @@ import { getNonNullifiedL1ToL2MessageWitness, } from '@aztec/circuit-types'; import { - AztecAddress, + type AztecAddress, type BlockHeader, type CompleteAddress, type ContractInstance, @@ -38,7 +38,6 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { produceNoteDaos } from '../note_decryption_utils/produce_note_daos.js'; import { getAcirSimulator } from '../simulator/index.js'; -import { type Synchronizer } from '../synchronizer/synchronizer.js'; /** * A data oracle that provides information needed for simulating a transaction. diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index 978b2598bdf5..363da40fdf65 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -34,7 +34,6 @@ import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; import { ContractDataOracle } from '../index.js'; -import { type Synchronizer } from '../synchronizer/synchronizer.js'; import { SimulatorOracle } from './index.js'; const TXS_PER_BLOCK = 4; From 6388f0efe38de897ed4fbc1810817dd34970ca90 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 11 Dec 2024 16:41:32 +0000 Subject: [PATCH 29/57] comment hack to run yarn proj --- .../ivc-integration/src/wasm_client_ivc_integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index f6402e91cb34..379a27bdb995 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -86,7 +86,7 @@ describe('Client IVC Integration', () => { const tx = { number_of_calls: '0x2', }; - // Witness gen app and kernels + // Witness gen for app and kernels const creatorAppWitnessGenResult = await witnessGenCreatorAppMockCircuit({ commitments_to_create: ['0x1', '0x2'] }); const readerAppWitnessGenResult = await witnessGenReaderAppMockCircuit({ commitments_to_read: ['0x2', '0x0'] }); From d23a0a1096c5db2751ac42407a9a8ff7c1c052a2 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 16:45:13 +0000 Subject: [PATCH 30/57] consolidation --- boxes/boxes/vite/package.json | 2 +- boxes/boxes/vite/src/config.ts | 6 +++--- boxes/package.json | 2 +- yarn-project/package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/boxes/boxes/vite/package.json b/boxes/boxes/vite/package.json index 2e669c8fd034..6ec60e3adafc 100644 --- a/boxes/boxes/vite/package.json +++ b/boxes/boxes/vite/package.json @@ -46,4 +46,4 @@ "vite-plugin-node-polyfills": "^0.22.0", "vite-plugin-top-level-await": "^1.4.4" } -} \ No newline at end of file +} diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index caa3430f9baf..cb4166eea2cd 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -6,7 +6,7 @@ import { } from "@aztec/aztec.js"; import { BoxReactContractArtifact } from "../artifacts/BoxReact"; import { AccountManager } from "@aztec/aztec.js/account"; -import { SingleKeyAccountContract } from "@aztec/accounts/single_key"; +import { SchnorrAccountContract } from "@aztec/accounts/schnorr"; import { createAztecNodeClient } from "@aztec/aztec.js"; import { PXEService } from "@aztec/pxe/service"; import { PXEServiceConfig, getPXEServiceConfig } from "@aztec/pxe/config"; @@ -42,7 +42,7 @@ export class PrivateEnv { const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey( this.secretKey, ); - this.accountContract = new SingleKeyAccountContract(encryptionPrivateKey); + this.accountContract = new SchnorrAccountContract(encryptionPrivateKey); this.account = new AccountManager( this.pxe, this.secretKey, @@ -80,7 +80,7 @@ export class PrivateEnv { proofCreator, config, ); - await server.start(); + await server.init(); return server; } diff --git a/boxes/package.json b/boxes/package.json index a904d9b967b5..4fc1b7e47b76 100644 --- a/boxes/package.json +++ b/boxes/package.json @@ -43,4 +43,4 @@ "devDependencies": { "@playwright/test": "1.46.1" } -} \ No newline at end of file +} diff --git a/yarn-project/package.json b/yarn-project/package.json index 436b2ac0a494..7a3e3eef7b12 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -85,4 +85,4 @@ "@noir-lang/noir_js": "file:../noir/packages/noir_js", "jest-runner@^29.7.0": "patch:jest-runner@npm%3A29.7.0#./.yarn/patches/jest-runner-npm-29.7.0-3bc9f82b58.patch" } -} \ No newline at end of file +} From 10c592473b2c9e588c87265f81d504a009ea72b8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 11 Dec 2024 17:08:20 +0000 Subject: [PATCH 31/57] undo --- .../ivc-integration/src/wasm_client_ivc_integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts index 379a27bdb995..f6402e91cb34 100644 --- a/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/wasm_client_ivc_integration.test.ts @@ -86,7 +86,7 @@ describe('Client IVC Integration', () => { const tx = { number_of_calls: '0x2', }; - // Witness gen for app and kernels + // Witness gen app and kernels const creatorAppWitnessGenResult = await witnessGenCreatorAppMockCircuit({ commitments_to_create: ['0x1', '0x2'] }); const readerAppWitnessGenResult = await witnessGenReaderAppMockCircuit({ commitments_to_read: ['0x2', '0x0'] }); From a9ce0d86a701b9ff83c13835e013f59f50b7cf9d Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 17:18:23 +0000 Subject: [PATCH 32/57] updated to schnorr account contract --- boxes/boxes/vite/src/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index cb4166eea2cd..64a40e1fa530 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -48,6 +48,7 @@ export class PrivateEnv { this.secretKey, this.accountContract, ); + await this.account.deploy().wait(); } async createPXEService( From 7e5387dd1b8c0a0e0701785044c16f357a983e14 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 11 Dec 2024 12:34:46 -0500 Subject: [PATCH 33/57] Update package.json --- yarn-project/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/package.json b/yarn-project/package.json index 436b2ac0a494..7d31e95a5c88 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -10,7 +10,7 @@ "formatting:fix": "FORCE_COLOR=true yarn workspaces foreach -p -v run formatting:fix", "lint": "yarn eslint --cache --ignore-pattern l1-artifacts .", "format": "yarn prettier --cache -w .", - "test": "FORCE_COLOR=true yarn workspaces foreach --exclude @aztec/ivc-integration --exclude @aztec/aztec3-packages --exclude @aztec/end-to-end --exclude @aztec/prover-client -p -v run test && yarn workspaces foreach --include @aztec/end-to-end -p -v run test:unit", + "test": "FORCE_COLOR=true yarn workspaces foreach --exclude @aztec/aztec3-packages --exclude @aztec/end-to-end --exclude @aztec/prover-client -p -v run test && yarn workspaces foreach --include @aztec/end-to-end -p -v run test:unit", "build": "FORCE_COLOR=true yarn workspaces foreach --parallel --topological-dev --verbose --exclude @aztec/aztec3-packages --exclude @aztec/docs run build", "build:fast": "cd foundation && yarn build && cd ../l1-artifacts && yarn build && cd ../circuits.js && yarn build && cd .. && yarn generate && tsc -b", "build:dev": "./watch.sh", @@ -85,4 +85,4 @@ "@noir-lang/noir_js": "file:../noir/packages/noir_js", "jest-runner@^29.7.0": "patch:jest-runner@npm%3A29.7.0#./.yarn/patches/jest-runner-npm-29.7.0-3bc9f82b58.patch" } -} \ No newline at end of file +} From 2f9a2eeb23c98595ed8723052aea53e4b97e1235 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 17:39:59 +0000 Subject: [PATCH 34/57] fix --- yarn-project/pxe/src/bin/index.ts | 2 +- yarn-project/pxe/src/index.ts | 1 + yarn-project/pxe/src/pxe_service/index.ts | 1 - yarn-project/pxe/src/pxe_service/pxe_service.ts | 9 +++------ yarn-project/pxe/src/synchronizer/synchronizer.ts | 5 ++++- .../pxe/src/{pxe_service => utils}/create_pxe_service.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename yarn-project/pxe/src/{pxe_service => utils}/create_pxe_service.ts (97%) diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index d2c4c6d5cf3d..d8b42d5ff72a 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -5,7 +5,7 @@ import { createLogger } from '@aztec/foundation/log'; import { getPXEServiceConfig } from '../config/index.js'; import { startPXEHttpServer } from '../pxe_http/index.js'; -import { createPXEService } from '../pxe_service/create_pxe_service.js'; +import { createPXEService } from '../utils/create_pxe_service.js'; const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env; diff --git a/yarn-project/pxe/src/index.ts b/yarn-project/pxe/src/index.ts index d6e46f5ad840..9c36ad7384e6 100644 --- a/yarn-project/pxe/src/index.ts +++ b/yarn-project/pxe/src/index.ts @@ -1,6 +1,7 @@ export * from './pxe_service/index.js'; export * from './pxe_http/index.js'; export * from './config/index.js'; +export * from './utils/create_pxe_service.js'; export { Tx, TxHash } from '@aztec/circuit-types'; diff --git a/yarn-project/pxe/src/pxe_service/index.ts b/yarn-project/pxe/src/pxe_service/index.ts index c9018d7ba8c8..66f9aae2adda 100644 --- a/yarn-project/pxe/src/pxe_service/index.ts +++ b/yarn-project/pxe/src/pxe_service/index.ts @@ -1,4 +1,3 @@ export * from './pxe_service.js'; -export * from './create_pxe_service.js'; export { enrichPublicSimulationError } from './error_enriching.js'; export { pxeTestSuite } from './test/pxe_test_suite.js'; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index fe90e47908ca..429360ef19d3 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -821,16 +821,13 @@ export class PXEService implements PXE { /** * Generate a kernel proof, and create a private kernel output. - * The function takes in a transaction execution request, and the result of private simulation + * The function takes in a transaction execution request, and the result of private execution * and then generates a kernel proof. * * @param txExecutionRequest - The transaction request to be simulated and proved. * @param proofCreator - The proof creator to use for proving the execution. - * @param msgSender - (Optional) The message sender to use for the simulation. - * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all. - * @returns An object that contains: - * A private transaction object containing the proof, public inputs, and encrypted logs. - * The return values of the private execution + * @param privateExecutionResult - The result of the private execution + * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled. */ async #prove( txExecutionRequest: TxExecutionRequest, diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index b3bb416de321..1e0f05af6c25 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -64,7 +64,10 @@ export class Synchronizer implements L2BlockStreamEventHandler { } } - /** Triggers a single run. */ + /** + * Syncs PXE and the node by dowloading the metadata of the latest blocks, allowing simulations to use + * recent data (e.g. notes), and handling any reorgs that might have occurred. + */ public async trigger() { this.running = true; diff --git a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts b/yarn-project/pxe/src/utils/create_pxe_service.ts similarity index 97% rename from yarn-project/pxe/src/pxe_service/create_pxe_service.ts rename to yarn-project/pxe/src/utils/create_pxe_service.ts index a8209e515041..773c7fa08aac 100644 --- a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts +++ b/yarn-project/pxe/src/utils/create_pxe_service.ts @@ -9,7 +9,7 @@ import { L2TipsStore } from '@aztec/kv-store/stores'; import { type PXEServiceConfig } from '../config/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; import { TestPrivateKernelProver } from '../kernel_prover/test/test_circuit_prover.js'; -import { PXEService } from './pxe_service.js'; +import { PXEService } from '../pxe_service/pxe_service.js'; /** * Create and start an PXEService instance with the given AztecNode. From d4adc1721815a5b9a71e02a25d55ed411fa11331 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 20:14:07 +0000 Subject: [PATCH 35/57] ffs --- spartan/aztec-network/templates/pxe.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index 01bccc233daf..09bd358625b5 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -100,7 +100,7 @@ spec: - -c - | curl -s -X POST -H 'content-type: application/json' \ - -d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \ + -d '{"jsonrpc":"2.0","method":"pxe_getNodeInfo","params":[],"id":67}' \ 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1' initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }} From 278c6fe5efa7a08776b2f8fa5d2110ae97043f7c Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 11 Dec 2024 20:14:52 +0000 Subject: [PATCH 36/57] ffs --- spartan/aztec-network/templates/pxe.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spartan/aztec-network/templates/pxe.yaml b/spartan/aztec-network/templates/pxe.yaml index 01bccc233daf..09bd358625b5 100644 --- a/spartan/aztec-network/templates/pxe.yaml +++ b/spartan/aztec-network/templates/pxe.yaml @@ -100,7 +100,7 @@ spec: - -c - | curl -s -X POST -H 'content-type: application/json' \ - -d '{"jsonrpc":"2.0","method":"pxe_isGlobalStateSynchronized","params":[],"id":67}' \ + -d '{"jsonrpc":"2.0","method":"pxe_getNodeInfo","params":[],"id":67}' \ 127.0.0.1:{{ .Values.pxe.service.nodePort }} | grep -q '"protocolVersion":1' initialDelaySeconds: {{ .Values.pxe.readinessProbe.initialDelaySeconds }} periodSeconds: {{ .Values.pxe.readinessProbe.periodSeconds }} From 9268f847f71a27e5f37de0f38397aac4a19a1f1c Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 05:27:49 +0000 Subject: [PATCH 37/57] bb wasm cli --- yarn-project/pxe/src/utils/create_pxe_service.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/yarn-project/pxe/src/utils/create_pxe_service.ts b/yarn-project/pxe/src/utils/create_pxe_service.ts index 773c7fa08aac..18783887ffb7 100644 --- a/yarn-project/pxe/src/utils/create_pxe_service.ts +++ b/yarn-project/pxe/src/utils/create_pxe_service.ts @@ -1,4 +1,5 @@ import { BBNativePrivateKernelProver } from '@aztec/bb-prover'; +import { BBWasmPrivateKernelProver } from '@aztec/bb-prover/wasm'; import { type AztecNode, type PrivateKernelProver } from '@aztec/circuit-types'; import { randomBytes } from '@aztec/foundation/crypto'; import { createLogger } from '@aztec/foundation/log'; @@ -59,9 +60,11 @@ function createProver(config: PXEServiceConfig, logSuffix?: string) { // (@PhilWindle) Temporary validation until WASM is implemented if (!config.bbBinaryPath || !config.bbWorkingDirectory) { - throw new Error(`Prover must be configured with binary path and working directory`); + return new BBWasmPrivateKernelProver(16); + } else { + const bbConfig = config as Required> & + PXEServiceConfig; + const log = createLogger('pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')); + return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, log); } - const bbConfig = config as Required> & PXEServiceConfig; - const log = createLogger('pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')); - return BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, log); } From 21fe1be293e63cd2706942fda9376db270a141c9 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 06:53:51 +0000 Subject: [PATCH 38/57] more tests --- boxes/boxes/vite/src/config.ts | 4 ---- yarn-project/bb-prover/src/wasm/index.ts | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index 64a40e1fa530..5828815c4016 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -17,12 +17,8 @@ import { L2TipsStore } from "@aztec/kv-store/stores"; import { createStore } from "@aztec/kv-store/indexeddb"; import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; -import createDebug from "debug"; - const SECRET_KEY = Fr.random(); -createDebug.enable("*"); - export class PrivateEnv { pxe; accountContract; diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts index 369089d1f635..cb992043e407 100644 --- a/yarn-project/bb-prover/src/wasm/index.ts +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -134,14 +134,15 @@ export class BBWasmPrivateKernelProver implements PrivateKernelProver { async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise { const timer = new Timer(); - this.log.debug(`Generating ClientIVC proof...`); + this.log.info(`Generating ClientIVC proof...`); const backend = new AztecClientBackend( acirs.map(acir => ungzip(acir)), { threads: this.threads }, ); const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap)))); - this.log.debug(`Generated ClientIVC proof`, { + await backend.destroy(); + this.log.info(`Generated ClientIVC proof`, { eventName: 'client-ivc-proof-generation', duration: timer.ms(), proofSize: proof.length, From 725759e2a0f2fde802b7e48674b0322c152208ca Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 07:46:58 +0000 Subject: [PATCH 39/57] removed jobqueue, stop, etc --- aztec-up/bin/docker-compose.sandbox.yml | 1 - boxes/boxes/vite/src/config.ts | 25 ++- boxes/docker-compose.yml | 1 - .../sandbox_reference/sandbox-reference.md | 2 - yarn-project/aztec/docker-compose.yml | 1 - yarn-project/aztec/src/cli/cmds/start_pxe.ts | 3 - yarn-project/aztec/src/sandbox.ts | 1 - yarn-project/cli-wallet/src/bin/index.ts | 5 - .../scripts/docker-compose-no-sandbox.yml | 1 - .../scripts/docker-compose-wallet.yml | 1 - .../end-to-end/scripts/docker-compose.yml | 1 - .../benchmarks/bench_process_history.test.ts | 3 +- .../src/benchmarks/bench_prover.test.ts | 3 - .../benchmarks/bench_publish_rollup.test.ts | 3 +- .../src/fixtures/snapshot_manager.ts | 1 - yarn-project/end-to-end/src/fixtures/utils.ts | 7 +- yarn-project/foundation/src/config/env_var.ts | 1 - yarn-project/pxe/src/bin/index.ts | 1 - yarn-project/pxe/src/config/index.ts | 7 - .../pxe/src/pxe_service/pxe_service.ts | 206 ++++++++---------- .../src/pxe_service/test/pxe_service.test.ts | 2 - .../pxe/src/synchronizer/synchronizer.ts | 9 +- 22 files changed, 112 insertions(+), 173 deletions(-) diff --git a/aztec-up/bin/docker-compose.sandbox.yml b/aztec-up/bin/docker-compose.sandbox.yml index 186ba3dec698..999aa5676850 100644 --- a/aztec-up/bin/docker-compose.sandbox.yml +++ b/aztec-up/bin/docker-compose.sandbox.yml @@ -28,7 +28,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 PXE_PORT: ${PXE_PORT:-8080} PORT: ${AZTEC_NODE_PORT:-8080} diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index e17120a3fc55..bced26cc0942 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -24,7 +24,10 @@ export class PrivateEnv { accountContract; account: AccountManager; - constructor(private secretKey: Fr, private nodeURL: string) {} + constructor( + private secretKey: Fr, + private nodeURL: string, + ) {} async init() { const config = getPXEServiceConfig(); @@ -33,20 +36,20 @@ export class PrivateEnv { const proofCreator = new TestPrivateKernelProver(); this.pxe = await this.createPXEService(aztecNode, config, proofCreator); const encryptionPrivateKey = deriveMasterIncomingViewingSecretKey( - this.secretKey + this.secretKey, ); this.accountContract = new SingleKeyAccountContract(encryptionPrivateKey); this.account = new AccountManager( this.pxe, this.secretKey, - this.accountContract + this.accountContract, ); } async createPXEService( aztecNode: AztecNode, config: PXEServiceConfig, - proofCreator?: PrivateKernelProver + proofCreator?: PrivateKernelProver, ) { const l1Contracts = await aztecNode.getL1ContractAddresses(); const configWithContracts = { @@ -57,7 +60,7 @@ export class PrivateEnv { const store = await createStore( "pxe_data", configWithContracts, - createLogger("pxe:data:indexeddb") + createLogger("pxe:data:indexeddb"), ); const keyStore = new KeyStore(store); @@ -65,16 +68,16 @@ export class PrivateEnv { const db = await KVPxeDatabase.create(store); const tips = new L2TipsStore(store, "pxe"); - const server = new PXEService( + const pxe = new PXEService( keyStore, aztecNode, db, tips, proofCreator, - config + config, ); - await server.start(); - return server; + await pxe.init(); + return pxe; } async getWallet() { @@ -85,7 +88,7 @@ export class PrivateEnv { export const deployerEnv = new PrivateEnv( SECRET_KEY, - process.env.PXE_URL || "http://localhost:8080" + process.env.PXE_URL || "http://localhost:8080", ); const IGNORE_FUNCTIONS = [ @@ -94,5 +97,5 @@ const IGNORE_FUNCTIONS = [ "sync_notes", ]; export const filteredInterface = BoxReactContractArtifact.functions.filter( - (f) => !IGNORE_FUNCTIONS.includes(f.name) + (f) => !IGNORE_FUNCTIONS.includes(f.name), ); diff --git a/boxes/docker-compose.yml b/boxes/docker-compose.yml index b06cca7ebc8c..a19c72fbc17a 100644 --- a/boxes/docker-compose.yml +++ b/boxes/docker-compose.yml @@ -17,7 +17,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 depends_on: - ethereum diff --git a/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md b/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md index ce0f32341b58..d00ef025751b 100644 --- a/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md +++ b/docs/docs/reference/developer_references/sandbox_reference/sandbox-reference.md @@ -37,7 +37,6 @@ ARCHIVER_POLLING_INTERVAL_MS=50 P2P_BLOCK_CHECK_INTERVAL_MS=50 SEQ_TX_POLLING_INTERVAL_MS=50 WS_BLOCK_CHECK_INTERVAL_MS=50 -PXE_BLOCK_POLLING_INTERVAL_MS=50 ARCHIVER_VIEM_POLLING_INTERVAL_MS=500 ``` @@ -90,7 +89,6 @@ Variables like `TEST_ACCOUNTS` & `PXE_PORT` are valid here as described above. AZTEC_NODE_URL='http://localhost:8079' # The address of an Aztec Node URL that the PXE will connect to (default: http://localhost:8079) PXE_PORT=8080 # The port that the PXE will be listening to (default: 8080) TEST_ACCOUNTS='true' # Option to deploy 3 test account when sandbox starts. (default: true) -PXE_BLOCK_POLLING_INTERVAL_MS=50 # Interval to check for new L2 blocks. (default: 50) PXE_L2_STARTING_BLOCK=1 # L2 Block to start synching the PXE from (default: 1) ``` diff --git a/yarn-project/aztec/docker-compose.yml b/yarn-project/aztec/docker-compose.yml index 3fe35cd42f82..7d158f93f30e 100644 --- a/yarn-project/aztec/docker-compose.yml +++ b/yarn-project/aztec/docker-compose.yml @@ -29,7 +29,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec/log:rw diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index f1d8681982c5..55bea808d2d1 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -117,8 +117,5 @@ export async function addPXE( // Add PXE to services list services.pxe = [pxe, PXESchema]; - // Add PXE stop function to signal handlers - signalHandlers.push(pxe.stop); - return pxe; } diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index 0545db16714c..d720894da3a4 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -157,7 +157,6 @@ export async function createSandbox(config: Partial = {}) { } const stop = async () => { - await pxe.stop(); await node.stop(); await watcher?.stop(); }; diff --git a/yarn-project/cli-wallet/src/bin/index.ts b/yarn-project/cli-wallet/src/bin/index.ts index bcdbb4d50a1b..df08765c1005 100644 --- a/yarn-project/cli-wallet/src/bin/index.ts +++ b/yarn-project/cli-wallet/src/bin/index.ts @@ -94,11 +94,6 @@ async function main() { await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe')); } db.init(AztecLmdbStore.open(dataDir)); - }) - .hook('postAction', async () => { - if (pxeWrapper.getPXE()) { - await (pxeWrapper.getPXE() as PXEService).stop(); - } }); injectCommands(program, userLog, debugLogger, db, pxeWrapper); diff --git a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml index 2fbbabb4d6dd..b219e4d01de7 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-''} JOB_NAME: ${JOB_NAME:-''} diff --git a/yarn-project/end-to-end/scripts/docker-compose-wallet.yml b/yarn-project/end-to-end/scripts/docker-compose-wallet.yml index b1a421ed5752..d7e4541e7fb6 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-wallet.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-wallet.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-} HARDWARE_CONCURRENCY: ${HARDWARE_CONCURRENCY:-} diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 4a96de1088dc..eae41741bb50 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -18,7 +18,6 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 ENABLE_GAS: ${ENABLE_GAS:-} HARDWARE_CONCURRENCY: ${HARDWARE_CONCURRENCY:-} diff --git a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts index d0b9c33de3e5..167548937a75 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts @@ -81,8 +81,7 @@ describe('benchmarks/process_history', () => { context.logger.info(`Registering fresh account on new pxe`); await pxe.registerAccount(Fr.random(), Fr.random()); - // Stop the external node and pxe - await pxe.stop(); + // Stop the external node await node.stop(); lastBlock = chainLength; diff --git a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts index d77451f317f2..49a09404359c 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts @@ -177,9 +177,6 @@ describe('benchmarks/proving', () => { }); afterAll(async () => { - for (const pxe of provingPxes) { - await pxe.stop(); - } await ctx.teardown(); await acvmCleanup(); await bbCleanup(); diff --git a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts index de9ecfd5797b..97d7fb4b17b7 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts @@ -53,8 +53,7 @@ describe('benchmarks/publish_rollup', () => { context.logger.info(`Registering fresh account on new pxe`); await pxe.registerAccount(Fr.random(), Fr.random()); - // Stop the external node and pxe - await pxe.stop(); + // Stop the external node await node.stop(); }, 20 * 60_000, diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 7a0507a6e630..6743a7ef2c4e 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -247,7 +247,6 @@ async function teardown(context: SubsystemsContext | undefined) { getLogger().info('Tearing down subsystems'); await context.proverNode?.stop(); await context.aztecNode.stop(); - await context.pxe.stop(); await context.acvmConfig?.cleanup(); await context.anvil.stop(); await context.watcher.stop(); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 8c71ccb4d9ab..c343015cda2d 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -146,9 +146,7 @@ export async function setupPXEService( const pxeServiceConfig = { ...getPXEServiceConfig(), ...opts }; const pxe = await createPXEService(aztecNode, pxeServiceConfig, useLogSuffix, proofCreator); - const teardown = async () => { - await pxe.stop(); - }; + const teardown = async () => {}; return { pxe, @@ -445,9 +443,6 @@ export async function setup( if (aztecNode instanceof AztecNodeService) { await aztecNode?.stop(); } - if (pxe instanceof PXEService) { - await pxe?.stop(); - } if (acvmConfig?.cleanup) { // remove the temp directory created for the acvm diff --git a/yarn-project/foundation/src/config/env_var.ts b/yarn-project/foundation/src/config/env_var.ts index cb43781825f4..ea13f2f97118 100644 --- a/yarn-project/foundation/src/config/env_var.ts +++ b/yarn-project/foundation/src/config/env_var.ts @@ -126,7 +126,6 @@ export type EnvVar = | 'PROVER_REQUIRED_CONFIRMATIONS' | 'PROVER_TEST_DELAY_MS' | 'PROVER_CACHE_DIR' - | 'PXE_BLOCK_POLLING_INTERVAL_MS' | 'PXE_L2_STARTING_BLOCK' | 'PXE_PROVER_ENABLED' | 'QUOTE_PROVIDER_BASIS_POINT_FEE' diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index d8b42d5ff72a..60a3d2da4cc4 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -25,7 +25,6 @@ async function main() { const shutdown = async () => { logger.info('Shutting down...'); - await pxeService.stop(); process.exit(0); }; diff --git a/yarn-project/pxe/src/config/index.ts b/yarn-project/pxe/src/config/index.ts index 4841f7ce6fd5..7eeb270453fa 100644 --- a/yarn-project/pxe/src/config/index.ts +++ b/yarn-project/pxe/src/config/index.ts @@ -28,8 +28,6 @@ export interface KernelProverConfig { * Configuration settings for the PXE. */ export interface PXEConfig { - /** The interval to wait between polling for new blocks. */ - l2BlockPollingIntervalMS: number; /** L2 block to start scanning from for new accounts */ l2StartingBlock: number; } @@ -47,11 +45,6 @@ export type CliPXEOptions = { export const pxeConfigMappings: ConfigMappingsType = { ...dataConfigMappings, - l2BlockPollingIntervalMS: { - env: 'PXE_BLOCK_POLLING_INTERVAL_MS', - description: 'The interval to wait between polling for new blocks.', - ...numberConfigHelper(1_000), - }, l2StartingBlock: { env: 'PXE_L2_STARTING_BLOCK', ...numberConfigHelper(INITIAL_L2_BLOCK_NUM), diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index c04785cfd335..c69cc9453256 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -89,9 +89,6 @@ export class PXEService implements PXE { private simulator: AcirSimulator; private log: Logger; private packageVersion: string; - // serialize synchronizer and calls to proveTx. - // ensures that state is not changed while simulating - private jobQueue = new SerialQueue(); constructor( private keyStore: KeyStore, @@ -107,8 +104,6 @@ export class PXEService implements PXE { this.contractDataOracle = new ContractDataOracle(db); this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); this.packageVersion = getPackageInfo().version; - - this.jobQueue.start(); } /** @@ -122,18 +117,6 @@ export class PXEService implements PXE { this.log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`); } - /** - * Stops the PXE Service, halting processing of new transactions and shutting down the synchronizer. - * This function ensures that all ongoing tasks are completed before stopping the server. - * It is useful for gracefully shutting down the server during maintenance or restarts. - * - * @returns A Promise resolving once the server has been stopped successfully. - */ - public async stop() { - await this.jobQueue.cancel(); - this.log.info('Cancelled Job Queue'); - } - isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise { return this.node.isL1ToL2MessageSynced(l1ToL2Message); } @@ -481,22 +464,16 @@ export class PXEService implements PXE { return result.publicInputs; } - public proveTx( + public async proveTx( txRequest: TxExecutionRequest, privateExecutionResult: PrivateExecutionResult, ): Promise { - return this.jobQueue - .put(async () => { - const { publicInputs, clientIvcProof } = await this.#prove( - txRequest, - this.proofCreator, - privateExecutionResult, - ); - return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!); - }) - .catch(err => { - throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); - }); + try { + const { publicInputs, clientIvcProof } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult); + return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!); + } catch (err: any) { + throw this.contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult)); + } } // TODO(#7456) Prevent msgSender being defined here for the first call @@ -508,79 +485,77 @@ export class PXEService implements PXE { profile: boolean = false, scopes?: AztecAddress[], ): Promise { - return await this.jobQueue - .put(async () => { - const txInfo = { - origin: txRequest.origin, - functionSelector: txRequest.functionSelector, - simulatePublic, - msgSender, - chainId: txRequest.txContext.chainId, - version: txRequest.txContext.version, - authWitnesses: txRequest.authWitnesses.map(w => w.requestHash), - }; - this.log.verbose( - `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, - txInfo, - ); - await this.synchronizer.trigger(); - const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); - - let publicInputs: PrivateKernelTailCircuitPublicInputs; - let profileResult; - if (profile) { - ({ publicInputs, profileResult } = await this.#profileKernelProver( - txRequest, - this.proofCreator, - privateExecutionResult, - )); - } else { - publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult); - } + try { + const txInfo = { + origin: txRequest.origin, + functionSelector: txRequest.functionSelector, + simulatePublic, + msgSender, + chainId: txRequest.txContext.chainId, + version: txRequest.txContext.version, + authWitnesses: txRequest.authWitnesses.map(w => w.requestHash), + }; + this.log.verbose( + `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, + txInfo, + ); + await this.synchronizer.trigger(); + const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); - const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs); - const simulatedTx = privateSimulationResult.toSimulatedTx(); - let publicOutput: PublicSimulationOutput | undefined; - if (simulatePublic) { - publicOutput = await this.#simulatePublicCalls(simulatedTx); - } + let publicInputs: PrivateKernelTailCircuitPublicInputs; + let profileResult; + if (profile) { + ({ publicInputs, profileResult } = await this.#profileKernelProver( + txRequest, + this.proofCreator, + privateExecutionResult, + )); + } else { + publicInputs = await this.#simulateKernels(txRequest, privateExecutionResult); + } - if (!skipTxValidation) { - if (!(await this.node.isValidTx(simulatedTx, true))) { - throw new Error('The simulated transaction is unable to be added to state and is invalid.'); - } + const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs); + const simulatedTx = privateSimulationResult.toSimulatedTx(); + let publicOutput: PublicSimulationOutput | undefined; + if (simulatePublic) { + publicOutput = await this.#simulatePublicCalls(simulatedTx); + } + + if (!skipTxValidation) { + if (!(await this.node.isValidTx(simulatedTx, true))) { + throw new Error('The simulated transaction is unable to be added to state and is invalid.'); } + } - this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()}`, { - txHash: simulatedTx.tryGetTxHash(), - ...txInfo, - ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), - ...(publicOutput - ? { - gasUsed: publicOutput.gasUsed, - revertCode: publicOutput.txEffect.revertCode.getCode(), - revertReason: publicOutput.revertReason, - } - : {}), - }); - - return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput( - privateSimulationResult, - publicOutput, - profileResult, - ); - }) - .catch(err => { - throw this.contextualizeError( - err, - inspect(txRequest), - `simulatePublic=${simulatePublic}`, - `msgSender=${msgSender?.toString() ?? 'undefined'}`, - `skipTxValidation=${skipTxValidation}`, - `profile=${profile}`, - `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, - ); + this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()}`, { + txHash: simulatedTx.tryGetTxHash(), + ...txInfo, + ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), + ...(publicOutput + ? { + gasUsed: publicOutput.gasUsed, + revertCode: publicOutput.txEffect.revertCode.getCode(), + revertReason: publicOutput.revertReason, + } + : {}), }); + + return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput( + privateSimulationResult, + publicOutput, + profileResult, + ); + } catch (err: any) { + throw this.contextualizeError( + err, + inspect(txRequest), + `simulatePublic=${simulatePublic}`, + `msgSender=${msgSender?.toString() ?? 'undefined'}`, + `skipTxValidation=${skipTxValidation}`, + `profile=${profile}`, + `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, + ); + } } public async sendTx(tx: Tx): Promise { @@ -603,25 +578,22 @@ export class PXEService implements PXE { _from?: AztecAddress, scopes?: AztecAddress[], ): Promise { - // all simulations must be serialized w.r.t. the synchronizer - return await this.jobQueue - .put(async () => { - await this.synchronizer.trigger(); - // TODO - Should check if `from` has the permission to call the view function. - const functionCall = await this.#getFunctionCall(functionName, args, to); - const executionResult = await this.#simulateUnconstrained(functionCall, scopes); - - // TODO - Return typed result based on the function artifact. - return executionResult; - }) - .catch(err => { - const stringifiedArgs = args.map(arg => arg.toString()).join(', '); - throw this.contextualizeError( - err, - `simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`, - `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, - ); - }); + try { + await this.synchronizer.trigger(); + // TODO - Should check if `from` has the permission to call the view function. + const functionCall = await this.#getFunctionCall(functionName, args, to); + const executionResult = await this.#simulateUnconstrained(functionCall, scopes); + + // TODO - Return typed result based on the function artifact. + return executionResult; + } catch (err: any) { + const stringifiedArgs = args.map(arg => arg.toString()).join(', '); + throw this.contextualizeError( + err, + `simulateUnconstrained ${to}:${functionName}(${stringifiedArgs})`, + `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`, + ); + } } public getTxReceipt(txHash: TxHash): Promise { 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 678f6c4bb761..d0dc0103bbfe 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 @@ -22,7 +22,6 @@ async function createPXEService(): Promise { const db = await KVPxeDatabase.create(kvStore); const tips = new L2TipsStore(kvStore, 'pxe'); const config: PXEServiceConfig = { - l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM, dataDirectory: undefined, dataStoreMapSizeKB: 1024 * 1024, @@ -67,7 +66,6 @@ describe('PXEService', () => { tips = new L2TipsStore(kvStore, 'pxe'); db = await KVPxeDatabase.create(kvStore); config = { - l2BlockPollingIntervalMS: 100, l2StartingBlock: INITIAL_L2_BLOCK_NUM, proverEnabled: false, dataDirectory: undefined, diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 382dc477e221..fa2143797aaa 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -27,16 +27,15 @@ export class Synchronizer implements L2BlockStreamEventHandler { private node: AztecNode, private db: PxeDatabase, private l2TipsStore: L2TipsStore, - config: Partial> = {}, + config: Partial> = {}, logSuffix?: string, ) { this.log = createLogger(logSuffix ? `pxe:synchronizer:${logSuffix}` : 'pxe:synchronizer'); this.blockStream = this.createBlockStream(config); } - protected createBlockStream(config: Partial>) { + protected createBlockStream(config: Partial>) { return new L2BlockStream(this.node, this.l2TipsStore, this, createLogger('pxe:block_stream'), { - pollIntervalMS: config.l2BlockPollingIntervalMS, startingBlock: config.l2StartingBlock, }); } @@ -93,6 +92,10 @@ export class Synchronizer implements L2BlockStreamEventHandler { this.running = false; } + public async stop() { + await this.blockStream.stop(); + } + public async getSynchedBlockNumber() { return (await this.db.getBlockNumber()) ?? this.initialSyncBlockNumber; } From f50c8e98619aae4de8b87f79da5430ae81507dab Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:32:24 +0000 Subject: [PATCH 40/57] fmt --- yarn-project/end-to-end/src/fixtures/utils.ts | 2 +- yarn-project/pxe/src/bin/index.ts | 2 +- yarn-project/pxe/src/pxe_service/pxe_service.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index c343015cda2d..b8954d38cd15 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -42,7 +42,7 @@ import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts'; import { type ProverNode, type ProverNodeConfig, createProverNode } from '@aztec/prover-node'; -import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; +import { type PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { type SequencerClient, TestL1Publisher } from '@aztec/sequencer-client'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { createAndStartTelemetryClient, getConfigEnvVars as getTelemetryConfig } from '@aztec/telemetry-client/start'; diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 60a3d2da4cc4..66f451dae925 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -23,7 +23,7 @@ async function main() { const nodeRpcClient = createAztecNodeClient(AZTEC_NODE_URL); const pxeService = await createPXEService(nodeRpcClient, pxeConfig); - const shutdown = async () => { + const shutdown = () => { logger.info('Shutting down...'); process.exit(0); }; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index c69cc9453256..3e52c79fa2f7 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -56,7 +56,6 @@ import { } from '@aztec/foundation/abi'; import { Fr, type Point } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; -import { SerialQueue } from '@aztec/foundation/queue'; import { type KeyStore } from '@aztec/key-store'; import { type L2TipsStore } from '@aztec/kv-store/stores'; import { From 00fd955d0835386526819cb70c24348a7fe2220b Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:48:48 +0000 Subject: [PATCH 41/57] renaming --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- yarn-project/pxe/src/synchronizer/synchronizer.ts | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 3e52c79fa2f7..6a1d557d783c 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -578,7 +578,7 @@ export class PXEService implements PXE { scopes?: AztecAddress[], ): Promise { try { - await this.synchronizer.trigger(); + await this.synchronizer.sync(); // TODO - Should check if `from` has the permission to call the view function. const functionCall = await this.#getFunctionCall(functionName, args, to); const executionResult = await this.#simulateUnconstrained(functionCall, scopes); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index fa2143797aaa..80a152dcf3a9 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -18,7 +18,6 @@ import { type PxeDatabase } from '../database/index.js'; * details, and fetch transactions by hash. */ export class Synchronizer implements L2BlockStreamEventHandler { - private running = false; private initialSyncBlockNumber = INITIAL_L2_BLOCK_NUM - 1; private log: Logger; protected readonly blockStream: L2BlockStream; @@ -74,9 +73,7 @@ export class Synchronizer implements L2BlockStreamEventHandler { * Syncs PXE and the node by dowloading the metadata of the latest blocks, allowing simulations to use * recent data (e.g. notes), and handling any reorgs that might have occurred. */ - public async trigger() { - this.running = true; - + public async sync() { let currentHeader; try { @@ -88,12 +85,7 @@ export class Synchronizer implements L2BlockStreamEventHandler { // REFACTOR: We should know the header of the genesis block without having to request it from the node. await this.db.setHeader(await this.node.getBlockHeader(0)); } - await this.blockStream.sync(); - this.running = false; - } - - public async stop() { - await this.blockStream.stop(); + await this.blockStream.triggerOnce(); } public async getSynchedBlockNumber() { From bc56c9ca527bec9f2fa247d6f64e68b1ab8b0c22 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 08:54:52 +0000 Subject: [PATCH 42/57] fix --- yarn-project/pxe/src/pxe_service/pxe_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 6a1d557d783c..dba22e806712 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -498,7 +498,7 @@ export class PXEService implements PXE { `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo, ); - await this.synchronizer.trigger(); + await this.synchronizer.sync(); const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); let publicInputs: PrivateKernelTailCircuitPublicInputs; From ff200deda8ba2cb8480b4de3ede4466ba5e9d422 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 09:00:27 +0000 Subject: [PATCH 43/57] typo --- yarn-project/pxe/src/synchronizer/synchronizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 80a152dcf3a9..225787866df0 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -85,7 +85,7 @@ export class Synchronizer implements L2BlockStreamEventHandler { // REFACTOR: We should know the header of the genesis block without having to request it from the node. await this.db.setHeader(await this.node.getBlockHeader(0)); } - await this.blockStream.triggerOnce(); + await this.blockStream.sync(); } public async getSynchedBlockNumber() { From 77f8ddb2d1d464a84ffdcbb395c4aea0806a2666 Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 12 Dec 2024 10:28:15 +0000 Subject: [PATCH 44/57] fmt --- yarn-project/cli-wallet/src/bin/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/yarn-project/cli-wallet/src/bin/index.ts b/yarn-project/cli-wallet/src/bin/index.ts index df08765c1005..1147134a56ff 100644 --- a/yarn-project/cli-wallet/src/bin/index.ts +++ b/yarn-project/cli-wallet/src/bin/index.ts @@ -2,7 +2,6 @@ import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js'; import { LOCALHOST } from '@aztec/cli/cli-utils'; import { type LogFn, createConsoleLogger, createLogger } from '@aztec/foundation/log'; import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; -import { type PXEService } from '@aztec/pxe'; import { Argument, Command, Option } from 'commander'; import { readFileSync } from 'fs'; From 3746d385131a4e4eae530bcee5409e334712f468 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 13 Dec 2024 07:47:51 +0000 Subject: [PATCH 45/57] env attempt --- boxes/boxes/vite/.env | 2 ++ boxes/boxes/vite/src/config.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 boxes/boxes/vite/.env diff --git a/boxes/boxes/vite/.env b/boxes/boxes/vite/.env new file mode 100644 index 000000000000..94bf9f0295e5 --- /dev/null +++ b/boxes/boxes/vite/.env @@ -0,0 +1,2 @@ +VITE_AZTEC_NODE_URL=http://localhost:8080 +VITE_LOG_LEVEL=debug \ No newline at end of file diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index 60301e3b7ecb..afb4fb5e9057 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -17,6 +17,12 @@ import { L2TipsStore } from "@aztec/kv-store/stores"; import { createStore } from "@aztec/kv-store/indexeddb"; import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; +process.env = Object.keys(import.meta.env).reduce((acc, key) => { + console.log(key); + acc[key.replace("VITE_", "")] = import.meta.env[key]; + return acc; +}, {}); + const SECRET_KEY = Fr.random(); export class PrivateEnv { @@ -82,14 +88,13 @@ export class PrivateEnv { } async getWallet() { - // taking advantage that register is no-op if already registered - return await this.account.register(); + return await this.account.getWallet(); } } export const deployerEnv = new PrivateEnv( SECRET_KEY, - process.env.PXE_URL || "http://localhost:8080", + process.env.AZTEC_NODE_URL, ); const IGNORE_FUNCTIONS = [ From 5bcb42a18bfe7613a6dc9d21f245f5f1261d9bd7 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 13 Dec 2024 10:22:15 +0000 Subject: [PATCH 46/57] more logging --- barretenberg/ts/src/barretenberg/index.ts | 2 +- boxes/boxes/vite/.env | 3 +-- boxes/boxes/vite/src/config.ts | 3 +-- yarn-project/pxe/src/kernel_prover/kernel_prover.ts | 5 +++++ yarn-project/pxe/src/pxe_service/pxe_service.ts | 6 ++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 4c8097bb89bb..688759c18bb5 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -69,7 +69,7 @@ export class Barretenberg extends BarretenbergApi { async initSRSClientIVC(): Promise { // crsPath can be undefined const crs = await Crs.new(2 ** 20 + 1, this.options.crsPath); - const grumpkinCrs = await GrumpkinCrs.new(2 ** 14 + 1, this.options.crsPath); + const grumpkinCrs = await GrumpkinCrs.new(2 ** 15 + 1, this.options.crsPath); // Load CRS into wasm global CRS state. // TODO: Make RawBuffer be default behavior, and have a specific Vector type for when wanting length prefixed. diff --git a/boxes/boxes/vite/.env b/boxes/boxes/vite/.env index 94bf9f0295e5..6f73ed0c33bd 100644 --- a/boxes/boxes/vite/.env +++ b/boxes/boxes/vite/.env @@ -1,2 +1 @@ -VITE_AZTEC_NODE_URL=http://localhost:8080 -VITE_LOG_LEVEL=debug \ No newline at end of file +VITE_AZTEC_NODE_URL=http://localhost:8080 \ No newline at end of file diff --git a/boxes/boxes/vite/src/config.ts b/boxes/boxes/vite/src/config.ts index afb4fb5e9057..734f450c80a4 100644 --- a/boxes/boxes/vite/src/config.ts +++ b/boxes/boxes/vite/src/config.ts @@ -18,7 +18,6 @@ import { createStore } from "@aztec/kv-store/indexeddb"; import { BBWasmPrivateKernelProver } from "@aztec/bb-prover/wasm"; process.env = Object.keys(import.meta.env).reduce((acc, key) => { - console.log(key); acc[key.replace("VITE_", "")] = import.meta.env[key]; return acc; }, {}); @@ -88,7 +87,7 @@ export class PrivateEnv { } async getWallet() { - return await this.account.getWallet(); + return await this.account.register(); } } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index eb7b9b7a8411..64f147254dc3 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -31,6 +31,7 @@ import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto'; 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'; import { getProtocolContractSiblingPath, @@ -118,6 +119,8 @@ export class KernelProver { profile: boolean = false, dryRun: boolean = false, ): Promise> { + const timer = new Timer(); + const isPrivateOnlyTx = this.isPrivateOnly(executionResult); const executionStack = [executionResult]; @@ -282,6 +285,8 @@ export class KernelProver { tailOutput.profileResult = { gateCounts }; } + this.log.info(`Witness generation took ${timer.ms()}ms`); + // TODO(#7368) how do we 'bincode' encode these inputs? if (!dryRun) { const ivcProof = await this.proofCreator.createClientIvcProof(acirs, witnessStack); diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index f2b1f4199091..b7110ae1a99d 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -56,6 +56,7 @@ import { } from '@aztec/foundation/abi'; import { Fr, type Point } from '@aztec/foundation/fields'; import { type Logger, createLogger } from '@aztec/foundation/log'; +import { Timer } from '@aztec/foundation/timer'; import { type KeyStore } from '@aztec/key-store'; import { type L2TipsStore } from '@aztec/kv-store/stores'; import { @@ -494,10 +495,11 @@ export class PXEService implements PXE { version: txRequest.txContext.version, authWitnesses: txRequest.authWitnesses.map(w => w.requestHash), }; - this.log.verbose( + this.log.info( `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo, ); + const timer = new Timer(); await this.synchronizer.sync(); const privateExecutionResult = await this.#executePrivate(txRequest, msgSender, scopes); @@ -526,7 +528,7 @@ export class PXEService implements PXE { } } - this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()}`, { + this.log.info(`Simulation completed for ${simulatedTx.tryGetTxHash()} in ${timer.ms()}ms`, { txHash: simulatedTx.tryGetTxHash(), ...txInfo, ...(profileResult ? { gateCounts: profileResult.gateCounts } : {}), From a80370efc7cb50e3d34816bd63b71edc92c73399 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 13 Dec 2024 15:45:53 +0000 Subject: [PATCH 47/57] trim the fat --- boxes/boxes/vite/package.json | 2 +- boxes/package.json | 4 +- boxes/yarn.lock | 531 +++++++++++- yarn-project/bb-prover/src/wasm/index.ts | 6 +- .../noir-protocol-circuits-types/package.json | 1 + .../src/artifacts.ts | 102 --- .../src/artifacts/client.ts | 38 + .../src/artifacts/index.ts | 14 + .../src/artifacts/server.ts | 60 ++ .../src/client.ts | 24 + .../src/execution/client.ts | 404 +++++++++ .../src/execution/index.ts | 2 + .../src/execution/server.ts | 366 ++++++++ .../noir-protocol-circuits-types/src/index.ts | 808 +----------------- .../src/utils/decoded_inputs.ts | 14 + .../src/utils/foreign_call_handler.ts | 26 + .../noir-protocol-circuits-types/src/vks.ts | 2 +- yarn-project/pxe/src/kernel_oracle/index.ts | 2 +- ...ild_private_kernel_reset_private_inputs.ts | 2 +- .../pxe/src/kernel_prover/kernel_prover.ts | 2 +- .../kernel_prover/test/test_circuit_prover.ts | 10 +- .../simulator/src/providers/acvm_wasm.ts | 2 +- 22 files changed, 1495 insertions(+), 927 deletions(-) delete mode 100644 yarn-project/noir-protocol-circuits-types/src/artifacts.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/artifacts/client.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/artifacts/index.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/client.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/execution/client.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/execution/index.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/execution/server.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/utils/decoded_inputs.ts create mode 100644 yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts diff --git a/boxes/boxes/vite/package.json b/boxes/boxes/vite/package.json index 6ec60e3adafc..e071e5d473f3 100644 --- a/boxes/boxes/vite/package.json +++ b/boxes/boxes/vite/package.json @@ -41,7 +41,7 @@ "node-stdlib-browser": "^1.3.0", "typescript": "~5.6.2", "typescript-eslint": "^8.11.0", - "vite": "^5.4.10", + "vite": "^6.0.3", "vite-plugin-externalize-deps": "^0.8.0", "vite-plugin-node-polyfills": "^0.22.0", "vite-plugin-top-level-await": "^1.4.4" diff --git a/boxes/package.json b/boxes/package.json index 4fc1b7e47b76..7cd31f064caf 100644 --- a/boxes/package.json +++ b/boxes/package.json @@ -4,8 +4,8 @@ "version": "0.5.0", "type": "module", "scripts": { - "compile": "yarn workspaces foreach --exclude vite -A -v run compile", - "build": "yarn workspaces foreach --exclude vite -A -v run build", + "compile": "yarn workspaces foreach -A -v run compile", + "build": "yarn workspaces foreach -A -v run build", "install-browsers": "playwright install --with-deps", "publish": "yarn npm publish", "test": "vitest bin.test.js", diff --git a/boxes/yarn.lock b/boxes/yarn.lock index 03288c2e13a6..42e467831211 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -559,6 +559,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/aix-ppc64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/aix-ppc64@npm:0.24.0" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm64@npm:0.21.5" @@ -566,6 +573,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/android-arm64@npm:0.24.0" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm@npm:0.21.5" @@ -573,6 +587,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/android-arm@npm:0.24.0" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-x64@npm:0.21.5" @@ -580,6 +601,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/android-x64@npm:0.24.0" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-arm64@npm:0.21.5" @@ -587,6 +615,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/darwin-arm64@npm:0.24.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-x64@npm:0.21.5" @@ -594,6 +629,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/darwin-x64@npm:0.24.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-arm64@npm:0.21.5" @@ -601,6 +643,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/freebsd-arm64@npm:0.24.0" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-x64@npm:0.21.5" @@ -608,6 +657,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/freebsd-x64@npm:0.24.0" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm64@npm:0.21.5" @@ -615,6 +671,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-arm64@npm:0.24.0" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm@npm:0.21.5" @@ -622,6 +685,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-arm@npm:0.24.0" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ia32@npm:0.21.5" @@ -629,6 +699,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-ia32@npm:0.24.0" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-loong64@npm:0.21.5" @@ -636,6 +713,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-loong64@npm:0.24.0" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-mips64el@npm:0.21.5" @@ -643,6 +727,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-mips64el@npm:0.24.0" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ppc64@npm:0.21.5" @@ -650,6 +741,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-ppc64@npm:0.24.0" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-riscv64@npm:0.21.5" @@ -657,6 +755,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-riscv64@npm:0.24.0" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-s390x@npm:0.21.5" @@ -664,6 +769,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-s390x@npm:0.24.0" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-x64@npm:0.21.5" @@ -671,6 +783,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/linux-x64@npm:0.24.0" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/netbsd-x64@npm:0.21.5" @@ -678,6 +797,20 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/netbsd-x64@npm:0.24.0" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/openbsd-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/openbsd-arm64@npm:0.24.0" + conditions: os=openbsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/openbsd-x64@npm:0.21.5" @@ -685,6 +818,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/openbsd-x64@npm:0.24.0" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/sunos-x64@npm:0.21.5" @@ -692,6 +832,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/sunos-x64@npm:0.24.0" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-arm64@npm:0.21.5" @@ -699,6 +846,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/win32-arm64@npm:0.24.0" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-ia32@npm:0.21.5" @@ -706,6 +860,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/win32-ia32@npm:0.24.0" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-x64@npm:0.21.5" @@ -713,6 +874,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.24.0": + version: 0.24.0 + resolution: "@esbuild/win32-x64@npm:0.24.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.1 resolution: "@eslint-community/eslint-utils@npm:4.4.1" @@ -1512,6 +1680,20 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-json@npm:^6.1.0": + version: 6.1.0 + resolution: "@rollup/plugin-json@npm:6.1.0" + dependencies: + "@rollup/pluginutils": "npm:^5.1.0" + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: 9400c431b5e0cf3088ba2eb2d038809a2b0fb2a84ed004997da85582f48cd64958ed3168893c4f2c8109e38652400ed68282d0c92bf8ec07a3b2ef2e1ceab0b7 + languageName: node + linkType: hard + "@rollup/plugin-virtual@npm:^3.0.2": version: 3.0.2 resolution: "@rollup/plugin-virtual@npm:3.0.2" @@ -1524,7 +1706,7 @@ __metadata: languageName: node linkType: hard -"@rollup/pluginutils@npm:^5.0.1": +"@rollup/pluginutils@npm:^5.0.1, @rollup/pluginutils@npm:^5.1.0": version: 5.1.3 resolution: "@rollup/pluginutils@npm:5.1.3" dependencies: @@ -1547,6 +1729,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm-eabi@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-android-arm-eabi@npm:4.28.1" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@rollup/rollup-android-arm64@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-android-arm64@npm:4.27.3" @@ -1554,6 +1743,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-android-arm64@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-android-arm64@npm:4.28.1" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-arm64@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-darwin-arm64@npm:4.27.3" @@ -1561,6 +1757,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-arm64@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-darwin-arm64@npm:4.28.1" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-darwin-x64@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-darwin-x64@npm:4.27.3" @@ -1568,6 +1771,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-darwin-x64@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-darwin-x64@npm:4.28.1" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@rollup/rollup-freebsd-arm64@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-freebsd-arm64@npm:4.27.3" @@ -1575,6 +1785,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-freebsd-arm64@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-freebsd-arm64@npm:4.28.1" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-freebsd-x64@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-freebsd-x64@npm:4.27.3" @@ -1582,6 +1799,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-freebsd-x64@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-freebsd-x64@npm:4.28.1" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@rollup/rollup-linux-arm-gnueabihf@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.27.3" @@ -1589,6 +1813,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-gnueabihf@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-arm-gnueabihf@npm:4.28.1" + conditions: os=linux & cpu=arm & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm-musleabihf@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.27.3" @@ -1596,6 +1827,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm-musleabihf@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-arm-musleabihf@npm:4.28.1" + conditions: os=linux & cpu=arm & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-gnu@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.27.3" @@ -1603,6 +1841,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm64-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-arm64-gnu@npm:4.28.1" + conditions: os=linux & cpu=arm64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-arm64-musl@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-arm64-musl@npm:4.27.3" @@ -1610,6 +1855,20 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-arm64-musl@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-arm64-musl@npm:4.28.1" + conditions: os=linux & cpu=arm64 & libc=musl + languageName: node + linkType: hard + +"@rollup/rollup-linux-loongarch64-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-loongarch64-gnu@npm:4.28.1" + conditions: os=linux & cpu=loong64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-powerpc64le-gnu@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.27.3" @@ -1617,6 +1876,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-powerpc64le-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-powerpc64le-gnu@npm:4.28.1" + conditions: os=linux & cpu=ppc64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-riscv64-gnu@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.27.3" @@ -1624,6 +1890,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-riscv64-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-riscv64-gnu@npm:4.28.1" + conditions: os=linux & cpu=riscv64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-s390x-gnu@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.27.3" @@ -1631,6 +1904,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-s390x-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-s390x-gnu@npm:4.28.1" + conditions: os=linux & cpu=s390x & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-gnu@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-x64-gnu@npm:4.27.3" @@ -1638,6 +1918,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-x64-gnu@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-x64-gnu@npm:4.28.1" + conditions: os=linux & cpu=x64 & libc=glibc + languageName: node + linkType: hard + "@rollup/rollup-linux-x64-musl@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-linux-x64-musl@npm:4.27.3" @@ -1645,6 +1932,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-linux-x64-musl@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-linux-x64-musl@npm:4.28.1" + conditions: os=linux & cpu=x64 & libc=musl + languageName: node + linkType: hard + "@rollup/rollup-win32-arm64-msvc@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.27.3" @@ -1652,6 +1946,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-arm64-msvc@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-win32-arm64-msvc@npm:4.28.1" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@rollup/rollup-win32-ia32-msvc@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.27.3" @@ -1659,6 +1960,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-ia32-msvc@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-win32-ia32-msvc@npm:4.28.1" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@rollup/rollup-win32-x64-msvc@npm:4.27.3": version: 4.27.3 resolution: "@rollup/rollup-win32-x64-msvc@npm:4.27.3" @@ -1666,6 +1974,13 @@ __metadata: languageName: node linkType: hard +"@rollup/rollup-win32-x64-msvc@npm:4.28.1": + version: 4.28.1 + resolution: "@rollup/rollup-win32-x64-msvc@npm:4.28.1" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@rtsao/scc@npm:^1.1.0": version: 1.1.0 resolution: "@rtsao/scc@npm:1.1.0" @@ -5058,6 +5373,89 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:^0.24.0": + version: 0.24.0 + resolution: "esbuild@npm:0.24.0" + dependencies: + "@esbuild/aix-ppc64": "npm:0.24.0" + "@esbuild/android-arm": "npm:0.24.0" + "@esbuild/android-arm64": "npm:0.24.0" + "@esbuild/android-x64": "npm:0.24.0" + "@esbuild/darwin-arm64": "npm:0.24.0" + "@esbuild/darwin-x64": "npm:0.24.0" + "@esbuild/freebsd-arm64": "npm:0.24.0" + "@esbuild/freebsd-x64": "npm:0.24.0" + "@esbuild/linux-arm": "npm:0.24.0" + "@esbuild/linux-arm64": "npm:0.24.0" + "@esbuild/linux-ia32": "npm:0.24.0" + "@esbuild/linux-loong64": "npm:0.24.0" + "@esbuild/linux-mips64el": "npm:0.24.0" + "@esbuild/linux-ppc64": "npm:0.24.0" + "@esbuild/linux-riscv64": "npm:0.24.0" + "@esbuild/linux-s390x": "npm:0.24.0" + "@esbuild/linux-x64": "npm:0.24.0" + "@esbuild/netbsd-x64": "npm:0.24.0" + "@esbuild/openbsd-arm64": "npm:0.24.0" + "@esbuild/openbsd-x64": "npm:0.24.0" + "@esbuild/sunos-x64": "npm:0.24.0" + "@esbuild/win32-arm64": "npm:0.24.0" + "@esbuild/win32-ia32": "npm:0.24.0" + "@esbuild/win32-x64": "npm:0.24.0" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-arm64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 9f1aadd8d64f3bff422ae78387e66e51a5e09de6935a6f987b6e4e189ed00fdc2d1bc03d2e33633b094008529c8b6e06c7ad1a9782fb09fec223bf95998c0683 + languageName: node + linkType: hard + "escalade@npm:^3.1.1, escalade@npm:^3.2.0": version: 3.2.0 resolution: "escalade@npm:3.2.0" @@ -9227,7 +9625,7 @@ __metadata: languageName: node linkType: hard -"postcss@npm:^8.4.29, postcss@npm:^8.4.33, postcss@npm:^8.4.43": +"postcss@npm:^8.4.29, postcss@npm:^8.4.33, postcss@npm:^8.4.43, postcss@npm:^8.4.49": version: 8.4.49 resolution: "postcss@npm:8.4.49" dependencies: @@ -9899,6 +10297,78 @@ __metadata: languageName: node linkType: hard +"rollup@npm:^4.23.0": + version: 4.28.1 + resolution: "rollup@npm:4.28.1" + dependencies: + "@rollup/rollup-android-arm-eabi": "npm:4.28.1" + "@rollup/rollup-android-arm64": "npm:4.28.1" + "@rollup/rollup-darwin-arm64": "npm:4.28.1" + "@rollup/rollup-darwin-x64": "npm:4.28.1" + "@rollup/rollup-freebsd-arm64": "npm:4.28.1" + "@rollup/rollup-freebsd-x64": "npm:4.28.1" + "@rollup/rollup-linux-arm-gnueabihf": "npm:4.28.1" + "@rollup/rollup-linux-arm-musleabihf": "npm:4.28.1" + "@rollup/rollup-linux-arm64-gnu": "npm:4.28.1" + "@rollup/rollup-linux-arm64-musl": "npm:4.28.1" + "@rollup/rollup-linux-loongarch64-gnu": "npm:4.28.1" + "@rollup/rollup-linux-powerpc64le-gnu": "npm:4.28.1" + "@rollup/rollup-linux-riscv64-gnu": "npm:4.28.1" + "@rollup/rollup-linux-s390x-gnu": "npm:4.28.1" + "@rollup/rollup-linux-x64-gnu": "npm:4.28.1" + "@rollup/rollup-linux-x64-musl": "npm:4.28.1" + "@rollup/rollup-win32-arm64-msvc": "npm:4.28.1" + "@rollup/rollup-win32-ia32-msvc": "npm:4.28.1" + "@rollup/rollup-win32-x64-msvc": "npm:4.28.1" + "@types/estree": "npm:1.0.6" + fsevents: "npm:~2.3.2" + dependenciesMeta: + "@rollup/rollup-android-arm-eabi": + optional: true + "@rollup/rollup-android-arm64": + optional: true + "@rollup/rollup-darwin-arm64": + optional: true + "@rollup/rollup-darwin-x64": + optional: true + "@rollup/rollup-freebsd-arm64": + optional: true + "@rollup/rollup-freebsd-x64": + optional: true + "@rollup/rollup-linux-arm-gnueabihf": + optional: true + "@rollup/rollup-linux-arm-musleabihf": + optional: true + "@rollup/rollup-linux-arm64-gnu": + optional: true + "@rollup/rollup-linux-arm64-musl": + optional: true + "@rollup/rollup-linux-loongarch64-gnu": + optional: true + "@rollup/rollup-linux-powerpc64le-gnu": + optional: true + "@rollup/rollup-linux-riscv64-gnu": + optional: true + "@rollup/rollup-linux-s390x-gnu": + optional: true + "@rollup/rollup-linux-x64-gnu": + optional: true + "@rollup/rollup-linux-x64-musl": + optional: true + "@rollup/rollup-win32-arm64-msvc": + optional: true + "@rollup/rollup-win32-ia32-msvc": + optional: true + "@rollup/rollup-win32-x64-msvc": + optional: true + fsevents: + optional: true + bin: + rollup: dist/bin/rollup + checksum: 2d2d0433b7cb53153a04c7b406f342f31517608dc57510e49177941b9e68c30071674b83a0292ef1d87184e5f7c6d0f2945c8b3c74963074de10c75366fe2c14 + languageName: node + linkType: hard + "run-parallel@npm:^1.1.9": version: 1.2.0 resolution: "run-parallel@npm:1.2.0" @@ -11391,7 +11861,7 @@ __metadata: languageName: node linkType: hard -"vite@npm:^5.0.0, vite@npm:^5.4.10": +"vite@npm:^5.0.0": version: 5.4.11 resolution: "vite@npm:5.4.11" dependencies: @@ -11434,6 +11904,58 @@ __metadata: languageName: node linkType: hard +"vite@npm:^6.0.3": + version: 6.0.3 + resolution: "vite@npm:6.0.3" + dependencies: + esbuild: "npm:^0.24.0" + fsevents: "npm:~2.3.3" + postcss: "npm:^8.4.49" + rollup: "npm:^4.23.0" + peerDependencies: + "@types/node": ^18.0.0 || ^20.0.0 || >=22.0.0 + jiti: ">=1.21.0" + less: "*" + lightningcss: ^1.21.0 + sass: "*" + sass-embedded: "*" + stylus: "*" + sugarss: "*" + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + dependenciesMeta: + fsevents: + optional: true + peerDependenciesMeta: + "@types/node": + optional: true + jiti: + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + bin: + vite: bin/vite.js + checksum: 764ebed14770426a638575b23a51127c630ace873999ab896b0184484d8107e7255cdf64cfb36c65c1ef1d583e44b70a1d14c0f05b89612e834a5806e3964475 + languageName: node + linkType: hard + "vite@workspace:boxes/vite": version: 0.0.0-use.local resolution: "vite@workspace:boxes/vite" @@ -11448,6 +11970,7 @@ __metadata: "@eslint/js": "npm:^9.13.0" "@noir-lang/acvm_js": "link:../../../noir/packages/acvm_js" "@noir-lang/noirc_abi": "link:../../../noir/packages/noirc_abi" + "@rollup/plugin-json": "npm:^6.1.0" "@types/react": "npm:^18.3.12" "@types/react-dom": "npm:^18.3.1" "@vitejs/plugin-react-swc": "npm:^3.5.0" @@ -11463,7 +11986,7 @@ __metadata: react-toastify: "npm:^10.0.6" typescript: "npm:~5.6.2" typescript-eslint: "npm:^8.11.0" - vite: "npm:^5.4.10" + vite: "npm:^6.0.3" vite-plugin-externalize-deps: "npm:^0.8.0" vite-plugin-node-polyfills: "npm:^0.22.0" vite-plugin-top-level-await: "npm:^1.4.4" diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts index cb992043e407..0a61f1b50ff3 100644 --- a/yarn-project/bb-prover/src/wasm/index.ts +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -1,7 +1,6 @@ import { AztecClientBackend } from '@aztec/bb.js'; -import { AppCircuitSimulateOutput, PrivateKernelProver, PrivateKernelSimulateOutput } from '@aztec/circuit-types'; +import { PrivateKernelProver, PrivateKernelSimulateOutput } from '@aztec/circuit-types'; import { - CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, ClientIvcProof, PrivateKernelCircuitPublicInputs, PrivateKernelInitCircuitPrivateInputs, @@ -9,7 +8,6 @@ import { PrivateKernelResetCircuitPrivateInputs, PrivateKernelTailCircuitPrivateInputs, PrivateKernelTailCircuitPublicInputs, - VerificationKeyAsFields, } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; @@ -28,7 +26,7 @@ import { convertPrivateKernelTailOutputsFromWitnessMap, convertPrivateKernelTailToPublicInputsToWitnessMap, getPrivateKernelResetArtifactName, -} from '@aztec/noir-protocol-circuits-types'; +} from '@aztec/noir-protocol-circuits-types/client'; import { WASMSimulator } from '@aztec/simulator/client'; import { NoirCompiledCircuit } from '@aztec/types/noir'; diff --git a/yarn-project/noir-protocol-circuits-types/package.json b/yarn-project/noir-protocol-circuits-types/package.json index 461cd3ede1a3..aa936af00f96 100644 --- a/yarn-project/noir-protocol-circuits-types/package.json +++ b/yarn-project/noir-protocol-circuits-types/package.json @@ -4,6 +4,7 @@ "type": "module", "exports": { ".": "./dest/index.js", + "./client": "./dest/client.js", "./types": "./dest/types/index.js" }, "inherits": [ diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts.ts deleted file mode 100644 index d0339d17050b..000000000000 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { type NoirCompiledCircuit } from '@aztec/types/noir'; - -import EmptyNestedJson from '../artifacts/empty_nested.json' assert { type: 'json' }; -import EmptyNestedSimulatedJson from '../artifacts/empty_nested_simulated.json' assert { type: 'json' }; -import BaseParityJson from '../artifacts/parity_base.json' assert { type: 'json' }; -import RootParityJson from '../artifacts/parity_root.json' assert { type: 'json' }; -import PrivateKernelEmptyJson from '../artifacts/private_kernel_empty.json' assert { type: 'json' }; -import PrivateKernelEmptySimulatedJson from '../artifacts/private_kernel_empty_simulated.json' assert { type: 'json' }; -import PrivateKernelInitJson from '../artifacts/private_kernel_init.json' assert { type: 'json' }; -import PrivateKernelInitSimulatedJson from '../artifacts/private_kernel_init_simulated.json' assert { type: 'json' }; -import PrivateKernelInnerJson from '../artifacts/private_kernel_inner.json' assert { type: 'json' }; -import PrivateKernelInnerSimulatedJson from '../artifacts/private_kernel_inner_simulated.json' assert { type: 'json' }; -import PrivateKernelTailJson from '../artifacts/private_kernel_tail.json' assert { type: 'json' }; -import PrivateKernelTailSimulatedJson from '../artifacts/private_kernel_tail_simulated.json' assert { type: 'json' }; -import PrivateKernelTailToPublicJson from '../artifacts/private_kernel_tail_to_public.json' assert { type: 'json' }; -import PrivateKernelTailToPublicSimulatedJson from '../artifacts/private_kernel_tail_to_public_simulated.json' assert { type: 'json' }; -import PrivateBaseRollupJson from '../artifacts/rollup_base_private.json' assert { type: 'json' }; -import PrivateBaseRollupSimulatedJson from '../artifacts/rollup_base_private_simulated.json' assert { type: 'json' }; -import PublicBaseRollupJson from '../artifacts/rollup_base_public.json' assert { type: 'json' }; -import PublicBaseRollupSimulatedJson from '../artifacts/rollup_base_public_simulated.json' assert { type: 'json' }; -import BlockMergeRollupJson from '../artifacts/rollup_block_merge.json' assert { type: 'json' }; -import BlockRootRollupJson from '../artifacts/rollup_block_root.json' assert { type: 'json' }; -import EmptyBlockRootRollupJson from '../artifacts/rollup_block_root_empty.json' assert { type: 'json' }; -import MergeRollupJson from '../artifacts/rollup_merge.json' assert { type: 'json' }; -import RootRollupJson from '../artifacts/rollup_root.json' assert { type: 'json' }; -import { - PrivateKernelResetArtifacts, - PrivateKernelResetSimulatedArtifacts, - type PrivateResetArtifact, -} from './private_kernel_reset_data.js'; - -// These are all circuits that should generate proofs with the `recursive` flag. -export type ServerProtocolArtifact = - | 'EmptyNestedArtifact' - | 'PrivateKernelEmptyArtifact' - | 'BaseParityArtifact' - | 'RootParityArtifact' - | 'PrivateBaseRollupArtifact' - | 'PublicBaseRollupArtifact' - | 'MergeRollupArtifact' - | 'BlockRootRollupArtifact' - | 'EmptyBlockRootRollupArtifact' - | 'BlockMergeRollupArtifact' - | 'RootRollupArtifact'; - -export type ClientProtocolArtifact = - | 'PrivateKernelInitArtifact' - | 'PrivateKernelInnerArtifact' - | 'PrivateKernelTailArtifact' - | 'PrivateKernelTailToPublicArtifact' - | PrivateResetArtifact; - -export type ProtocolArtifact = ServerProtocolArtifact | ClientProtocolArtifact; - -export const ServerCircuitArtifacts: Record = { - EmptyNestedArtifact: EmptyNestedJson as NoirCompiledCircuit, - PrivateKernelEmptyArtifact: PrivateKernelEmptyJson as NoirCompiledCircuit, - BaseParityArtifact: BaseParityJson as NoirCompiledCircuit, - RootParityArtifact: RootParityJson as NoirCompiledCircuit, - PrivateBaseRollupArtifact: PrivateBaseRollupJson as NoirCompiledCircuit, - PublicBaseRollupArtifact: PublicBaseRollupJson as NoirCompiledCircuit, - MergeRollupArtifact: MergeRollupJson as NoirCompiledCircuit, - BlockRootRollupArtifact: BlockRootRollupJson as NoirCompiledCircuit, - EmptyBlockRootRollupArtifact: EmptyBlockRootRollupJson as NoirCompiledCircuit, - BlockMergeRollupArtifact: BlockMergeRollupJson as NoirCompiledCircuit, - RootRollupArtifact: RootRollupJson as NoirCompiledCircuit, -}; - -export const SimulatedServerCircuitArtifacts: Record = { - EmptyNestedArtifact: EmptyNestedSimulatedJson as NoirCompiledCircuit, - PrivateKernelEmptyArtifact: PrivateKernelEmptySimulatedJson as NoirCompiledCircuit, - BaseParityArtifact: BaseParityJson as NoirCompiledCircuit, - RootParityArtifact: RootParityJson as NoirCompiledCircuit, - PrivateBaseRollupArtifact: PrivateBaseRollupSimulatedJson as NoirCompiledCircuit, - PublicBaseRollupArtifact: PublicBaseRollupSimulatedJson as NoirCompiledCircuit, - MergeRollupArtifact: MergeRollupJson as NoirCompiledCircuit, - BlockRootRollupArtifact: BlockRootRollupJson as NoirCompiledCircuit, - EmptyBlockRootRollupArtifact: EmptyBlockRootRollupJson as NoirCompiledCircuit, - BlockMergeRollupArtifact: BlockMergeRollupJson as NoirCompiledCircuit, - RootRollupArtifact: RootRollupJson as NoirCompiledCircuit, -}; - -export const ClientCircuitArtifacts: Record = { - PrivateKernelInitArtifact: PrivateKernelInitJson as NoirCompiledCircuit, - PrivateKernelInnerArtifact: PrivateKernelInnerJson as NoirCompiledCircuit, - PrivateKernelTailArtifact: PrivateKernelTailJson as NoirCompiledCircuit, - PrivateKernelTailToPublicArtifact: PrivateKernelTailToPublicJson as NoirCompiledCircuit, - ...PrivateKernelResetArtifacts, -}; - -export const SimulatedClientCircuitArtifacts: Record = { - PrivateKernelInitArtifact: PrivateKernelInitSimulatedJson as NoirCompiledCircuit, - PrivateKernelInnerArtifact: PrivateKernelInnerSimulatedJson as NoirCompiledCircuit, - PrivateKernelTailArtifact: PrivateKernelTailSimulatedJson as NoirCompiledCircuit, - PrivateKernelTailToPublicArtifact: PrivateKernelTailToPublicSimulatedJson as NoirCompiledCircuit, - ...PrivateKernelResetSimulatedArtifacts, -}; - -export const ProtocolCircuitArtifacts: Record = { - ...ClientCircuitArtifacts, - ...ServerCircuitArtifacts, -}; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/client.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/client.ts new file mode 100644 index 000000000000..256ac0405dd8 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/client.ts @@ -0,0 +1,38 @@ +import { type NoirCompiledCircuit } from '@aztec/types/noir'; + +import PrivateKernelInitJson from '../../artifacts/private_kernel_init.json' assert { type: 'json' }; +import PrivateKernelInitSimulatedJson from '../../artifacts/private_kernel_init_simulated.json' assert { type: 'json' }; +import PrivateKernelInnerJson from '../../artifacts/private_kernel_inner.json' assert { type: 'json' }; +import PrivateKernelInnerSimulatedJson from '../../artifacts/private_kernel_inner_simulated.json' assert { type: 'json' }; +import PrivateKernelTailJson from '../../artifacts/private_kernel_tail.json' assert { type: 'json' }; +import PrivateKernelTailSimulatedJson from '../../artifacts/private_kernel_tail_simulated.json' assert { type: 'json' }; +import PrivateKernelTailToPublicJson from '../../artifacts/private_kernel_tail_to_public.json' assert { type: 'json' }; +import PrivateKernelTailToPublicSimulatedJson from '../../artifacts/private_kernel_tail_to_public_simulated.json' assert { type: 'json' }; +import { + PrivateKernelResetArtifacts, + PrivateKernelResetSimulatedArtifacts, + type PrivateResetArtifact, +} from '../private_kernel_reset_data.js'; + +export type ClientProtocolArtifact = + | 'PrivateKernelInitArtifact' + | 'PrivateKernelInnerArtifact' + | 'PrivateKernelTailArtifact' + | 'PrivateKernelTailToPublicArtifact' + | PrivateResetArtifact; + +export const ClientCircuitArtifacts: Record = { + PrivateKernelInitArtifact: PrivateKernelInitJson as NoirCompiledCircuit, + PrivateKernelInnerArtifact: PrivateKernelInnerJson as NoirCompiledCircuit, + PrivateKernelTailArtifact: PrivateKernelTailJson as NoirCompiledCircuit, + PrivateKernelTailToPublicArtifact: PrivateKernelTailToPublicJson as NoirCompiledCircuit, + ...PrivateKernelResetArtifacts, +}; + +export const SimulatedClientCircuitArtifacts: Record = { + PrivateKernelInitArtifact: PrivateKernelInitSimulatedJson as NoirCompiledCircuit, + PrivateKernelInnerArtifact: PrivateKernelInnerSimulatedJson as NoirCompiledCircuit, + PrivateKernelTailArtifact: PrivateKernelTailSimulatedJson as NoirCompiledCircuit, + PrivateKernelTailToPublicArtifact: PrivateKernelTailToPublicSimulatedJson as NoirCompiledCircuit, + ...PrivateKernelResetSimulatedArtifacts, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/index.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/index.ts new file mode 100644 index 000000000000..acf23c285931 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/index.ts @@ -0,0 +1,14 @@ +import { type NoirCompiledCircuit } from '@aztec/types/noir'; + +import { ClientCircuitArtifacts, type ClientProtocolArtifact } from './client.js'; +import { ServerCircuitArtifacts, type ServerProtocolArtifact } from './server.js'; + +export * from './client.js'; +export * from './server.js'; + +export type ProtocolArtifact = ServerProtocolArtifact | ClientProtocolArtifact; + +export const ProtocolCircuitArtifacts: Record = { + ...ClientCircuitArtifacts, + ...ServerCircuitArtifacts, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts new file mode 100644 index 000000000000..21b780bea1f7 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts @@ -0,0 +1,60 @@ +import { type NoirCompiledCircuit } from '@aztec/types/noir'; + +import EmptyNestedJson from '../../artifacts/empty_nested.json' assert { type: 'json' }; +import EmptyNestedSimulatedJson from '../../artifacts/empty_nested_simulated.json' assert { type: 'json' }; +import BaseParityJson from '../../artifacts/parity_base.json' assert { type: 'json' }; +import RootParityJson from '../../artifacts/parity_root.json' assert { type: 'json' }; +import PrivateKernelEmptyJson from '../../artifacts/private_kernel_empty.json' assert { type: 'json' }; +import PrivateKernelEmptySimulatedJson from '../../artifacts/private_kernel_empty_simulated.json' assert { type: 'json' }; +import PrivateBaseRollupJson from '../../artifacts/rollup_base_private.json' assert { type: 'json' }; +import PrivateBaseRollupSimulatedJson from '../../artifacts/rollup_base_private_simulated.json' assert { type: 'json' }; +import PublicBaseRollupJson from '../../artifacts/rollup_base_public.json' assert { type: 'json' }; +import PublicBaseRollupSimulatedJson from '../../artifacts/rollup_base_public_simulated.json' assert { type: 'json' }; +import BlockMergeRollupJson from '../../artifacts/rollup_block_merge.json' assert { type: 'json' }; +import BlockRootRollupJson from '../../artifacts/rollup_block_root.json' assert { type: 'json' }; +import EmptyBlockRootRollupJson from '../../artifacts/rollup_block_root_empty.json' assert { type: 'json' }; +import MergeRollupJson from '../../artifacts/rollup_merge.json' assert { type: 'json' }; +import RootRollupJson from '../../artifacts/rollup_root.json' assert { type: 'json' }; +import { ClientCircuitArtifacts, ClientProtocolArtifact } from './client.js'; + +// These are all circuits that should generate proofs with the `recursive` flag. +export type ServerProtocolArtifact = + | 'EmptyNestedArtifact' + | 'PrivateKernelEmptyArtifact' + | 'BaseParityArtifact' + | 'RootParityArtifact' + | 'PrivateBaseRollupArtifact' + | 'PublicBaseRollupArtifact' + | 'MergeRollupArtifact' + | 'BlockRootRollupArtifact' + | 'EmptyBlockRootRollupArtifact' + | 'BlockMergeRollupArtifact' + | 'RootRollupArtifact'; + +export const ServerCircuitArtifacts: Record = { + EmptyNestedArtifact: EmptyNestedJson as NoirCompiledCircuit, + PrivateKernelEmptyArtifact: PrivateKernelEmptyJson as NoirCompiledCircuit, + BaseParityArtifact: BaseParityJson as NoirCompiledCircuit, + RootParityArtifact: RootParityJson as NoirCompiledCircuit, + PrivateBaseRollupArtifact: PrivateBaseRollupJson as NoirCompiledCircuit, + PublicBaseRollupArtifact: PublicBaseRollupJson as NoirCompiledCircuit, + MergeRollupArtifact: MergeRollupJson as NoirCompiledCircuit, + BlockRootRollupArtifact: BlockRootRollupJson as NoirCompiledCircuit, + EmptyBlockRootRollupArtifact: EmptyBlockRootRollupJson as NoirCompiledCircuit, + BlockMergeRollupArtifact: BlockMergeRollupJson as NoirCompiledCircuit, + RootRollupArtifact: RootRollupJson as NoirCompiledCircuit, +}; + +export const SimulatedServerCircuitArtifacts: Record = { + EmptyNestedArtifact: EmptyNestedSimulatedJson as NoirCompiledCircuit, + PrivateKernelEmptyArtifact: PrivateKernelEmptySimulatedJson as NoirCompiledCircuit, + BaseParityArtifact: BaseParityJson as NoirCompiledCircuit, + RootParityArtifact: RootParityJson as NoirCompiledCircuit, + PrivateBaseRollupArtifact: PrivateBaseRollupSimulatedJson as NoirCompiledCircuit, + PublicBaseRollupArtifact: PublicBaseRollupSimulatedJson as NoirCompiledCircuit, + MergeRollupArtifact: MergeRollupJson as NoirCompiledCircuit, + BlockRootRollupArtifact: BlockRootRollupJson as NoirCompiledCircuit, + EmptyBlockRootRollupArtifact: EmptyBlockRootRollupJson as NoirCompiledCircuit, + BlockMergeRollupArtifact: BlockMergeRollupJson as NoirCompiledCircuit, + RootRollupArtifact: RootRollupJson as NoirCompiledCircuit, +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/client.ts b/yarn-project/noir-protocol-circuits-types/src/client.ts new file mode 100644 index 000000000000..db2b21ae6015 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/client.ts @@ -0,0 +1,24 @@ +export { + convertPrivateKernelInitInputsToWitnessMap, + convertPrivateKernelInitOutputsFromWitnessMap, + convertPrivateKernelInnerInputsToWitnessMap, + convertPrivateKernelInnerOutputsFromWitnessMap, + convertPrivateKernelResetInputsToWitnessMap, + convertPrivateKernelResetOutputsFromWitnessMap, + convertPrivateKernelTailForPublicOutputsFromWitnessMap, + convertPrivateKernelTailInputsToWitnessMap, + convertPrivateKernelTailOutputsFromWitnessMap, + convertPrivateKernelTailToPublicInputsToWitnessMap, + executeInit, + executeInner, + executeReset, + executeTail, + executeTailForPublic, +} from './execution/client.js'; + +export { ClientCircuitArtifacts, type ClientProtocolArtifact } from './artifacts/client.js'; + +export { getPrivateKernelResetArtifactName } from './utils/private_kernel_reset.js'; +export { maxPrivateKernelResetDimensions, privateKernelResetDimensionsConfig } from './private_kernel_reset_data.js'; +export { foreignCallHandler } from './utils/foreign_call_handler.js'; +export { ClientCircuitVks, getVKIndex, getVKTreeRoot, getVKSiblingPath } from './vks.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts new file mode 100644 index 000000000000..0ef272fbae78 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts @@ -0,0 +1,404 @@ +import { + type PrivateKernelCircuitPublicInputs, + type PrivateKernelInitCircuitPrivateInputs, + type PrivateKernelInnerCircuitPrivateInputs, + type PrivateKernelResetCircuitPrivateInputs, + type PrivateKernelResetCircuitPrivateInputsVariants, + type PrivateKernelResetDimensions, + type PrivateKernelTailCircuitPrivateInputs, + type PrivateKernelTailCircuitPublicInputs, +} from '@aztec/circuits.js'; +import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; + +import TOML from '@iarna/toml'; +import { type CompiledCircuit, type InputMap, Noir, WitnessMap } from '@noir-lang/noir_js'; +import { type Abi, abiDecode, abiEncode } from '@noir-lang/noirc_abi'; + +import { ClientCircuitArtifacts, SimulatedClientCircuitArtifacts } from '../artifacts/client.js'; +import { PrivateResetArtifact } from '../private_kernel_reset_data.js'; +import { + mapFieldToNoir, + mapPrivateCallDataToNoir, + mapPrivateCircuitPublicInputsToNoir, + mapPrivateKernelCircuitPublicInputsFromNoir, + mapPrivateKernelCircuitPublicInputsToNoir, + mapPrivateKernelDataToNoir, + mapPrivateKernelResetHintsToNoir, + mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir, + mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir, + mapTxRequestToNoir, +} from '../type_conversion.js'; +import { + type PrivateKernelInitReturnType, + type PrivateKernelInnerReturnType, + type PrivateKernelResetReturnType, + type PrivateKernelTailReturnType, + type PrivateKernelTailToPublicReturnType, + PrivateKernelInit as executePrivateKernelInitWithACVM, + PrivateKernelInner as executePrivateKernelInnerWithACVM, + PrivateKernelTailToPublic as executePrivateKernelTailToPublicWithACVM, + PrivateKernelTail as executePrivateKernelTailWithACVM, +} from '../types/index.js'; +import { DecodedInputs } from '../utils/decoded_inputs.js'; +import { foreignCallHandler } from '../utils/foreign_call_handler.js'; +import { getPrivateKernelResetArtifactName } from '../utils/private_kernel_reset.js'; + +/** + * Executes the init private kernel. + * @param privateKernelInitCircuitPrivateInputs - The private inputs to the initial private kernel. + * @returns The public inputs. + */ +export async function executeInit( + privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, +): Promise { + const inputs = { + tx_request: mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), + vk_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), + protocol_contract_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.protocolContractTreeRoot), + private_call: mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), + is_private_only: privateKernelInitCircuitPrivateInputs.isPrivateOnly, + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, + ), + }; + updateProtocolCircuitSampleInputs('private-kernel-init', TOML.stringify(inputs)); + const returnType = await executePrivateKernelInitWithACVM( + inputs.tx_request, + inputs.vk_tree_root, + inputs.protocol_contract_tree_root, + inputs.private_call, + inputs.is_private_only, + inputs.app_public_inputs, + SimulatedClientCircuitArtifacts.PrivateKernelInitArtifact as CompiledCircuit, + foreignCallHandler, + ); + + return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Executes the inner private kernel. + * @param privateKernelInnerCircuitPrivateInputs - The private inputs to the inner private kernel. + * @returns The public inputs. + */ +export async function executeInner( + privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, +): Promise { + const inputs = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs, + ), + private_call: mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, + ), + }; + updateProtocolCircuitSampleInputs('private-kernel-inner', TOML.stringify(inputs)); + const returnType = await executePrivateKernelInnerWithACVM( + inputs.previous_kernel, + inputs.previous_kernel_public_inputs, + inputs.private_call, + inputs.app_public_inputs, + SimulatedClientCircuitArtifacts.PrivateKernelInnerArtifact as CompiledCircuit, + foreignCallHandler, + ); + + return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Executes the inner private kernel. + * @param privateKernelResetCircuitPrivateInputs - The private inputs to the reset private kernel. + * @returns The public inputs. + */ +export async function executeReset< + NH_RR_PENDING extends number, + NH_RR_SETTLED extends number, + NLL_RR_PENDING extends number, + NLL_RR_SETTLED extends number, + KEY_VALIDATION_REQUESTS extends number, + NUM_TRANSIENT_DATA_HINTS extends number, +>( + privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputsVariants< + NH_RR_PENDING, + NH_RR_SETTLED, + NLL_RR_PENDING, + NLL_RR_SETTLED, + KEY_VALIDATION_REQUESTS, + NUM_TRANSIENT_DATA_HINTS + >, + dimensions: PrivateKernelResetDimensions, + // TODO: This input is a hack so we can write full reset inputs to a Prover.toml. Ideally we remove it in favour of adding a test that runs a full reset. + untrimmedPrivateKernelResetCircuitPrivateInputs?: PrivateKernelResetCircuitPrivateInputs, +): Promise { + const artifact = SimulatedClientCircuitArtifacts[getPrivateKernelResetArtifactName(dimensions)]; + const program = new Noir(artifact as CompiledCircuit); + if (untrimmedPrivateKernelResetCircuitPrivateInputs) { + updateResetCircuitSampleInputs(untrimmedPrivateKernelResetCircuitPrivateInputs); + } + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, + ), + hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), + }; + const { returnValue } = await program.execute(args, foreignCallHandler); + return mapPrivateKernelCircuitPublicInputsFromNoir(returnValue as any); +} + +/** + * Executes the tail private kernel. + * @param privateKernelCircuitPrivateInputs - The private inputs to the tail private kernel. + * @returns The public inputs. + */ +export async function executeTail( + privateInputs: PrivateKernelTailCircuitPrivateInputs, +): Promise { + const inputs = { + previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), + }; + updateProtocolCircuitSampleInputs('private-kernel-tail', TOML.stringify(inputs)); + const returnType = await executePrivateKernelTailWithACVM( + inputs.previous_kernel, + inputs.previous_kernel_public_inputs, + SimulatedClientCircuitArtifacts.PrivateKernelTailArtifact as CompiledCircuit, + foreignCallHandler, + ); + + return mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir(returnType); +} + +/** + * Executes the tail private kernel. + * @param privateKernelInnerCircuitPrivateInputs - The private inputs to the tail private kernel. + * @returns The public inputs. + */ +export async function executeTailForPublic( + privateInputs: PrivateKernelTailCircuitPrivateInputs, +): Promise { + const inputs = { + previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), + }; + updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', TOML.stringify(inputs)); + const returnType = await executePrivateKernelTailToPublicWithACVM( + inputs.previous_kernel, + inputs.previous_kernel_public_inputs, + SimulatedClientCircuitArtifacts.PrivateKernelTailToPublicArtifact as CompiledCircuit, + foreignCallHandler, + ); + + return mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir(returnType); +} + +/** + * Converts the inputs of the private kernel init circuit into a witness map + * @param inputs - The private kernel inputs. + * @returns The witness map + */ +export function convertPrivateKernelInitInputsToWitnessMap( + privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, +): WitnessMap { + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInitArtifact.abi, { + tx_request: mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), + vk_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), + protocol_contract_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.protocolContractTreeRoot), + private_call: mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), + is_private_only: privateKernelInitCircuitPrivateInputs.isPrivateOnly, + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, + ), + }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the private kernel inner circuit into a witness map + * @param inputs - The private kernel inputs. + * @returns The witness map + */ +export function convertPrivateKernelInnerInputsToWitnessMap( + privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, +): WitnessMap { + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs, + ), + private_call: mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), + app_public_inputs: mapPrivateCircuitPublicInputsToNoir( + privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, + ), + }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the private kernel reset circuit into a witness map + * @param inputs - The private kernel inputs. + * @returns The witness map + */ +export function convertPrivateKernelResetInputsToWitnessMap< + NH_RR_PENDING extends number, + NH_RR_SETTLED extends number, + NLL_RR_PENDING extends number, + NLL_RR_SETTLED extends number, + KEY_VALIDATION_REQUESTS extends number, + NUM_TRANSIENT_DATA_HINTS extends number, +>( + privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputsVariants< + NH_RR_PENDING, + NH_RR_SETTLED, + NLL_RR_PENDING, + NLL_RR_SETTLED, + KEY_VALIDATION_REQUESTS, + NUM_TRANSIENT_DATA_HINTS + >, + artifactName: PrivateResetArtifact, +): WitnessMap { + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, + ), + hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), + }; + const artifact = ClientCircuitArtifacts[artifactName]; + const initialWitnessMap = abiEncode(artifact.abi as Abi, args); + return initialWitnessMap; +} + +/** + * Converts the inputs of the private kernel tail circuit into a witness map + * @param inputs - The private kernel inputs. + * @returns The witness map + */ +export function convertPrivateKernelTailInputsToWitnessMap( + privateKernelTailCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, +): WitnessMap { + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelTailCircuitPrivateInputs.previousKernel.publicInputs, + ), + }; + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, args); + return initialWitnessMap; +} + +/** + * Converts the inputs of the private kernel tail to public circuit into a witness map + * @param inputs - The private kernel inputs. + * @returns The witness map + */ +export function convertPrivateKernelTailToPublicInputsToWitnessMap( + privateKernelTailToPublicCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, +): WitnessMap { + const args: InputMap = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailToPublicCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelTailToPublicCircuitPrivateInputs.previousKernel.publicInputs, + ), + }; + const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, args); + return initialWitnessMap; +} + +/** + * Converts the outputs of the private kernel init circuit from a witness map. + * @param outputs - The private kernel outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateKernelInitOutputsFromWitnessMap(outputs: WitnessMap): PrivateKernelCircuitPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelInitArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as PrivateKernelInitReturnType; + + return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the private kernel inner circuit from a witness map. + * @param outputs - The private kernel outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateKernelInnerOutputsFromWitnessMap(outputs: WitnessMap): PrivateKernelCircuitPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as PrivateKernelInnerReturnType; + + return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the private kernel reset circuit from a witness map. + * @param outputs - The private kernel outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateKernelResetOutputsFromWitnessMap( + outputs: WitnessMap, + artifactName: PrivateResetArtifact, +): PrivateKernelCircuitPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const artifact = ClientCircuitArtifacts[artifactName]; + const decodedInputs: DecodedInputs = abiDecode(artifact.abi as Abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as PrivateKernelResetReturnType; + + return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the private kernel tail circuit from a witness map. + * @param outputs - The private kernel outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateKernelTailOutputsFromWitnessMap( + outputs: WitnessMap, +): PrivateKernelTailCircuitPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as PrivateKernelTailReturnType; + + return mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir(returnType); +} + +/** + * Converts the outputs of the private kernel tail for public circuit from a witness map. + * @param outputs - The private kernel outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateKernelTailForPublicOutputsFromWitnessMap( + outputs: WitnessMap, +): PrivateKernelTailCircuitPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as PrivateKernelTailToPublicReturnType; + + return mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir(returnType); +} + +function updateResetCircuitSampleInputs( + privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputs, +) { + const inputs = { + previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), + previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( + privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, + ), + hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), + }; + updateProtocolCircuitSampleInputs('private-kernel-reset', TOML.stringify(inputs)); +} diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/index.ts b/yarn-project/noir-protocol-circuits-types/src/execution/index.ts new file mode 100644 index 000000000000..9ab6d0fec4c4 --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/execution/index.ts @@ -0,0 +1,2 @@ +export * from './client.js'; +export * from './server.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts new file mode 100644 index 000000000000..9b0c2d5e04ab --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts @@ -0,0 +1,366 @@ +import { + type BaseOrMergeRollupPublicInputs, + type BaseParityInputs, + type BlockMergeRollupInputs, + type BlockRootOrBlockMergePublicInputs, + type BlockRootRollupInputs, + type EmptyBlockRootRollupInputs, + type KernelCircuitPublicInputs, + type MergeRollupInputs, + type ParityPublicInputs, + type PrivateBaseRollupInputs, + type PrivateKernelEmptyInputs, + type PublicBaseRollupInputs, + type RootParityInputs, + type RootRollupInputs, + type RootRollupPublicInputs, +} from '@aztec/circuits.js'; +import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; + +import TOML from '@iarna/toml'; +import { WitnessMap } from '@noir-lang/acvm_js'; +import { abiDecode, abiEncode } from '@noir-lang/noirc_abi'; + +import { ServerCircuitArtifacts, SimulatedServerCircuitArtifacts } from '../artifacts/server.js'; +import { + mapBaseOrMergeRollupPublicInputsFromNoir, + mapBaseParityInputsToNoir, + mapBlockMergeRollupInputsToNoir, + mapBlockRootOrBlockMergePublicInputsFromNoir, + mapBlockRootRollupInputsToNoir, + mapEmptyBlockRootRollupInputsToNoir, + mapEmptyKernelInputsToNoir, + mapKernelCircuitPublicInputsFromNoir, + mapMergeRollupInputsToNoir, + mapParityPublicInputsFromNoir, + mapPrivateBaseRollupInputsToNoir, + mapPublicBaseRollupInputsToNoir, + mapRootParityInputsToNoir, + mapRootRollupInputsToNoir, + mapRootRollupPublicInputsFromNoir, +} from '../type_conversion.js'; +import { + type ParityBaseReturnType, + type ParityRootReturnType, + type PrivateKernelEmptyReturnType, + type RollupBasePrivateReturnType, + type RollupBasePublicReturnType, + type RollupBlockMergeReturnType, + type RollupBlockRootEmptyReturnType, + type RollupBlockRootReturnType, + type RollupMergeReturnType, + type RollupRootReturnType, +} from '../types/index.js'; +import { DecodedInputs } from '../utils/decoded_inputs.js'; + +/** + * Converts the inputs of the base parity circuit into a witness map. + * @param inputs - The base parity inputs. + * @returns The witness map + */ +export function convertBaseParityInputsToWitnessMap(inputs: BaseParityInputs): WitnessMap { + const mapped = mapBaseParityInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BaseParityArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the root parity circuit into a witness map. + * @param inputs - The root parity inputs. + * @returns The witness map + */ +export function convertRootParityInputsToWitnessMap(inputs: RootParityInputs): WitnessMap { + const mapped = mapRootParityInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.RootParityArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +export function convertPrivateKernelEmptyInputsToWitnessMap(inputs: PrivateKernelEmptyInputs): WitnessMap { + const mapped = mapEmptyKernelInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, { input: mapped as any }); + return initialWitnessMap; +} + +export function convertPrivateBaseRollupInputsToWitnessMap(inputs: PrivateBaseRollupInputs): WitnessMap { + const mapped = mapPrivateBaseRollupInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +export function convertSimulatedPrivateBaseRollupInputsToWitnessMap(inputs: PrivateBaseRollupInputs): WitnessMap { + const mapped = mapPrivateBaseRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-base-private', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(SimulatedServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, { + inputs: mapped as any, + }); + return initialWitnessMap; +} + +export function convertPublicBaseRollupInputsToWitnessMap(inputs: PublicBaseRollupInputs): WitnessMap { + const mapped = mapPublicBaseRollupInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PublicBaseRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +export function convertSimulatedPublicBaseRollupInputsToWitnessMap(inputs: PublicBaseRollupInputs): WitnessMap { + const mapped = mapPublicBaseRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-base-public', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(SimulatedServerCircuitArtifacts.PublicBaseRollupArtifact.abi, { + inputs: mapped as any, + }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the merge rollup circuit into a witness map. + * @param inputs - The merge rollup inputs. + * @returns The witness map + */ +export function convertMergeRollupInputsToWitnessMap(inputs: MergeRollupInputs): WitnessMap { + const mapped = mapMergeRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-merge', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.MergeRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the block root rollup circuit into a witness map. + * @param inputs - The block root rollup inputs. + * @returns The witness map + */ +export function convertBlockRootRollupInputsToWitnessMap(inputs: BlockRootRollupInputs): WitnessMap { + const mapped = mapBlockRootRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-block-root', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BlockRootRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the empty block root rollup circuit into a witness map. + * @param inputs - The empty block root rollup inputs. + * @returns The witness map + */ +export function convertEmptyBlockRootRollupInputsToWitnessMap(inputs: EmptyBlockRootRollupInputs): WitnessMap { + const mapped = mapEmptyBlockRootRollupInputsToNoir(inputs); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.EmptyBlockRootRollupArtifact.abi, { + inputs: mapped as any, + }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the block merge rollup circuit into a witness map. + * @param inputs - The block merge rollup inputs. + * @returns The witness map + */ +export function convertBlockMergeRollupInputsToWitnessMap(inputs: BlockMergeRollupInputs): WitnessMap { + const mapped = mapBlockMergeRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-block-merge', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BlockMergeRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +/** + * Converts the inputs of the root rollup circuit into a witness map. + * @param inputs - The root rollup inputs. + * @returns The witness map + */ +export function convertRootRollupInputsToWitnessMap(inputs: RootRollupInputs): WitnessMap { + const mapped = mapRootRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-root', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(ServerCircuitArtifacts.RootRollupArtifact.abi, { inputs: mapped as any }); + return initialWitnessMap; +} + +export function convertPrivateKernelEmptyOutputsFromWitnessMap(outputs: WitnessMap): KernelCircuitPublicInputs { + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, outputs); + const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; + + return mapKernelCircuitPublicInputsFromNoir(returnType); +} + +export function convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap( + outputs: WitnessMap, +): KernelCircuitPublicInputs { + const decodedInputs: DecodedInputs = abiDecode( + SimulatedServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, + outputs, + ); + const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; + + return mapKernelCircuitPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the simulated base rollup circuit from a witness map. + * @param outputs - The base rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertSimulatedPrivateBaseRollupOutputsFromWitnessMap( + outputs: WitnessMap, +): BaseOrMergeRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode( + SimulatedServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, + outputs, + ); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBasePrivateReturnType; + + return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the base rollup circuit from a witness map. + * @param outputs - The base rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertPrivateBaseRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBasePrivateReturnType; + + return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the simulated base rollup circuit from a witness map. + * @param outputs - The base rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertSimulatedPublicBaseRollupOutputsFromWitnessMap( + outputs: WitnessMap, +): BaseOrMergeRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(SimulatedServerCircuitArtifacts.PublicBaseRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBasePublicReturnType; + + return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the base rollup circuit from a witness map. + * @param outputs - The base rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertPublicBaseRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PublicBaseRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBasePublicReturnType; + + return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the merge rollup circuit from a witness map. + * @param outputs - The merge rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertMergeRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.MergeRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupMergeReturnType; + + return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the empty block root rollup circuit from a witness map. + * @param outputs - The block root rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertEmptyBlockRootRollupOutputsFromWitnessMap( + outputs: WitnessMap, +): BlockRootOrBlockMergePublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.EmptyBlockRootRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBlockRootEmptyReturnType; + + return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the block root rollup circuit from a witness map. + * @param outputs - The block root rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertBlockRootRollupOutputsFromWitnessMap(outputs: WitnessMap): BlockRootOrBlockMergePublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BlockRootRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBlockRootReturnType; + + return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the block merge rollup circuit from a witness map. + * @param outputs - The block merge rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertBlockMergeRollupOutputsFromWitnessMap(outputs: WitnessMap): BlockRootOrBlockMergePublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BlockMergeRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBlockMergeReturnType; + + return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the root rollup circuit from a witness map. + * @param outputs - The root rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertRootRollupOutputsFromWitnessMap(outputs: WitnessMap): RootRollupPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.RootRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupRootReturnType; + + return mapRootRollupPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the base parity circuit from a witness map. + * @param outputs - The base parity outputs as a witness map. + * @returns The public inputs. + */ +export function convertBaseParityOutputsFromWitnessMap(outputs: WitnessMap): ParityPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BaseParityArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as ParityBaseReturnType; + + return mapParityPublicInputsFromNoir(returnType); +} + +/** + * Converts the outputs of the root parity circuit from a witness map. + * @param outputs - The root parity outputs as a witness map. + * @returns The public inputs. + */ +export function convertRootParityOutputsFromWitnessMap(outputs: WitnessMap): ParityPublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.RootParityArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as ParityRootReturnType; + + return mapParityPublicInputsFromNoir(returnType); +} diff --git a/yarn-project/noir-protocol-circuits-types/src/index.ts b/yarn-project/noir-protocol-circuits-types/src/index.ts index 3f5236f5d401..22bb7a5a0415 100644 --- a/yarn-project/noir-protocol-circuits-types/src/index.ts +++ b/yarn-project/noir-protocol-circuits-types/src/index.ts @@ -1,807 +1,7 @@ -import { - type BaseOrMergeRollupPublicInputs, - type BaseParityInputs, - type BlockMergeRollupInputs, - type BlockRootOrBlockMergePublicInputs, - type BlockRootRollupInputs, - type EmptyBlockRootRollupInputs, - Fr, - type KernelCircuitPublicInputs, - type MergeRollupInputs, - type ParityPublicInputs, - type PrivateBaseRollupInputs, - type PrivateKernelCircuitPublicInputs, - type PrivateKernelEmptyInputs, - type PrivateKernelInitCircuitPrivateInputs, - type PrivateKernelInnerCircuitPrivateInputs, - type PrivateKernelResetCircuitPrivateInputs, - type PrivateKernelResetCircuitPrivateInputsVariants, - type PrivateKernelResetDimensions, - type PrivateKernelTailCircuitPrivateInputs, - type PrivateKernelTailCircuitPublicInputs, - type PublicBaseRollupInputs, - type RootParityInputs, - type RootRollupInputs, - type RootRollupPublicInputs, -} from '@aztec/circuits.js'; -import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; -import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; +export * from './artifacts/index.js'; +export * from './execution/index.js'; -import TOML from '@iarna/toml'; -import { type ForeignCallInput, type ForeignCallOutput } from '@noir-lang/acvm_js'; -import { type CompiledCircuit, type InputMap, Noir } from '@noir-lang/noir_js'; -import { type Abi, abiDecode, abiEncode } from '@noir-lang/noirc_abi'; -import { type WitnessMap } from '@noir-lang/types'; -import { strict as assert } from 'assert'; - -import { - ClientCircuitArtifacts, - ServerCircuitArtifacts, - SimulatedClientCircuitArtifacts, - SimulatedServerCircuitArtifacts, -} from './artifacts.js'; -import { type PrivateResetArtifact } from './private_kernel_reset_data.js'; -import { - mapBaseOrMergeRollupPublicInputsFromNoir, - mapBaseParityInputsToNoir, - mapBlockMergeRollupInputsToNoir, - mapBlockRootOrBlockMergePublicInputsFromNoir, - mapBlockRootRollupInputsToNoir, - mapEmptyBlockRootRollupInputsToNoir, - mapEmptyKernelInputsToNoir, - mapFieldToNoir, - mapKernelCircuitPublicInputsFromNoir, - mapMergeRollupInputsToNoir, - mapParityPublicInputsFromNoir, - mapPrivateBaseRollupInputsToNoir, - mapPrivateCallDataToNoir, - mapPrivateCircuitPublicInputsToNoir, - mapPrivateKernelCircuitPublicInputsFromNoir, - mapPrivateKernelCircuitPublicInputsToNoir, - mapPrivateKernelDataToNoir, - mapPrivateKernelResetHintsToNoir, - mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir, - mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir, - mapPublicBaseRollupInputsToNoir, - mapRootParityInputsToNoir, - mapRootRollupInputsToNoir, - mapRootRollupPublicInputsFromNoir, - mapTxRequestToNoir, -} from './type_conversion.js'; -import { - type ParityBaseReturnType, - type ParityRootReturnType, - type PrivateKernelEmptyReturnType, - type PrivateKernelInitReturnType, - type PrivateKernelInnerReturnType, - type PrivateKernelResetReturnType, - type PrivateKernelTailReturnType, - type PrivateKernelTailToPublicReturnType, - type RollupBasePrivateReturnType, - type RollupBasePublicReturnType, - type RollupBlockMergeReturnType, - type RollupBlockRootEmptyReturnType, - type RollupBlockRootReturnType, - type RollupMergeReturnType, - type RollupRootReturnType, - PrivateKernelInit as executePrivateKernelInitWithACVM, - PrivateKernelInner as executePrivateKernelInnerWithACVM, - PrivateKernelTailToPublic as executePrivateKernelTailToPublicWithACVM, - PrivateKernelTail as executePrivateKernelTailWithACVM, -} from './types/index.js'; -import { getPrivateKernelResetArtifactName } from './utils/private_kernel_reset.js'; - -export * from './artifacts.js'; +export { getPrivateKernelResetArtifactName } from './utils/private_kernel_reset.js'; export { maxPrivateKernelResetDimensions, privateKernelResetDimensionsConfig } from './private_kernel_reset_data.js'; -export * from './utils/private_kernel_reset.js'; +export { foreignCallHandler } from './utils/foreign_call_handler.js'; export * from './vks.js'; - -/* eslint-disable camelcase */ - -// TODO(Tom): This should be exported from noirc_abi -/** - * The decoded inputs from the circuit. - */ -export type DecodedInputs = { - /** - * The inputs to the circuit - */ - inputs: Record; - /** - * The return value of the circuit - */ - return_value: any; -}; - -/** - * Executes the init private kernel. - * @param privateKernelInitCircuitPrivateInputs - The private inputs to the initial private kernel. - * @returns The public inputs. - */ -export async function executeInit( - privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, -): Promise { - const inputs = { - tx_request: mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), - vk_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), - protocol_contract_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.protocolContractTreeRoot), - private_call: mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), - is_private_only: privateKernelInitCircuitPrivateInputs.isPrivateOnly, - app_public_inputs: mapPrivateCircuitPublicInputsToNoir( - privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, - ), - }; - updateProtocolCircuitSampleInputs('private-kernel-init', TOML.stringify(inputs)); - const returnType = await executePrivateKernelInitWithACVM( - inputs.tx_request, - inputs.vk_tree_root, - inputs.protocol_contract_tree_root, - inputs.private_call, - inputs.is_private_only, - inputs.app_public_inputs, - SimulatedClientCircuitArtifacts.PrivateKernelInitArtifact as CompiledCircuit, - foreignCallHandler, - ); - - return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Executes the inner private kernel. - * @param privateKernelInnerCircuitPrivateInputs - The private inputs to the inner private kernel. - * @returns The public inputs. - */ -export async function executeInner( - privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, -): Promise { - const inputs = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs, - ), - private_call: mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), - app_public_inputs: mapPrivateCircuitPublicInputsToNoir( - privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, - ), - }; - updateProtocolCircuitSampleInputs('private-kernel-inner', TOML.stringify(inputs)); - const returnType = await executePrivateKernelInnerWithACVM( - inputs.previous_kernel, - inputs.previous_kernel_public_inputs, - inputs.private_call, - inputs.app_public_inputs, - SimulatedClientCircuitArtifacts.PrivateKernelInnerArtifact as CompiledCircuit, - foreignCallHandler, - ); - - return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Executes the inner private kernel. - * @param privateKernelResetCircuitPrivateInputs - The private inputs to the reset private kernel. - * @returns The public inputs. - */ -export async function executeReset< - NH_RR_PENDING extends number, - NH_RR_SETTLED extends number, - NLL_RR_PENDING extends number, - NLL_RR_SETTLED extends number, - KEY_VALIDATION_REQUESTS extends number, - NUM_TRANSIENT_DATA_HINTS extends number, ->( - privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputsVariants< - NH_RR_PENDING, - NH_RR_SETTLED, - NLL_RR_PENDING, - NLL_RR_SETTLED, - KEY_VALIDATION_REQUESTS, - NUM_TRANSIENT_DATA_HINTS - >, - dimensions: PrivateKernelResetDimensions, - // TODO: This input is a hack so we can write full reset inputs to a Prover.toml. Ideally we remove it in favour of adding a test that runs a full reset. - untrimmedPrivateKernelResetCircuitPrivateInputs?: PrivateKernelResetCircuitPrivateInputs, -): Promise { - const artifact = SimulatedClientCircuitArtifacts[getPrivateKernelResetArtifactName(dimensions)]; - const program = new Noir(artifact as CompiledCircuit); - if (untrimmedPrivateKernelResetCircuitPrivateInputs) { - updateResetCircuitSampleInputs(untrimmedPrivateKernelResetCircuitPrivateInputs); - } - const args: InputMap = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, - ), - hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), - }; - const { returnValue } = await program.execute(args, foreignCallHandler); - return mapPrivateKernelCircuitPublicInputsFromNoir(returnValue as any); -} - -/** - * Executes the tail private kernel. - * @param privateKernelCircuitPrivateInputs - The private inputs to the tail private kernel. - * @returns The public inputs. - */ -export async function executeTail( - privateInputs: PrivateKernelTailCircuitPrivateInputs, -): Promise { - const inputs = { - previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), - }; - updateProtocolCircuitSampleInputs('private-kernel-tail', TOML.stringify(inputs)); - const returnType = await executePrivateKernelTailWithACVM( - inputs.previous_kernel, - inputs.previous_kernel_public_inputs, - SimulatedClientCircuitArtifacts.PrivateKernelTailArtifact as CompiledCircuit, - foreignCallHandler, - ); - - return mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir(returnType); -} - -/** - * Executes the tail private kernel. - * @param privateKernelInnerCircuitPrivateInputs - The private inputs to the tail private kernel. - * @returns The public inputs. - */ -export async function executeTailForPublic( - privateInputs: PrivateKernelTailCircuitPrivateInputs, -): Promise { - const inputs = { - previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), - }; - updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', TOML.stringify(inputs)); - const returnType = await executePrivateKernelTailToPublicWithACVM( - inputs.previous_kernel, - inputs.previous_kernel_public_inputs, - SimulatedClientCircuitArtifacts.PrivateKernelTailToPublicArtifact as CompiledCircuit, - foreignCallHandler, - ); - - return mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir(returnType); -} - -/** - * Converts the inputs of the private kernel init circuit into a witness map - * @param inputs - The private kernel inputs. - * @returns The witness map - */ -export function convertPrivateKernelInitInputsToWitnessMap( - privateKernelInitCircuitPrivateInputs: PrivateKernelInitCircuitPrivateInputs, -): WitnessMap { - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInitArtifact.abi, { - tx_request: mapTxRequestToNoir(privateKernelInitCircuitPrivateInputs.txRequest), - vk_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.vkTreeRoot), - protocol_contract_tree_root: mapFieldToNoir(privateKernelInitCircuitPrivateInputs.protocolContractTreeRoot), - private_call: mapPrivateCallDataToNoir(privateKernelInitCircuitPrivateInputs.privateCall), - is_private_only: privateKernelInitCircuitPrivateInputs.isPrivateOnly, - app_public_inputs: mapPrivateCircuitPublicInputsToNoir( - privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, - ), - }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the private kernel inner circuit into a witness map - * @param inputs - The private kernel inputs. - * @returns The witness map - */ -export function convertPrivateKernelInnerInputsToWitnessMap( - privateKernelInnerCircuitPrivateInputs: PrivateKernelInnerCircuitPrivateInputs, -): WitnessMap { - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelInnerCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelInnerCircuitPrivateInputs.previousKernel.publicInputs, - ), - private_call: mapPrivateCallDataToNoir(privateKernelInnerCircuitPrivateInputs.privateCall), - app_public_inputs: mapPrivateCircuitPublicInputsToNoir( - privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, - ), - }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the private kernel reset circuit into a witness map - * @param inputs - The private kernel inputs. - * @returns The witness map - */ -export function convertPrivateKernelResetInputsToWitnessMap< - NH_RR_PENDING extends number, - NH_RR_SETTLED extends number, - NLL_RR_PENDING extends number, - NLL_RR_SETTLED extends number, - KEY_VALIDATION_REQUESTS extends number, - NUM_TRANSIENT_DATA_HINTS extends number, ->( - privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputsVariants< - NH_RR_PENDING, - NH_RR_SETTLED, - NLL_RR_PENDING, - NLL_RR_SETTLED, - KEY_VALIDATION_REQUESTS, - NUM_TRANSIENT_DATA_HINTS - >, - artifactName: PrivateResetArtifact, -): WitnessMap { - const args: InputMap = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, - ), - hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), - }; - const artifact = ClientCircuitArtifacts[artifactName]; - const initialWitnessMap = abiEncode(artifact.abi as Abi, args); - return initialWitnessMap; -} - -/** - * Converts the inputs of the private kernel tail circuit into a witness map - * @param inputs - The private kernel inputs. - * @returns The witness map - */ -export function convertPrivateKernelTailInputsToWitnessMap( - privateKernelTailCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, -): WitnessMap { - const args: InputMap = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelTailCircuitPrivateInputs.previousKernel.publicInputs, - ), - }; - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, args); - return initialWitnessMap; -} - -/** - * Converts the inputs of the private kernel tail to public circuit into a witness map - * @param inputs - The private kernel inputs. - * @returns The witness map - */ -export function convertPrivateKernelTailToPublicInputsToWitnessMap( - privateKernelTailToPublicCircuitPrivateInputs: PrivateKernelTailCircuitPrivateInputs, -): WitnessMap { - const args: InputMap = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelTailToPublicCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelTailToPublicCircuitPrivateInputs.previousKernel.publicInputs, - ), - }; - const initialWitnessMap = abiEncode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, args); - return initialWitnessMap; -} - -/** - * Converts the outputs of the private kernel init circuit from a witness map. - * @param outputs - The private kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateKernelInitOutputsFromWitnessMap(outputs: WitnessMap): PrivateKernelCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelInitArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PrivateKernelInitReturnType; - - return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the private kernel inner circuit from a witness map. - * @param outputs - The private kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateKernelInnerOutputsFromWitnessMap(outputs: WitnessMap): PrivateKernelCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelInnerArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PrivateKernelInnerReturnType; - - return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the private kernel reset circuit from a witness map. - * @param outputs - The private kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateKernelResetOutputsFromWitnessMap( - outputs: WitnessMap, - artifactName: PrivateResetArtifact, -): PrivateKernelCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const artifact = ClientCircuitArtifacts[artifactName]; - const decodedInputs: DecodedInputs = abiDecode(artifact.abi as Abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PrivateKernelResetReturnType; - - return mapPrivateKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the private kernel tail circuit from a witness map. - * @param outputs - The private kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateKernelTailOutputsFromWitnessMap( - outputs: WitnessMap, -): PrivateKernelTailCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelTailArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PrivateKernelTailReturnType; - - return mapPrivateKernelTailCircuitPublicInputsForRollupFromNoir(returnType); -} - -/** - * Converts the outputs of the private kernel tail for public circuit from a witness map. - * @param outputs - The private kernel outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateKernelTailForPublicOutputsFromWitnessMap( - outputs: WitnessMap, -): PrivateKernelTailCircuitPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ClientCircuitArtifacts.PrivateKernelTailToPublicArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as PrivateKernelTailToPublicReturnType; - - return mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir(returnType); -} - -/** - * Converts the inputs of the base parity circuit into a witness map. - * @param inputs - The base parity inputs. - * @returns The witness map - */ -export function convertBaseParityInputsToWitnessMap(inputs: BaseParityInputs): WitnessMap { - const mapped = mapBaseParityInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BaseParityArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the root parity circuit into a witness map. - * @param inputs - The root parity inputs. - * @returns The witness map - */ -export function convertRootParityInputsToWitnessMap(inputs: RootParityInputs): WitnessMap { - const mapped = mapRootParityInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.RootParityArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -export function convertPrivateKernelEmptyInputsToWitnessMap(inputs: PrivateKernelEmptyInputs): WitnessMap { - const mapped = mapEmptyKernelInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, { input: mapped as any }); - return initialWitnessMap; -} - -export function convertPrivateBaseRollupInputsToWitnessMap(inputs: PrivateBaseRollupInputs): WitnessMap { - const mapped = mapPrivateBaseRollupInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -export function convertSimulatedPrivateBaseRollupInputsToWitnessMap(inputs: PrivateBaseRollupInputs): WitnessMap { - const mapped = mapPrivateBaseRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-base-private', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(SimulatedServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, { - inputs: mapped as any, - }); - return initialWitnessMap; -} - -export function convertPublicBaseRollupInputsToWitnessMap(inputs: PublicBaseRollupInputs): WitnessMap { - const mapped = mapPublicBaseRollupInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.PublicBaseRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -export function convertSimulatedPublicBaseRollupInputsToWitnessMap(inputs: PublicBaseRollupInputs): WitnessMap { - const mapped = mapPublicBaseRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-base-public', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(SimulatedServerCircuitArtifacts.PublicBaseRollupArtifact.abi, { - inputs: mapped as any, - }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the merge rollup circuit into a witness map. - * @param inputs - The merge rollup inputs. - * @returns The witness map - */ -export function convertMergeRollupInputsToWitnessMap(inputs: MergeRollupInputs): WitnessMap { - const mapped = mapMergeRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-merge', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.MergeRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the block root rollup circuit into a witness map. - * @param inputs - The block root rollup inputs. - * @returns The witness map - */ -export function convertBlockRootRollupInputsToWitnessMap(inputs: BlockRootRollupInputs): WitnessMap { - const mapped = mapBlockRootRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-block-root', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BlockRootRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the empty block root rollup circuit into a witness map. - * @param inputs - The empty block root rollup inputs. - * @returns The witness map - */ -export function convertEmptyBlockRootRollupInputsToWitnessMap(inputs: EmptyBlockRootRollupInputs): WitnessMap { - const mapped = mapEmptyBlockRootRollupInputsToNoir(inputs); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.EmptyBlockRootRollupArtifact.abi, { - inputs: mapped as any, - }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the block merge rollup circuit into a witness map. - * @param inputs - The block merge rollup inputs. - * @returns The witness map - */ -export function convertBlockMergeRollupInputsToWitnessMap(inputs: BlockMergeRollupInputs): WitnessMap { - const mapped = mapBlockMergeRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-block-merge', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.BlockMergeRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -/** - * Converts the inputs of the root rollup circuit into a witness map. - * @param inputs - The root rollup inputs. - * @returns The witness map - */ -export function convertRootRollupInputsToWitnessMap(inputs: RootRollupInputs): WitnessMap { - const mapped = mapRootRollupInputsToNoir(inputs); - updateProtocolCircuitSampleInputs('rollup-root', TOML.stringify({ inputs: mapped })); - const initialWitnessMap = abiEncode(ServerCircuitArtifacts.RootRollupArtifact.abi, { inputs: mapped as any }); - return initialWitnessMap; -} - -export function convertPrivateKernelEmptyOutputsFromWitnessMap(outputs: WitnessMap): KernelCircuitPublicInputs { - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, outputs); - const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; - - return mapKernelCircuitPublicInputsFromNoir(returnType); -} - -export function convertSimulatedPrivateKernelEmptyOutputsFromWitnessMap( - outputs: WitnessMap, -): KernelCircuitPublicInputs { - const decodedInputs: DecodedInputs = abiDecode( - SimulatedServerCircuitArtifacts.PrivateKernelEmptyArtifact.abi, - outputs, - ); - const returnType = decodedInputs.return_value as PrivateKernelEmptyReturnType; - - return mapKernelCircuitPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the simulated base rollup circuit from a witness map. - * @param outputs - The base rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertSimulatedPrivateBaseRollupOutputsFromWitnessMap( - outputs: WitnessMap, -): BaseOrMergeRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode( - SimulatedServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, - outputs, - ); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBasePrivateReturnType; - - return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the base rollup circuit from a witness map. - * @param outputs - The base rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertPrivateBaseRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PrivateBaseRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBasePrivateReturnType; - - return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the simulated base rollup circuit from a witness map. - * @param outputs - The base rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertSimulatedPublicBaseRollupOutputsFromWitnessMap( - outputs: WitnessMap, -): BaseOrMergeRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(SimulatedServerCircuitArtifacts.PublicBaseRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBasePublicReturnType; - - return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the base rollup circuit from a witness map. - * @param outputs - The base rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertPublicBaseRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.PublicBaseRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBasePublicReturnType; - - return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the merge rollup circuit from a witness map. - * @param outputs - The merge rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertMergeRollupOutputsFromWitnessMap(outputs: WitnessMap): BaseOrMergeRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.MergeRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupMergeReturnType; - - return mapBaseOrMergeRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the empty block root rollup circuit from a witness map. - * @param outputs - The block root rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertEmptyBlockRootRollupOutputsFromWitnessMap( - outputs: WitnessMap, -): BlockRootOrBlockMergePublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.EmptyBlockRootRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBlockRootEmptyReturnType; - - return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the block root rollup circuit from a witness map. - * @param outputs - The block root rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertBlockRootRollupOutputsFromWitnessMap(outputs: WitnessMap): BlockRootOrBlockMergePublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BlockRootRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBlockRootReturnType; - - return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the block merge rollup circuit from a witness map. - * @param outputs - The block merge rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertBlockMergeRollupOutputsFromWitnessMap(outputs: WitnessMap): BlockRootOrBlockMergePublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BlockMergeRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupBlockMergeReturnType; - - return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the root rollup circuit from a witness map. - * @param outputs - The root rollup outputs as a witness map. - * @returns The public inputs. - */ -export function convertRootRollupOutputsFromWitnessMap(outputs: WitnessMap): RootRollupPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.RootRollupArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as RollupRootReturnType; - - return mapRootRollupPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the base parity circuit from a witness map. - * @param outputs - The base parity outputs as a witness map. - * @returns The public inputs. - */ -export function convertBaseParityOutputsFromWitnessMap(outputs: WitnessMap): ParityPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.BaseParityArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as ParityBaseReturnType; - - return mapParityPublicInputsFromNoir(returnType); -} - -/** - * Converts the outputs of the root parity circuit from a witness map. - * @param outputs - The root parity outputs as a witness map. - * @returns The public inputs. - */ -export function convertRootParityOutputsFromWitnessMap(outputs: WitnessMap): ParityPublicInputs { - // Decode the witness map into two fields, the return values and the inputs - const decodedInputs: DecodedInputs = abiDecode(ServerCircuitArtifacts.RootParityArtifact.abi, outputs); - - // Cast the inputs as the return type - const returnType = decodedInputs.return_value as ParityRootReturnType; - - return mapParityPublicInputsFromNoir(returnType); -} - -function updateResetCircuitSampleInputs( - privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputs, -) { - const inputs = { - previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), - previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir( - privateKernelResetCircuitPrivateInputs.previousKernel.publicInputs, - ), - hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), - }; - updateProtocolCircuitSampleInputs('private-kernel-reset', TOML.stringify(inputs)); -} - -function fromACVMField(field: string): Fr { - return Fr.fromBuffer(Buffer.from(field.slice(2), 'hex')); -} - -export function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise { - // ForeignCallInput is actually a string[], so the args are string[][]. - const log = createLogger('noir-protocol-circuits:oracle'); - - if (name === 'debugLog') { - assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields'); - const [msgRaw, _ignoredFieldsSize, fields] = args; - const msg: string = msgRaw.map(acvmField => String.fromCharCode(fromACVMField(acvmField).toNumber())).join(''); - const fieldsFr: Fr[] = fields.map((field: string) => fromACVMField(field)); - log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr)); - } else { - throw Error(`unexpected oracle during execution: ${name}`); - } - - return Promise.resolve([]); -} diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/decoded_inputs.ts b/yarn-project/noir-protocol-circuits-types/src/utils/decoded_inputs.ts new file mode 100644 index 000000000000..631b1a48f30a --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/utils/decoded_inputs.ts @@ -0,0 +1,14 @@ +// TODO(Tom): This should be exported from noirc_abi +/** + * The decoded inputs from the circuit. + */ +export type DecodedInputs = { + /** + * The inputs to the circuit + */ + inputs: Record; + /** + * The return value of the circuit + */ + return_value: any; +}; diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts b/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts new file mode 100644 index 000000000000..e01c95a83f9e --- /dev/null +++ b/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts @@ -0,0 +1,26 @@ +import { Fr } from '@aztec/circuits.js'; +import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; + +import { type ForeignCallInput, type ForeignCallOutput } from '@noir-lang/acvm_js'; +import { strict as assert } from 'assert'; + +function fromACVMField(field: string): Fr { + return Fr.fromBuffer(Buffer.from(field.slice(2), 'hex')); +} + +export function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise { + // ForeignCallInput is actually a string[], so the args are string[][]. + const log = createLogger('noir-protocol-circuits:oracle'); + + if (name === 'debugLog') { + assert(args.length === 3, 'expected 3 arguments for debugLog: msg, fields_length, fields'); + const [msgRaw, _ignoredFieldsSize, fields] = args; + const msg: string = msgRaw.map(acvmField => String.fromCharCode(fromACVMField(acvmField).toNumber())).join(''); + const fieldsFr: Fr[] = fields.map((field: string) => fromACVMField(field)); + log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr)); + } else { + throw Error(`unexpected oracle during execution: ${name}`); + } + + return Promise.resolve([]); +} diff --git a/yarn-project/noir-protocol-circuits-types/src/vks.ts b/yarn-project/noir-protocol-circuits-types/src/vks.ts index ca1675d32ad8..dbf31a3a6e30 100644 --- a/yarn-project/noir-protocol-circuits-types/src/vks.ts +++ b/yarn-project/noir-protocol-circuits-types/src/vks.ts @@ -41,7 +41,7 @@ import EmptyBlockRootRollupVkJson from '../artifacts/keys/rollup_block_root_empt 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 { type ClientProtocolArtifact, type ProtocolArtifact, type ServerProtocolArtifact } from './artifacts.js'; +import { type ClientProtocolArtifact, type ProtocolArtifact, type ServerProtocolArtifact } from './artifacts/index.js'; import { PrivateKernelResetVkIndexes, PrivateKernelResetVks } from './private_kernel_reset_data.js'; import { keyJsonToVKData } from './utils/vk_json.js'; diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index 7a5648ed7c34..030f8d4cf0fd 100644 --- a/yarn-project/pxe/src/kernel_oracle/index.ts +++ b/yarn-project/pxe/src/kernel_oracle/index.ts @@ -15,7 +15,7 @@ import { import { createLogger } from '@aztec/foundation/log'; import { type Tuple } from '@aztec/foundation/serialize'; import { type KeyStore } from '@aztec/key-store'; -import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types'; +import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/client'; import { type ContractDataOracle } from '../contract_data_oracle/index.js'; import { type ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js'; diff --git a/yarn-project/pxe/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts b/yarn-project/pxe/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts index 438506677dfd..b7435a4483b3 100644 --- a/yarn-project/pxe/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts +++ b/yarn-project/pxe/src/kernel_prover/hints/build_private_kernel_reset_private_inputs.ts @@ -37,7 +37,7 @@ import { import { makeTuple } from '@aztec/foundation/array'; import { padArrayEnd } from '@aztec/foundation/collection'; import { type Tuple, assertLength } from '@aztec/foundation/serialize'; -import { privateKernelResetDimensionsConfig } from '@aztec/noir-protocol-circuits-types'; +import { privateKernelResetDimensionsConfig } from '@aztec/noir-protocol-circuits-types/client'; import { type ProvingDataOracle } from '../proving_data_oracle.js'; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 64f147254dc3..784e239f55fd 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -32,7 +32,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'; +import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/client'; import { getProtocolContractSiblingPath, isProtocolContract, diff --git a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts index 020552dbaa68..f43a661b0eef 100644 --- a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts @@ -18,8 +18,8 @@ import { import { createLogger } from '@aztec/foundation/log'; import { elapsed } from '@aztec/foundation/timer'; import { - type ProtocolArtifact, - ProtocolCircuitVks, + ClientCircuitVks, + type ClientProtocolArtifact, executeInit, executeInner, executeReset, @@ -27,7 +27,7 @@ import { executeTailForPublic, getPrivateKernelResetArtifactName, maxPrivateKernelResetDimensions, -} from '@aztec/noir-protocol-circuits-types'; +} from '@aztec/noir-protocol-circuits-types/client'; import { type WitnessMap } from '@noir-lang/types'; @@ -116,10 +116,10 @@ export class TestPrivateKernelProver implements PrivateKernelProver { private makeEmptyKernelSimulateOutput< PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs, - >(publicInputs: PublicInputsType, circuitType: ProtocolArtifact) { + >(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) { const kernelProofOutput: PrivateKernelSimulateOutput = { publicInputs, - verificationKey: ProtocolCircuitVks[circuitType].keyAsFields, + verificationKey: ClientCircuitVks[circuitType].keyAsFields, outputWitness: new Map(), bytecode: Buffer.from([]), }; diff --git a/yarn-project/simulator/src/providers/acvm_wasm.ts b/yarn-project/simulator/src/providers/acvm_wasm.ts index 102da71a40aa..244e6e168a0a 100644 --- a/yarn-project/simulator/src/providers/acvm_wasm.ts +++ b/yarn-project/simulator/src/providers/acvm_wasm.ts @@ -1,4 +1,4 @@ -import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types'; +import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/client'; import { type NoirCompiledCircuit } from '@aztec/types/noir'; import { executeCircuit } from '@noir-lang/acvm_js'; From 9ffe5a07b754335834a895a2d4e4c9cda19386b1 Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 13 Dec 2024 16:29:40 +0000 Subject: [PATCH 48/57] fmt --- yarn-project/bb-prover/package.json | 1 + .../src/prover/bb_private_kernel_prover.ts | 14 +++---------- yarn-project/bb-prover/src/wasm/index.ts | 20 +++++++++---------- .../src/artifacts/server.ts | 1 - .../src/execution/client.ts | 8 +++++--- .../src/execution/server.ts | 4 ++-- .../kernel_prover/test/test_circuit_prover.ts | 8 +------- yarn-project/simulator/src/providers/index.ts | 1 - yarn-project/yarn.lock | 1 + 9 files changed, 23 insertions(+), 35 deletions(-) diff --git a/yarn-project/bb-prover/package.json b/yarn-project/bb-prover/package.json index dc1fa54030e6..82b623c73a9f 100644 --- a/yarn-project/bb-prover/package.json +++ b/yarn-project/bb-prover/package.json @@ -82,6 +82,7 @@ "@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi", "@noir-lang/types": "portal:../../noir/packages/types", "commander": "^12.1.0", + "pako": "^2.1.0", "source-map-support": "^0.5.21", "tslib": "^2.4.0" }, 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 7282df5980ac..d633ee32fcc0 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 @@ -1,22 +1,14 @@ +import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types'; +import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; import { - type AppCircuitSimulateOutput, - type PrivateKernelProver, - type PrivateKernelSimulateOutput, -} from '@aztec/circuit-types'; -import { type CircuitSimulationStats, type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; -import { - AGGREGATION_OBJECT_LENGTH, ClientIvcProof, - Fr, type PrivateKernelCircuitPublicInputs, type PrivateKernelInitCircuitPrivateInputs, type PrivateKernelInnerCircuitPrivateInputs, type PrivateKernelResetCircuitPrivateInputs, type PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs, - Proof, - RecursiveProof, - type VerificationKeyAsFields, + type Proof, type VerificationKeyData, } from '@aztec/circuits.js'; import { runInDirectory } from '@aztec/foundation/fs'; diff --git a/yarn-project/bb-prover/src/wasm/index.ts b/yarn-project/bb-prover/src/wasm/index.ts index 0a61f1b50ff3..9163848db9e2 100644 --- a/yarn-project/bb-prover/src/wasm/index.ts +++ b/yarn-project/bb-prover/src/wasm/index.ts @@ -1,20 +1,20 @@ import { AztecClientBackend } from '@aztec/bb.js'; -import { PrivateKernelProver, PrivateKernelSimulateOutput } from '@aztec/circuit-types'; +import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types'; import { ClientIvcProof, - PrivateKernelCircuitPublicInputs, - PrivateKernelInitCircuitPrivateInputs, - PrivateKernelInnerCircuitPrivateInputs, - PrivateKernelResetCircuitPrivateInputs, - PrivateKernelTailCircuitPrivateInputs, - PrivateKernelTailCircuitPublicInputs, + type PrivateKernelCircuitPublicInputs, + type PrivateKernelInitCircuitPrivateInputs, + type PrivateKernelInnerCircuitPrivateInputs, + type PrivateKernelResetCircuitPrivateInputs, + type PrivateKernelTailCircuitPrivateInputs, + type PrivateKernelTailCircuitPublicInputs, } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { ClientCircuitArtifacts, ClientCircuitVks, - ClientProtocolArtifact, + type ClientProtocolArtifact, convertPrivateKernelInitInputsToWitnessMap, convertPrivateKernelInitOutputsFromWitnessMap, convertPrivateKernelInnerInputsToWitnessMap, @@ -28,9 +28,9 @@ import { getPrivateKernelResetArtifactName, } from '@aztec/noir-protocol-circuits-types/client'; import { WASMSimulator } from '@aztec/simulator/client'; -import { NoirCompiledCircuit } from '@aztec/types/noir'; +import { type NoirCompiledCircuit } from '@aztec/types/noir'; -import { WitnessMap } from '@noir-lang/noir_js'; +import { type WitnessMap } from '@noir-lang/noir_js'; import { serializeWitness } from '@noir-lang/noirc_abi'; import { ungzip } from 'pako'; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts index 21b780bea1f7..3baaf1e5a5bb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts @@ -15,7 +15,6 @@ import BlockRootRollupJson from '../../artifacts/rollup_block_root.json' assert import EmptyBlockRootRollupJson from '../../artifacts/rollup_block_root_empty.json' assert { type: 'json' }; import MergeRollupJson from '../../artifacts/rollup_merge.json' assert { type: 'json' }; import RootRollupJson from '../../artifacts/rollup_root.json' assert { type: 'json' }; -import { ClientCircuitArtifacts, ClientProtocolArtifact } from './client.js'; // These are all circuits that should generate proofs with the `recursive` flag. export type ServerProtocolArtifact = diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts index 0ef272fbae78..c1e71d95fb0b 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts @@ -11,11 +11,11 @@ import { import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; import TOML from '@iarna/toml'; -import { type CompiledCircuit, type InputMap, Noir, WitnessMap } from '@noir-lang/noir_js'; +import { type CompiledCircuit, type InputMap, Noir, type WitnessMap } from '@noir-lang/noir_js'; import { type Abi, abiDecode, abiEncode } from '@noir-lang/noirc_abi'; import { ClientCircuitArtifacts, SimulatedClientCircuitArtifacts } from '../artifacts/client.js'; -import { PrivateResetArtifact } from '../private_kernel_reset_data.js'; +import { type PrivateResetArtifact } from '../private_kernel_reset_data.js'; import { mapFieldToNoir, mapPrivateCallDataToNoir, @@ -39,10 +39,12 @@ import { PrivateKernelTailToPublic as executePrivateKernelTailToPublicWithACVM, PrivateKernelTail as executePrivateKernelTailWithACVM, } from '../types/index.js'; -import { DecodedInputs } from '../utils/decoded_inputs.js'; +import { type DecodedInputs } from '../utils/decoded_inputs.js'; import { foreignCallHandler } from '../utils/foreign_call_handler.js'; import { getPrivateKernelResetArtifactName } from '../utils/private_kernel_reset.js'; +/* eslint-disable camelcase */ + /** * Executes the init private kernel. * @param privateKernelInitCircuitPrivateInputs - The private inputs to the initial private kernel. diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts index 9b0c2d5e04ab..77cbd116817c 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts @@ -18,7 +18,7 @@ import { import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; import TOML from '@iarna/toml'; -import { WitnessMap } from '@noir-lang/acvm_js'; +import { type WitnessMap } from '@noir-lang/acvm_js'; import { abiDecode, abiEncode } from '@noir-lang/noirc_abi'; import { ServerCircuitArtifacts, SimulatedServerCircuitArtifacts } from '../artifacts/server.js'; @@ -51,7 +51,7 @@ import { type RollupMergeReturnType, type RollupRootReturnType, } from '../types/index.js'; -import { DecodedInputs } from '../utils/decoded_inputs.js'; +import { type DecodedInputs } from '../utils/decoded_inputs.js'; /** * Converts the inputs of the base parity circuit into a witness map. diff --git a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts index f43a661b0eef..b6e4e9180774 100644 --- a/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/test/test_circuit_prover.ts @@ -1,11 +1,6 @@ -import { - type AppCircuitSimulateOutput, - type PrivateKernelProver, - type PrivateKernelSimulateOutput, -} from '@aztec/circuit-types'; +import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types'; import type { CircuitSimulationStats } from '@aztec/circuit-types/stats'; import { - CLIENT_IVC_VERIFICATION_KEY_LENGTH_IN_FIELDS, ClientIvcProof, type PrivateKernelCircuitPublicInputs, type PrivateKernelInitCircuitPrivateInputs, @@ -13,7 +8,6 @@ import { type PrivateKernelResetCircuitPrivateInputs, type PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs, - VerificationKeyAsFields, } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { elapsed } from '@aztec/foundation/timer'; diff --git a/yarn-project/simulator/src/providers/index.ts b/yarn-project/simulator/src/providers/index.ts index 15902dc2b652..634f163865d3 100644 --- a/yarn-project/simulator/src/providers/index.ts +++ b/yarn-project/simulator/src/providers/index.ts @@ -1,4 +1,3 @@ export * from './acvm_native.js'; -export * from './acvm_wasm.js'; export * from './simulation_provider.js'; export * from './factory.js'; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 5492efb92f54..1d643c2211bc 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -307,6 +307,7 @@ __metadata: commander: ^12.1.0 jest: ^29.5.0 jest-mock-extended: ^3.0.3 + pako: ^2.1.0 source-map-support: ^0.5.21 ts-node: ^10.9.1 tslib: ^2.4.0 From 2a6a045e2bf320a4ee40082c3481b79cea6d4563 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 05:14:04 +0000 Subject: [PATCH 49/57] updated lock --- boxes/yarn.lock | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/boxes/yarn.lock b/boxes/yarn.lock index 42e467831211..cf51ab3099c1 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -1680,20 +1680,6 @@ __metadata: languageName: node linkType: hard -"@rollup/plugin-json@npm:^6.1.0": - version: 6.1.0 - resolution: "@rollup/plugin-json@npm:6.1.0" - dependencies: - "@rollup/pluginutils": "npm:^5.1.0" - peerDependencies: - rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 - peerDependenciesMeta: - rollup: - optional: true - checksum: 9400c431b5e0cf3088ba2eb2d038809a2b0fb2a84ed004997da85582f48cd64958ed3168893c4f2c8109e38652400ed68282d0c92bf8ec07a3b2ef2e1ceab0b7 - languageName: node - linkType: hard - "@rollup/plugin-virtual@npm:^3.0.2": version: 3.0.2 resolution: "@rollup/plugin-virtual@npm:3.0.2" @@ -1706,7 +1692,7 @@ __metadata: languageName: node linkType: hard -"@rollup/pluginutils@npm:^5.0.1, @rollup/pluginutils@npm:^5.1.0": +"@rollup/pluginutils@npm:^5.0.1": version: 5.1.3 resolution: "@rollup/pluginutils@npm:5.1.3" dependencies: @@ -11970,7 +11956,6 @@ __metadata: "@eslint/js": "npm:^9.13.0" "@noir-lang/acvm_js": "link:../../../noir/packages/acvm_js" "@noir-lang/noirc_abi": "link:../../../noir/packages/noirc_abi" - "@rollup/plugin-json": "npm:^6.1.0" "@types/react": "npm:^18.3.12" "@types/react-dom": "npm:^18.3.1" "@vitejs/plugin-react-swc": "npm:^3.5.0" From 465077fd94258d263bc005572da71b14ab453002 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 06:34:21 +0000 Subject: [PATCH 50/57] more module splitting --- boxes/boxes/vite/vite.config.ts | 5 +-- .../src/prover/bb_private_kernel_prover.ts | 3 +- .../bb-prover/src/prover/bb_prover.ts | 3 +- .../src/prover/client_ivc_proof_utils.ts | 39 +++++++++++++++++++ yarn-project/bb-prover/src/prover/index.ts | 1 + .../bb-prover/src/verifier/bb_verifier.ts | 3 +- .../l1_payload/encrypted_log_payload.test.ts | 2 +- .../circuits.js/src/hash/hash.test.ts | 3 +- .../circuits.js/src/hash/map_slot.test.ts | 2 +- .../circuits.js/src/keys/derivation.test.ts | 2 +- .../src/structs/block_header.test.ts | 3 +- .../src/structs/client_ivc_proof.ts | 38 ------------------ .../src/structs/tx_request.test.ts | 3 +- .../circuits.js/src/types/public_keys.test.ts | 2 +- .../contract_class_registration.test.ts | 2 +- .../end-to-end/src/e2e_prover/full.test.ts | 3 +- yarn-project/foundation/package.json | 1 + .../foundation/src/fields/point.test.ts | 2 +- .../testing/{test_data.ts => files/index.ts} | 10 ++--- yarn-project/foundation/src/testing/index.ts | 6 ++- .../src/native_client_ivc_integration.test.ts | 14 +++++-- .../src/execution/client.ts | 36 +++++++++++++---- .../src/execution/server.ts | 2 +- .../src/orchestrator/orchestrator.ts | 2 +- .../src/test/bb_prover_full_rollup.test.ts | 3 +- .../pxe/src/kernel_prover/kernel_prover.ts | 2 +- 26 files changed, 113 insertions(+), 79 deletions(-) create mode 100644 yarn-project/bb-prover/src/prover/client_ivc_proof_utils.ts rename yarn-project/foundation/src/testing/{test_data.ts => files/index.ts} (92%) diff --git a/boxes/boxes/vite/vite.config.ts b/boxes/boxes/vite/vite.config.ts index 1eee22a8210e..7920e3e5cd9d 100644 --- a/boxes/boxes/vite/vite.config.ts +++ b/boxes/boxes/vite/vite.config.ts @@ -32,10 +32,7 @@ export default defineConfig({ plugins: [ react(), nodePolyfillsFix({ - overrides: { - fs: "memfs", - buffer: "buffer/", - }, + exclude: ["fs"], }), topLevelAwait(), ], 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 d633ee32fcc0..3059f826a571 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 @@ -45,6 +45,7 @@ import { type BBConfig } from '../config.js'; import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js'; import { mapProtocolArtifactNameToCircuitName } from '../stats.js'; import { extractVkData } from '../verification_key/verification_key_data.js'; +import { readFromOutputDirectory } from './client_ivc_proof_utils.js'; /** * This proof creator implementation uses the native bb binary. @@ -96,7 +97,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { throw new Error(provingResult.reason); } - const proof = await ClientIvcProof.readFromOutputDirectory(directory); + const proof = await readFromOutputDirectory(directory); this.log.info(`Generated IVC proof`, { duration: provingResult.durationMs, diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index 7deae9e16ffd..62391579ed88 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -99,6 +99,7 @@ import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js'; import { ProverInstrumentation } from '../instrumentation.js'; import { mapProtocolArtifactNameToCircuitName } from '../stats.js'; import { extractAvmVkData, extractVkData } from '../verification_key/verification_key_data.js'; +import { writeToOutputDirectory } from './client_ivc_proof_utils.js'; const logger = createLogger('bb-prover'); @@ -551,7 +552,7 @@ export class BBNativeRollupProver implements ServerCircuitProver { const hasher = crypto.createHash('sha256'); hasher.update(input.toBuffer()); - await input.clientIVCData.writeToOutputDirectory(bbWorkingDirectory); + await writeToOutputDirectory(input.clientIVCData, bbWorkingDirectory); const provingResult = await generateTubeProof(this.config.bbBinaryPath, bbWorkingDirectory, logger.verbose); if (provingResult.status === BB_RESULT.FAILURE) { diff --git a/yarn-project/bb-prover/src/prover/client_ivc_proof_utils.ts b/yarn-project/bb-prover/src/prover/client_ivc_proof_utils.ts new file mode 100644 index 000000000000..ba604dc6866c --- /dev/null +++ b/yarn-project/bb-prover/src/prover/client_ivc_proof_utils.ts @@ -0,0 +1,39 @@ +import { ClientIvcProof } from '@aztec/circuits.js'; + +import { promises as fs } from 'fs'; +import { join } from 'path'; + +/** + * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs + * Create a ClientIvcProof from the result of client_ivc_prove_output_all or client_ivc_prove_output_all_msgpack + * @param directory the directory of results + * @returns the encapsulated client ivc proof + */ +export async function readFromOutputDirectory(directory: string) { + const [clientIvcVkBuffer, clientIvcProofBuffer] = await Promise.all( + ['client_ivc_vk', 'client_ivc_proof'].map(fileName => fs.readFile(join(directory, fileName))), + ); + return new ClientIvcProof(clientIvcProofBuffer, clientIvcVkBuffer); +} + +/** + * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs + * Serialize a ClientIvcProof to the files expected by prove_tube + * + * Example usage: + * await runInDirectory(bbWorkingDirectory, async (dir: string) => { + * await privateTx.clientIvcProof!.writeToOutputDirectory(bbWorkingDirectory); + * const result = await generateTubeProof(bbPath, dir, logger.info) + * expect(result.status).toBe(BB_RESULT.SUCCESS) + * }); + * @param proof the ClientIvcProof from readFromOutputDirectory + * @param directory the directory of results + */ +export async function writeToOutputDirectory(clientIvcProof: ClientIvcProof, directory: string) { + const { clientIvcProofBuffer, clientIvcVkBuffer } = clientIvcProof; + const fileData = [ + ['client_ivc_proof', clientIvcProofBuffer], + ['client_ivc_vk', clientIvcVkBuffer], + ] as const; + await Promise.all(fileData.map(([fileName, buffer]) => fs.writeFile(join(directory, fileName), buffer))); +} diff --git a/yarn-project/bb-prover/src/prover/index.ts b/yarn-project/bb-prover/src/prover/index.ts index 614534850895..4079e27943cf 100644 --- a/yarn-project/bb-prover/src/prover/index.ts +++ b/yarn-project/bb-prover/src/prover/index.ts @@ -1,2 +1,3 @@ export * from './bb_prover.js'; export * from './bb_private_kernel_prover.js'; +export * from './client_ivc_proof_utils.js'; diff --git a/yarn-project/bb-prover/src/verifier/bb_verifier.ts b/yarn-project/bb-prover/src/verifier/bb_verifier.ts index e99102f074e8..e1f5b17def29 100644 --- a/yarn-project/bb-prover/src/verifier/bb_verifier.ts +++ b/yarn-project/bb-prover/src/verifier/bb_verifier.ts @@ -23,6 +23,7 @@ import { } from '../bb/execute.js'; import { type BBConfig } from '../config.js'; import { type UltraKeccakHonkProtocolArtifact, getUltraHonkFlavorForCircuit } from '../honk.js'; +import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js'; import { isProtocolArtifactRecursive, mapProtocolArtifactNameToCircuitName } from '../stats.js'; import { extractVkData } from '../verification_key/verification_key_data.js'; @@ -162,7 +163,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier { this.logger.debug(`${circuit} BB out - ${message}`); }; - await tx.clientIvcProof.writeToOutputDirectory(bbWorkingDirectory); + await writeToOutputDirectory(tx.clientIvcProof, bbWorkingDirectory); const result = await verifyClientIvcProof(this.config.bbBinaryPath, bbWorkingDirectory, logFunction); if (result.status === BB_RESULT.FAILURE) { diff --git a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_payload.test.ts b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_payload.test.ts index 93879b71d629..8fa34784694f 100644 --- a/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_payload.test.ts +++ b/yarn-project/circuit-types/src/logs/l1_payload/encrypted_log_payload.test.ts @@ -8,7 +8,7 @@ import { } from '@aztec/circuits.js'; import { randomBytes } from '@aztec/foundation/crypto'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; -import { updateInlineTestData } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { EncryptedLogPayload } from './encrypted_log_payload.js'; diff --git a/yarn-project/circuits.js/src/hash/hash.test.ts b/yarn-project/circuits.js/src/hash/hash.test.ts index fc1f0bc9018d..39fa210a6f3b 100644 --- a/yarn-project/circuits.js/src/hash/hash.test.ts +++ b/yarn-project/circuits.js/src/hash/hash.test.ts @@ -1,5 +1,6 @@ import { times } from '@aztec/foundation/collection'; -import { setupCustomSnapshotSerializers, updateInlineTestData } from '@aztec/foundation/testing'; +import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { AztecAddress, EthAddress, Fr, L2ToL1Message, ScopedL2ToL1Message } from '../index.js'; import { makeAztecAddress } from '../tests/factories.js'; diff --git a/yarn-project/circuits.js/src/hash/map_slot.test.ts b/yarn-project/circuits.js/src/hash/map_slot.test.ts index f21df688f33f..b120c496ea5c 100644 --- a/yarn-project/circuits.js/src/hash/map_slot.test.ts +++ b/yarn-project/circuits.js/src/hash/map_slot.test.ts @@ -1,6 +1,6 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; -import { updateInlineTestData } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { deriveStorageSlotInMap } from './index.js'; diff --git a/yarn-project/circuits.js/src/keys/derivation.test.ts b/yarn-project/circuits.js/src/keys/derivation.test.ts index 6f67df60ea4e..e2fec80baf58 100644 --- a/yarn-project/circuits.js/src/keys/derivation.test.ts +++ b/yarn-project/circuits.js/src/keys/derivation.test.ts @@ -1,5 +1,5 @@ import { Fr, Point } from '@aztec/foundation/fields'; -import { updateInlineTestData } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { PublicKeys } from '../types/public_keys.js'; import { computeAddress, computePreaddress } from './derivation.js'; diff --git a/yarn-project/circuits.js/src/structs/block_header.test.ts b/yarn-project/circuits.js/src/structs/block_header.test.ts index 053bf0d26397..40c7e3eec967 100644 --- a/yarn-project/circuits.js/src/structs/block_header.test.ts +++ b/yarn-project/circuits.js/src/structs/block_header.test.ts @@ -1,5 +1,6 @@ import { randomInt } from '@aztec/foundation/crypto'; -import { setupCustomSnapshotSerializers, updateInlineTestData } from '@aztec/foundation/testing'; +import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { BLOCK_HEADER_LENGTH } from '../constants.gen.js'; import { makeHeader } from '../tests/factories.js'; diff --git a/yarn-project/circuits.js/src/structs/client_ivc_proof.ts b/yarn-project/circuits.js/src/structs/client_ivc_proof.ts index 3ce4169c2f8e..f8c2bf1b59ea 100644 --- a/yarn-project/circuits.js/src/structs/client_ivc_proof.ts +++ b/yarn-project/circuits.js/src/structs/client_ivc_proof.ts @@ -1,9 +1,6 @@ import { bufferSchemaFor } from '@aztec/foundation/schemas'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; -import { promises as fs } from 'fs'; -import path from 'path'; - /** * TODO(https://github.com/AztecProtocol/aztec-packages/issues/7370) refactory this to * eventually we read all these VKs from the data tree instead of passing them @@ -25,41 +22,6 @@ export class ClientIvcProof { return new ClientIvcProof(Buffer.from(''), Buffer.from('')); } - /** - * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs - * Create a ClientIvcProof from the result of client_ivc_prove_output_all or client_ivc_prove_output_all_msgpack - * @param directory the directory of results - * @returns the encapsulated client ivc proof - */ - static async readFromOutputDirectory(directory: string) { - const [clientIvcVkBuffer, clientIvcProofBuffer] = await Promise.all( - ['client_ivc_vk', 'client_ivc_proof'].map(fileName => fs.readFile(path.join(directory, fileName))), - ); - return new ClientIvcProof(clientIvcProofBuffer, clientIvcVkBuffer); - } - - /** - * TODO(#7371): eventually remove client_ivc_prove_output_all_msgpack and properly handle these accumulators and VKs - * Serialize a ClientIvcProof to the files expected by prove_tube - * - * Example usage: - * await runInDirectory(bbWorkingDirectory, async (dir: string) => { - * await privateTx.clientIvcProof!.writeToOutputDirectory(bbWorkingDirectory); - * const result = await generateTubeProof(bbPath, dir, logger.info) - * expect(result.status).toBe(BB_RESULT.SUCCESS) - * }); - * @param proof the ClientIvcProof from readFromOutputDirectory - * @param directory the directory of results - */ - async writeToOutputDirectory(directory: string) { - const { clientIvcProofBuffer, clientIvcVkBuffer } = this; - const fileData = [ - ['client_ivc_proof', clientIvcProofBuffer], - ['client_ivc_vk', clientIvcVkBuffer], - ] as const; - await Promise.all(fileData.map(([fileName, buffer]) => fs.writeFile(path.join(directory, fileName), buffer))); - } - static get schema() { return bufferSchemaFor(ClientIvcProof); } diff --git a/yarn-project/circuits.js/src/structs/tx_request.test.ts b/yarn-project/circuits.js/src/structs/tx_request.test.ts index 8c97cd8e0f48..723e322817e5 100644 --- a/yarn-project/circuits.js/src/structs/tx_request.test.ts +++ b/yarn-project/circuits.js/src/structs/tx_request.test.ts @@ -2,7 +2,8 @@ import { FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { randomInt } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; -import { setupCustomSnapshotSerializers, updateInlineTestData } from '@aztec/foundation/testing'; +import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { TX_REQUEST_LENGTH } from '../constants.gen.js'; import { makeTxRequest } from '../tests/factories.js'; diff --git a/yarn-project/circuits.js/src/types/public_keys.test.ts b/yarn-project/circuits.js/src/types/public_keys.test.ts index b4a21a9e2c08..e8068ff6c310 100644 --- a/yarn-project/circuits.js/src/types/public_keys.test.ts +++ b/yarn-project/circuits.js/src/types/public_keys.test.ts @@ -1,5 +1,5 @@ import { Fr, Point } from '@aztec/foundation/fields'; -import { updateInlineTestData } from '@aztec/foundation/testing'; +import { updateInlineTestData } from '@aztec/foundation/testing/files'; import { PublicKeys } from './public_keys.js'; diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts index 4ef0d5014d8c..040d421464b4 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts @@ -22,7 +22,7 @@ import { } from '@aztec/aztec.js/deployment'; import { type ContractClassIdPreimage, PublicKeys, computeContractClassId } from '@aztec/circuits.js'; import { FunctionSelector, FunctionType } from '@aztec/foundation/abi'; -import { writeTestData } from '@aztec/foundation/testing'; +import { writeTestData } from '@aztec/foundation/testing/files'; import { StatefulTestContract, TokenContractArtifact } from '@aztec/noir-contracts.js'; import { TestContract } from '@aztec/noir-contracts.js/Test'; diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index 69fca3c6a2b6..f8e42817c5e4 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -1,5 +1,6 @@ import { type AztecAddress, EthAddress, retryUntil } from '@aztec/aztec.js'; -import { isGenerateTestDataEnabled, switchGenerateProtocolCircuitTestData } from '@aztec/foundation/testing'; +import { isGenerateTestDataEnabled } from '@aztec/foundation/testing'; +import { switchGenerateProtocolCircuitTestData } from '@aztec/foundation/testing/files'; import { RewardDistributorAbi, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import '@jest/globals'; diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 616a186ef131..ed496a7193ab 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -47,6 +47,7 @@ "./committable": "./dest/committable/index.js", "./noir": "./dest/noir/index.js", "./testing": "./dest/testing/index.js", + "./testing/files": "./dest/testing/files/index.js", "./array": "./dest/array/index.js", "./validation": "./dest/validation/index.js", "./promise": "./dest/promise/index.js", diff --git a/yarn-project/foundation/src/fields/point.test.ts b/yarn-project/foundation/src/fields/point.test.ts index f98771fb5c0e..f7650b38da06 100644 --- a/yarn-project/foundation/src/fields/point.test.ts +++ b/yarn-project/foundation/src/fields/point.test.ts @@ -1,6 +1,6 @@ import { jsonParseWithSchema, jsonStringify } from '../json-rpc/convert.js'; import { schemas } from '../schemas/schemas.js'; -import { updateInlineTestData } from '../testing/test_data.js'; +import { updateInlineTestData } from '../testing/files/index.js'; import { Fr } from './fields.js'; import { Point } from './point.js'; diff --git a/yarn-project/foundation/src/testing/test_data.ts b/yarn-project/foundation/src/testing/files/index.ts similarity index 92% rename from yarn-project/foundation/src/testing/test_data.ts rename to yarn-project/foundation/src/testing/files/index.ts index e1575d01ebbb..87a99ab51d49 100644 --- a/yarn-project/foundation/src/testing/test_data.ts +++ b/yarn-project/foundation/src/testing/files/index.ts @@ -1,17 +1,13 @@ import { existsSync, readFileSync, writeFileSync } from 'fs'; import { dirname, join, resolve } from 'path'; -import { createConsoleLogger } from '../log/console.js'; -import { fileURLToPath } from '../url/index.js'; +import { createConsoleLogger } from '../../log/console.js'; +import { fileURLToPath } from '../../url/index.js'; +import { isGenerateTestDataEnabled } from '../index.js'; const testData: { [key: string]: unknown[] } = {}; let generateProtocolCircuitTestData = false; -/** Returns whether test data generation is enabled */ -export function isGenerateTestDataEnabled() { - return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined'; -} - /** * This is separate so Prover.tomls don't get edited everytime any test is run, * Only full.test updates prover tomls, then switches this off. diff --git a/yarn-project/foundation/src/testing/index.ts b/yarn-project/foundation/src/testing/index.ts index b39430dd6f06..484c260d7412 100644 --- a/yarn-project/foundation/src/testing/index.ts +++ b/yarn-project/foundation/src/testing/index.ts @@ -1,3 +1,7 @@ -export * from './test_data.js'; export * from './snapshot_serializer.js'; export * from './port_allocator.js'; + +/** Returns whether test data generation is enabled */ +export function isGenerateTestDataEnabled() { + return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined'; +} diff --git a/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts index 9572a436fb26..4d59ce3011e7 100644 --- a/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts @@ -1,4 +1,10 @@ -import { BB_RESULT, executeBbClientIvcProof, verifyClientIvcProof } from '@aztec/bb-prover'; +import { + BB_RESULT, + executeBbClientIvcProof, + readFromOutputDirectory, + verifyClientIvcProof, + writeToOutputDirectory, +} from '@aztec/bb-prover'; import { ClientIvcProof } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; @@ -46,7 +52,7 @@ describe('Client IVC Integration', () => { throw new Error(provingResult.reason); } - return ClientIvcProof.readFromOutputDirectory(bbWorkingDirectory); + return readFromOutputDirectory(bbWorkingDirectory); } // This test will verify a client IVC proof of a simple tx: @@ -57,7 +63,7 @@ describe('Client IVC Integration', () => { const [bytecodes, witnessStack] = await generate3FunctionTestingIVCStack(); const proof = await createClientIvcProof(witnessStack, bytecodes); - await proof.writeToOutputDirectory(bbWorkingDirectory); + await writeToOutputDirectory(proof, bbWorkingDirectory); const verifyResult = await verifyClientIvcProof(bbBinaryPath, bbWorkingDirectory, logger.info); expect(verifyResult.status).toEqual(BB_RESULT.SUCCESS); @@ -74,7 +80,7 @@ describe('Client IVC Integration', () => { const [bytecodes, witnessStack] = await generate6FunctionTestingIVCStack(); const proof = await createClientIvcProof(witnessStack, bytecodes); - await proof.writeToOutputDirectory(bbWorkingDirectory); + await writeToOutputDirectory(proof, bbWorkingDirectory); const verifyResult = await verifyClientIvcProof(bbBinaryPath, bbWorkingDirectory, logger.info); expect(verifyResult.status).toEqual(BB_RESULT.SUCCESS); diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts index c1e71d95fb0b..d9ec4f0ff775 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts @@ -8,7 +8,7 @@ import { type PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs, } from '@aztec/circuits.js'; -import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; +import { isGenerateTestDataEnabled } from '@aztec/foundation/testing'; import TOML from '@iarna/toml'; import { type CompiledCircuit, type InputMap, Noir, type WitnessMap } from '@noir-lang/noir_js'; @@ -63,7 +63,11 @@ export async function executeInit( privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, ), }; - updateProtocolCircuitSampleInputs('private-kernel-init', TOML.stringify(inputs)); + // Gated to avoid importing the testing files module in the browser + if (isGenerateTestDataEnabled()) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + updateProtocolCircuitSampleInputs('private-kernel-init', TOML.stringify(inputs)); + } const returnType = await executePrivateKernelInitWithACVM( inputs.tx_request, inputs.vk_tree_root, @@ -96,7 +100,11 @@ export async function executeInner( privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, ), }; - updateProtocolCircuitSampleInputs('private-kernel-inner', TOML.stringify(inputs)); + // Gated to avoid importing the testing files module in the browser + if (isGenerateTestDataEnabled()) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + updateProtocolCircuitSampleInputs('private-kernel-inner', TOML.stringify(inputs)); + } const returnType = await executePrivateKernelInnerWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -137,7 +145,7 @@ export async function executeReset< const artifact = SimulatedClientCircuitArtifacts[getPrivateKernelResetArtifactName(dimensions)]; const program = new Noir(artifact as CompiledCircuit); if (untrimmedPrivateKernelResetCircuitPrivateInputs) { - updateResetCircuitSampleInputs(untrimmedPrivateKernelResetCircuitPrivateInputs); + await updateResetCircuitSampleInputs(untrimmedPrivateKernelResetCircuitPrivateInputs); } const args: InputMap = { previous_kernel: mapPrivateKernelDataToNoir(privateKernelResetCircuitPrivateInputs.previousKernel), @@ -162,7 +170,11 @@ export async function executeTail( previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), }; - updateProtocolCircuitSampleInputs('private-kernel-tail', TOML.stringify(inputs)); + // Gated to avoid importing the testing files module in the browser + if (isGenerateTestDataEnabled()) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + updateProtocolCircuitSampleInputs('private-kernel-tail', TOML.stringify(inputs)); + } const returnType = await executePrivateKernelTailWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -185,7 +197,11 @@ export async function executeTailForPublic( previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), }; - updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', TOML.stringify(inputs)); + // Gated to avoid importing the testing files module in the browser + if (isGenerateTestDataEnabled()) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', TOML.stringify(inputs)); + } const returnType = await executePrivateKernelTailToPublicWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -392,7 +408,7 @@ export function convertPrivateKernelTailForPublicOutputsFromWitnessMap( return mapPrivateKernelTailCircuitPublicInputsForPublicFromNoir(returnType); } -function updateResetCircuitSampleInputs( +async function updateResetCircuitSampleInputs( privateKernelResetCircuitPrivateInputs: PrivateKernelResetCircuitPrivateInputs, ) { const inputs = { @@ -402,5 +418,9 @@ function updateResetCircuitSampleInputs( ), hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), }; - updateProtocolCircuitSampleInputs('private-kernel-reset', TOML.stringify(inputs)); + // Gated to avoid importing the testing files module in the browser + if (isGenerateTestDataEnabled()) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + updateProtocolCircuitSampleInputs('private-kernel-reset', TOML.stringify(inputs)); + } } diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts index 77cbd116817c..3e136c01e06e 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts @@ -15,7 +15,7 @@ import { type RootRollupInputs, type RootRollupPublicInputs, } from '@aztec/circuits.js'; -import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing'; +import { updateProtocolCircuitSampleInputs } from '@aztec/foundation/testing/files'; import TOML from '@iarna/toml'; import { type WitnessMap } from '@noir-lang/acvm_js'; diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 8bca32c0d266..702794cfe114 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -45,7 +45,7 @@ import { AbortError } from '@aztec/foundation/error'; import { createLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { type Tuple } from '@aztec/foundation/serialize'; -import { pushTestData } from '@aztec/foundation/testing'; +import { pushTestData } from '@aztec/foundation/testing/files'; import { elapsed } from '@aztec/foundation/timer'; import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; 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 302962054db1..51d1944f3726 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 @@ -4,7 +4,8 @@ import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js'; import { makeTuple } from '@aztec/foundation/array'; import { times } from '@aztec/foundation/collection'; import { type Logger, createLogger } from '@aztec/foundation/log'; -import { getTestData, isGenerateTestDataEnabled, writeTestData } from '@aztec/foundation/testing'; +import { isGenerateTestDataEnabled } from '@aztec/foundation/testing'; +import { getTestData, writeTestData } from '@aztec/foundation/testing/files'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 784e239f55fd..15c4e4c16fe4 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -30,7 +30,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto'; import { createLogger } from '@aztec/foundation/log'; import { assertLength } from '@aztec/foundation/serialize'; -import { pushTestData } from '@aztec/foundation/testing'; +import { pushTestData } from '@aztec/foundation/testing/files'; import { Timer } from '@aztec/foundation/timer'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/client'; import { From 10600accbb572a40aa68b10c3176f66d45db5630 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 09:47:24 +0000 Subject: [PATCH 51/57] more stripping --- boxes/boxes/vite/package.json | 10 +- boxes/boxes/vite/vite.config.ts | 6 +- boxes/yarn.lock | 126 +++++------------- .../contract_class_registration.test.ts | 9 +- .../foundation/src/testing/files/index.ts | 33 +---- yarn-project/foundation/src/testing/index.ts | 6 +- .../foundation/src/testing/test_data.ts | 36 +++++ .../src/execution/client.ts | 64 +++++---- .../src/orchestrator/orchestrator.ts | 2 +- .../src/test/bb_prover_full_rollup.test.ts | 4 +- .../pxe/src/kernel_prover/kernel_prover.ts | 16 ++- 11 files changed, 137 insertions(+), 175 deletions(-) create mode 100644 yarn-project/foundation/src/testing/test_data.ts diff --git a/boxes/boxes/vite/package.json b/boxes/boxes/vite/package.json index e071e5d473f3..5d127569aef3 100644 --- a/boxes/boxes/vite/package.json +++ b/boxes/boxes/vite/package.json @@ -32,18 +32,16 @@ "@eslint/js": "^9.13.0", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", - "@vitejs/plugin-react-swc": "^3.5.0", + "@vitejs/plugin-react-swc": "^3.7.2", "eslint": "^9.13.0", - "eslint-plugin-react-hooks": "^5.0.0", - "eslint-plugin-react-refresh": "^0.4.14", + "eslint-plugin-react-hooks": "^5.1.0", + "eslint-plugin-react-refresh": "^0.4.16", "globals": "^15.11.0", - "memfs": "^4.14.0", - "node-stdlib-browser": "^1.3.0", "typescript": "~5.6.2", "typescript-eslint": "^8.11.0", "vite": "^6.0.3", - "vite-plugin-externalize-deps": "^0.8.0", "vite-plugin-node-polyfills": "^0.22.0", + "vite-plugin-strip-block": "^1.0.1", "vite-plugin-top-level-await": "^1.4.4" } } diff --git a/boxes/boxes/vite/vite.config.ts b/boxes/boxes/vite/vite.config.ts index 7920e3e5cd9d..3f5640d92b17 100644 --- a/boxes/boxes/vite/vite.config.ts +++ b/boxes/boxes/vite/vite.config.ts @@ -2,6 +2,7 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { PolyfillOptions, nodePolyfills } from "vite-plugin-node-polyfills"; import topLevelAwait from "vite-plugin-top-level-await"; +import stripBlockPlugin from "vite-plugin-strip-block"; // Unfortunate, but needed due to https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/81 // Suspected to be because of the yarn workspace setup, but not sure @@ -30,10 +31,9 @@ export default defineConfig({ }, }, plugins: [ + stripBlockPlugin({ start: "testing-only:start", end: "testing-only:end" }), react(), - nodePolyfillsFix({ - exclude: ["fs"], - }), + nodePolyfillsFix(), topLevelAwait(), ], optimizeDeps: { diff --git a/boxes/yarn.lock b/boxes/yarn.lock index cf51ab3099c1..69d40a3842c6 100644 --- a/boxes/yarn.lock +++ b/boxes/yarn.lock @@ -1448,38 +1448,6 @@ __metadata: languageName: node linkType: hard -"@jsonjoy.com/base64@npm:^1.1.1": - version: 1.1.2 - resolution: "@jsonjoy.com/base64@npm:1.1.2" - peerDependencies: - tslib: 2 - checksum: 88717945f66dc89bf58ce75624c99fe6a5c9a0c8614e26d03e406447b28abff80c69fb37dabe5aafef1862cf315071ae66e5c85f6018b437d95f8d13d235e6eb - languageName: node - linkType: hard - -"@jsonjoy.com/json-pack@npm:^1.0.3": - version: 1.1.0 - resolution: "@jsonjoy.com/json-pack@npm:1.1.0" - dependencies: - "@jsonjoy.com/base64": "npm:^1.1.1" - "@jsonjoy.com/util": "npm:^1.1.2" - hyperdyperid: "npm:^1.2.0" - thingies: "npm:^1.20.0" - peerDependencies: - tslib: 2 - checksum: cdf5cb567a7f2e703d4966a3e3a5f7f7b54ee40a2102aa0ede5c79bcf2060c8465d82f39de8583db4cf1d8415bec8e57dfb1156ef663567b846cdea45813d9d1 - languageName: node - linkType: hard - -"@jsonjoy.com/util@npm:^1.1.2, @jsonjoy.com/util@npm:^1.3.0": - version: 1.5.0 - resolution: "@jsonjoy.com/util@npm:1.5.0" - peerDependencies: - tslib: 2 - checksum: 0065ae12c4108d8aede01a479c8d2b5a39bce99e9a449d235befc753f57e8385d9c1115720529f26597840b7398d512898155423d9859fd638319fb0c827365d - languageName: node - linkType: hard - "@leichtgewicht/ip-codec@npm:^2.0.1": version: 2.0.5 resolution: "@leichtgewicht/ip-codec@npm:2.0.5" @@ -2830,14 +2798,14 @@ __metadata: languageName: node linkType: hard -"@vitejs/plugin-react-swc@npm:^3.5.0": - version: 3.7.1 - resolution: "@vitejs/plugin-react-swc@npm:3.7.1" +"@vitejs/plugin-react-swc@npm:^3.7.2": + version: 3.7.2 + resolution: "@vitejs/plugin-react-swc@npm:3.7.2" dependencies: "@swc/core": "npm:^1.7.26" peerDependencies: - vite: ^4 || ^5 - checksum: 2d613e69c0d0b809c94df80ca2b0caf39c50f0b98aa1f8599fd086bc37dac1449898eb6572000e1c133313137cac93440c4cb0861e05820c78bd2c07a52e64a8 + vite: ^4 || ^5 || ^6 + checksum: 9b9a5e0540791ba96a9fe4e8b8146ab274edcc730315535705f20126d6dfaffe72ae474bac9904ce841976e1959b6ecffd047bb2f0b7abf4d85aae7fbfdd00ab languageName: node linkType: hard @@ -5587,16 +5555,25 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-hooks@npm:^5.0.0": - version: 5.0.0 - resolution: "eslint-plugin-react-hooks@npm:5.0.0" +"eslint-plugin-react-hooks@npm:^5.1.0": + version: 5.1.0 + resolution: "eslint-plugin-react-hooks@npm:5.1.0" peerDependencies: eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 - checksum: bcb74b421f32e4203a7100405b57aab85526be4461e5a1da01bc537969a30012d2ee209a2c2a6cac543833a27188ce1e6ad71e4628d0bb4a2e5365cad86c5002 + checksum: 37ef76e1d916d46ab8e93a596078efcf2162e2c653614437e0c54e31d02a5dadabec22802fab717effe257aeb4bdc20c2a710666a89ab1cf07e01e614dde75d8 + languageName: node + linkType: hard + +"eslint-plugin-react-refresh@npm:^0.4.16": + version: 0.4.16 + resolution: "eslint-plugin-react-refresh@npm:0.4.16" + peerDependencies: + eslint: ">=8.40" + checksum: 0628d54b6cc6773a89252e2a7c82c7905a00dc8dc99a6ae2885a64f3b45bd3012a40cf9791ee24aa5dcf75665d8c8be4699845bbbf205cd0ef652702701a7865 languageName: node linkType: hard -"eslint-plugin-react-refresh@npm:^0.4.14, eslint-plugin-react-refresh@npm:^0.4.3": +"eslint-plugin-react-refresh@npm:^0.4.3": version: 0.4.14 resolution: "eslint-plugin-react-refresh@npm:0.4.14" peerDependencies: @@ -6917,13 +6894,6 @@ __metadata: languageName: node linkType: hard -"hyperdyperid@npm:^1.2.0": - version: 1.2.0 - resolution: "hyperdyperid@npm:1.2.0" - checksum: 885ba3177c7181d315a856ee9c0005ff8eb5dcb1ce9e9d61be70987895d934d84686c37c981cceeb53216d4c9c15c1cc25f1804e84cc6a74a16993c5d7fd0893 - languageName: node - linkType: hard - "iconv-lite@npm:0.4.24": version: 0.4.24 resolution: "iconv-lite@npm:0.4.24" @@ -8431,18 +8401,6 @@ __metadata: languageName: node linkType: hard -"memfs@npm:^4.14.0": - version: 4.14.0 - resolution: "memfs@npm:4.14.0" - dependencies: - "@jsonjoy.com/json-pack": "npm:^1.0.3" - "@jsonjoy.com/util": "npm:^1.3.0" - tree-dump: "npm:^1.0.1" - tslib: "npm:^2.0.0" - checksum: d1de2e4b3c269f5b5f27b63f60bb8ea9ae5800843776e0bed4548f2957dcd55237ac5eab3a5ffe0d561a6be53e42c055a7bc79efc1613563b14e14c287ef3b0a - languageName: node - linkType: hard - "merge-descriptors@npm:1.0.3": version: 1.0.3 resolution: "merge-descriptors@npm:1.0.3" @@ -8898,7 +8856,7 @@ __metadata: languageName: node linkType: hard -"node-stdlib-browser@npm:^1.2.0, node-stdlib-browser@npm:^1.3.0": +"node-stdlib-browser@npm:^1.2.0": version: 1.3.0 resolution: "node-stdlib-browser@npm:1.3.0" dependencies: @@ -11206,15 +11164,6 @@ __metadata: languageName: node linkType: hard -"thingies@npm:^1.20.0": - version: 1.21.0 - resolution: "thingies@npm:1.21.0" - peerDependencies: - tslib: ^2 - checksum: 7570ee855aecb73185a672ecf3eb1c287a6512bf5476449388433b2d4debcf78100bc8bfd439b0edd38d2bc3bfb8341de5ce85b8557dec66d0f27b962c9a8bc1 - languageName: node - linkType: hard - "thread-stream@npm:^2.6.0": version: 2.7.0 resolution: "thread-stream@npm:2.7.0" @@ -11349,15 +11298,6 @@ __metadata: languageName: node linkType: hard -"tree-dump@npm:^1.0.1": - version: 1.0.2 - resolution: "tree-dump@npm:1.0.2" - peerDependencies: - tslib: 2 - checksum: d1d180764e9c691b28332dbd74226c6b6af361dfb1e134bb11e60e17cb11c215894adee50ffc578da5dcf546006693947be8b6665eb1269b56e2f534926f1c1f - languageName: node - linkType: hard - "ts-api-utils@npm:^1.0.1, ts-api-utils@npm:^1.3.0": version: 1.4.0 resolution: "ts-api-utils@npm:1.4.0" @@ -11813,15 +11753,6 @@ __metadata: languageName: node linkType: hard -"vite-plugin-externalize-deps@npm:^0.8.0": - version: 0.8.0 - resolution: "vite-plugin-externalize-deps@npm:0.8.0" - peerDependencies: - vite: ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 - checksum: 0ed0d2a85f96e6470b700c1a598de9e3b189b186f7a3d05e4e945c0381bb2717dce5a40de5d6b485ec8e30f31ff33b17d56d487f618395d7b55ad7ef74d35ca3 - languageName: node - linkType: hard - "vite-plugin-node-polyfills@npm:^0.22.0": version: 0.22.0 resolution: "vite-plugin-node-polyfills@npm:0.22.0" @@ -11834,6 +11765,13 @@ __metadata: languageName: node linkType: hard +"vite-plugin-strip-block@npm:^1.0.1": + version: 1.0.1 + resolution: "vite-plugin-strip-block@npm:1.0.1" + checksum: 4302a035fbcaff8c5cfdffeedfd7c61d9b7198aeac1123cdadc00770db1d4828e7b780ce3a84106c786e771eb47c60289a694283c95702819f6f909c21bc3bbe + languageName: node + linkType: hard + "vite-plugin-top-level-await@npm:^1.4.4": version: 1.4.4 resolution: "vite-plugin-top-level-await@npm:1.4.4" @@ -11958,22 +11896,20 @@ __metadata: "@noir-lang/noirc_abi": "link:../../../noir/packages/noirc_abi" "@types/react": "npm:^18.3.12" "@types/react-dom": "npm:^18.3.1" - "@vitejs/plugin-react-swc": "npm:^3.5.0" + "@vitejs/plugin-react-swc": "npm:^3.7.2" buffer: "npm:^6.0.3" eslint: "npm:^9.13.0" - eslint-plugin-react-hooks: "npm:^5.0.0" - eslint-plugin-react-refresh: "npm:^0.4.14" + eslint-plugin-react-hooks: "npm:^5.1.0" + eslint-plugin-react-refresh: "npm:^0.4.16" globals: "npm:^15.11.0" - memfs: "npm:^4.14.0" - node-stdlib-browser: "npm:^1.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" react-toastify: "npm:^10.0.6" typescript: "npm:~5.6.2" typescript-eslint: "npm:^8.11.0" vite: "npm:^6.0.3" - vite-plugin-externalize-deps: "npm:^0.8.0" vite-plugin-node-polyfills: "npm:^0.22.0" + vite-plugin-strip-block: "npm:^1.0.1" vite-plugin-top-level-await: "npm:^1.4.4" languageName: unknown linkType: soft diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts index 040d421464b4..53a55d1eb872 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts @@ -106,7 +106,7 @@ describe('e2e_deploy_contract contract class registration', () => { const tx = await (await broadcastPrivateFunction(wallet, artifact, selector)).send().wait(); const logs = await pxe.getContractClassLogs({ txHash: tx.txHash }); const logData = logs.logs[0].log.data; - writeTestData('yarn-project/protocol-contracts/fixtures/PrivateFunctionBroadcastedEventData.hex', logData); + await writeTestData('yarn-project/protocol-contracts/fixtures/PrivateFunctionBroadcastedEventData.hex', logData); const fetchedClass = await aztecNode.getContractClass(contractClass.id); const fetchedFunction = fetchedClass!.privateFunctions[0]!; @@ -120,7 +120,10 @@ describe('e2e_deploy_contract contract class registration', () => { const tx = await (await broadcastUnconstrainedFunction(wallet, artifact, selector)).send().wait(); const logs = await pxe.getContractClassLogs({ txHash: tx.txHash }); const logData = logs.logs[0].log.data; - writeTestData('yarn-project/protocol-contracts/fixtures/UnconstrainedFunctionBroadcastedEventData.hex', logData); + await writeTestData( + 'yarn-project/protocol-contracts/fixtures/UnconstrainedFunctionBroadcastedEventData.hex', + logData, + ); const fetchedClass = await aztecNode.getContractClass(contractClass.id); const fetchedFunction = fetchedClass!.unconstrainedFunctions[0]!; @@ -181,7 +184,7 @@ describe('e2e_deploy_contract contract class registration', () => { const block = await aztecNode.getBlockNumber(); const logs = await aztecNode.getPrivateLogs(block, 1); expect(logs.length).toBe(1); - writeTestData( + await writeTestData( 'yarn-project/protocol-contracts/fixtures/ContractInstanceDeployedEventData.hex', logs[0].toBuffer(), ); diff --git a/yarn-project/foundation/src/testing/files/index.ts b/yarn-project/foundation/src/testing/files/index.ts index 87a99ab51d49..a45f40f82032 100644 --- a/yarn-project/foundation/src/testing/files/index.ts +++ b/yarn-project/foundation/src/testing/files/index.ts @@ -3,9 +3,8 @@ import { dirname, join, resolve } from 'path'; import { createConsoleLogger } from '../../log/console.js'; import { fileURLToPath } from '../../url/index.js'; -import { isGenerateTestDataEnabled } from '../index.js'; +import { isGenerateTestDataEnabled } from '../test_data.js'; -const testData: { [key: string]: unknown[] } = {}; let generateProtocolCircuitTestData = false; /** @@ -16,36 +15,6 @@ export function switchGenerateProtocolCircuitTestData() { generateProtocolCircuitTestData = !generateProtocolCircuitTestData; } -/** Pushes test data with the given name, only if test data generation is enabled. */ -export function pushTestData(itemName: string, data: T) { - if (!isGenerateTestDataEnabled()) { - return; - } - - if (typeof expect === 'undefined') { - return; - } - - const testName = expect.getState().currentTestName; - const fullItemName = `${testName} ${itemName}`; - - if (!testData[fullItemName]) { - testData[fullItemName] = []; - } - testData[fullItemName].push(data); -} - -/** Returns all instances of pushed test data with the given name, or empty if test data generation is not enabled. */ -export function getTestData(itemName: string): unknown[] { - if (!isGenerateTestDataEnabled()) { - return []; - } - - const testName = expect.getState().currentTestName; - const fullItemName = `${testName} ${itemName}`; - return testData[fullItemName]; -} - /** Writes the contents specified to the target file if test data generation is enabled. */ export function writeTestData(targetFileFromRepoRoot: string, contents: string | Buffer) { if (!isGenerateTestDataEnabled()) { diff --git a/yarn-project/foundation/src/testing/index.ts b/yarn-project/foundation/src/testing/index.ts index 484c260d7412..5d2ecb37c2bb 100644 --- a/yarn-project/foundation/src/testing/index.ts +++ b/yarn-project/foundation/src/testing/index.ts @@ -1,7 +1,3 @@ export * from './snapshot_serializer.js'; export * from './port_allocator.js'; - -/** Returns whether test data generation is enabled */ -export function isGenerateTestDataEnabled() { - return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined'; -} +export * from './test_data.js'; diff --git a/yarn-project/foundation/src/testing/test_data.ts b/yarn-project/foundation/src/testing/test_data.ts new file mode 100644 index 000000000000..7e16b0e6be5a --- /dev/null +++ b/yarn-project/foundation/src/testing/test_data.ts @@ -0,0 +1,36 @@ +const testData: { [key: string]: unknown[] } = {}; + +/** Returns whether test data generation is enabled */ +export function isGenerateTestDataEnabled() { + return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined'; +} + +/** Pushes test data with the given name, only if test data generation is enabled. */ +export function pushTestData(itemName: string, data: T) { + if (!isGenerateTestDataEnabled()) { + return; + } + + if (typeof expect === 'undefined') { + return; + } + + const testName = expect.getState().currentTestName; + const fullItemName = `${testName} ${itemName}`; + + if (!testData[fullItemName]) { + testData[fullItemName] = []; + } + testData[fullItemName].push(data); +} + +/** Returns all instances of pushed test data with the given name, or empty if test data generation is not enabled. */ +export function getTestData(itemName: string): unknown[] { + if (!isGenerateTestDataEnabled()) { + return []; + } + + const testName = expect.getState().currentTestName; + const fullItemName = `${testName} ${itemName}`; + return testData[fullItemName]; +} diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts index d9ec4f0ff775..900b1c3ad938 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts @@ -8,9 +8,7 @@ import { type PrivateKernelTailCircuitPrivateInputs, type PrivateKernelTailCircuitPublicInputs, } from '@aztec/circuits.js'; -import { isGenerateTestDataEnabled } from '@aztec/foundation/testing'; -import TOML from '@iarna/toml'; import { type CompiledCircuit, type InputMap, Noir, type WitnessMap } from '@noir-lang/noir_js'; import { type Abi, abiDecode, abiEncode } from '@noir-lang/noirc_abi'; @@ -45,6 +43,14 @@ import { getPrivateKernelResetArtifactName } from '../utils/private_kernel_reset /* eslint-disable camelcase */ +// Utility function with self-contained dynamic imports, so it can be stripped from browser bundles +// This is only ever used in testing, so it's safe to do so +async function updateProtocolCircuitSampleInputs(circuitName: string, inputs: any) { + const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); + const TOML = await import('@iarna/toml'); + updateProtocolCircuitSampleInputs(circuitName, TOML.stringify(inputs)); +} + /** * Executes the init private kernel. * @param privateKernelInitCircuitPrivateInputs - The private inputs to the initial private kernel. @@ -63,11 +69,12 @@ export async function executeInit( privateKernelInitCircuitPrivateInputs.privateCall.publicInputs, ), }; - // Gated to avoid importing the testing files module in the browser - if (isGenerateTestDataEnabled()) { - const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); - updateProtocolCircuitSampleInputs('private-kernel-init', TOML.stringify(inputs)); - } + + // Allow bundlers to remove this code + /* testing-only:start */ + await updateProtocolCircuitSampleInputs('private-kernel-init', inputs); + /* testing-only:end */ + const returnType = await executePrivateKernelInitWithACVM( inputs.tx_request, inputs.vk_tree_root, @@ -100,11 +107,12 @@ export async function executeInner( privateKernelInnerCircuitPrivateInputs.privateCall.publicInputs, ), }; - // Gated to avoid importing the testing files module in the browser - if (isGenerateTestDataEnabled()) { - const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); - updateProtocolCircuitSampleInputs('private-kernel-inner', TOML.stringify(inputs)); - } + + // Allow bundlers to remove this code + /* testing-only:start */ + await updateProtocolCircuitSampleInputs('private-kernel-inner', inputs); + /* testing-only:end */ + const returnType = await executePrivateKernelInnerWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -170,11 +178,12 @@ export async function executeTail( previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), }; - // Gated to avoid importing the testing files module in the browser - if (isGenerateTestDataEnabled()) { - const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); - updateProtocolCircuitSampleInputs('private-kernel-tail', TOML.stringify(inputs)); - } + + // Allow bundlers to remove this code + /* testing-only:start */ + await updateProtocolCircuitSampleInputs('private-kernel-tail', inputs); + /* testing-only:end */ + const returnType = await executePrivateKernelTailWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -197,11 +206,12 @@ export async function executeTailForPublic( previous_kernel: mapPrivateKernelDataToNoir(privateInputs.previousKernel), previous_kernel_public_inputs: mapPrivateKernelCircuitPublicInputsToNoir(privateInputs.previousKernel.publicInputs), }; - // Gated to avoid importing the testing files module in the browser - if (isGenerateTestDataEnabled()) { - const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); - updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', TOML.stringify(inputs)); - } + + // Allow bundlers to remove this code + /* testing-only:start */ + await updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', inputs); + /* testing-only:end */ + const returnType = await executePrivateKernelTailToPublicWithACVM( inputs.previous_kernel, inputs.previous_kernel_public_inputs, @@ -418,9 +428,9 @@ async function updateResetCircuitSampleInputs( ), hints: mapPrivateKernelResetHintsToNoir(privateKernelResetCircuitPrivateInputs.hints), }; - // Gated to avoid importing the testing files module in the browser - if (isGenerateTestDataEnabled()) { - const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); - updateProtocolCircuitSampleInputs('private-kernel-reset', TOML.stringify(inputs)); - } + + // Allow bundlers to remove this code + /* testing-only:start */ + await updateProtocolCircuitSampleInputs('private-kernel-reset', inputs); + /* testing-only:end */ } diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index 702794cfe114..8bca32c0d266 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -45,7 +45,7 @@ import { AbortError } from '@aztec/foundation/error'; import { createLogger } from '@aztec/foundation/log'; import { promiseWithResolvers } from '@aztec/foundation/promise'; import { type Tuple } from '@aztec/foundation/serialize'; -import { pushTestData } from '@aztec/foundation/testing/files'; +import { pushTestData } from '@aztec/foundation/testing'; import { elapsed } from '@aztec/foundation/timer'; import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { protocolContractTreeRoot } from '@aztec/protocol-contracts'; 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 51d1944f3726..0f888894c200 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 @@ -4,8 +4,8 @@ import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js'; import { makeTuple } from '@aztec/foundation/array'; import { times } from '@aztec/foundation/collection'; import { type Logger, createLogger } from '@aztec/foundation/log'; -import { isGenerateTestDataEnabled } from '@aztec/foundation/testing'; -import { getTestData, writeTestData } from '@aztec/foundation/testing/files'; +import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing'; +import { writeTestData } from '@aztec/foundation/testing/files'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types'; import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 15c4e4c16fe4..8ec4759e3cf8 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -30,7 +30,7 @@ import { makeTuple } from '@aztec/foundation/array'; import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto'; import { createLogger } from '@aztec/foundation/log'; import { assertLength } from '@aztec/foundation/serialize'; -import { pushTestData } from '@aztec/foundation/testing/files'; +import { pushTestData } from '@aztec/foundation/testing'; import { Timer } from '@aztec/foundation/timer'; import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/client'; import { @@ -200,7 +200,12 @@ export class KernelProver { privateCallData, isPrivateOnlyTx, ); + + // Allow bundlers to remove this code + /* testing-only:start */ pushTestData('private-kernel-inputs-init', proofInput); + /* testing-only:end */ + output = await this.proofCreator.simulateProofInit(proofInput); acirs.push(output.bytecode); @@ -217,7 +222,12 @@ export class KernelProver { assertLength(previousVkMembershipWitness.siblingPath, VK_TREE_HEIGHT), ); const proofInput = new PrivateKernelInnerCircuitPrivateInputs(previousKernelData, privateCallData); + + // Allow bundlers to remove this code + /* testing-only:start */ pushTestData('private-kernel-inputs-inner', proofInput); + /* testing-only:end */ + output = await this.proofCreator.simulateProofInner(proofInput); acirs.push(output.bytecode); @@ -269,7 +279,11 @@ export class KernelProver { const privateInputs = new PrivateKernelTailCircuitPrivateInputs(previousKernelData); + // Allow bundlers to remove this code + /* testing-only:start */ pushTestData('private-kernel-inputs-ordering', privateInputs); + /* testing-only:end */ + const tailOutput = await this.proofCreator.simulateProofTail(privateInputs); if (tailOutput.publicInputs.forPublic) { const privateLogs = privateInputs.previousKernel.publicInputs.end.privateLogs; From c2f88ac4e90dd56e9c5154891065ab4be704c7fd Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 11:54:59 +0000 Subject: [PATCH 52/57] more fat-trimming --- boxes/boxes/vite/vite.config.ts | 6 +-- yarn-project/circuits.js/package.json | 3 +- yarn-project/circuits.js/tsconfig.json | 3 +- .../src/fixtures/snapshot_manager.ts | 6 +-- yarn-project/end-to-end/src/fixtures/utils.ts | 4 +- yarn-project/ethereum/src/eth_cheat_codes.ts | 28 ---------- .../src/test/eth_cheat_codes_with_state.ts | 51 +++++++++++++++++++ yarn-project/ethereum/src/test/index.ts | 1 + .../noir-protocol-circuits-types/package.json | 3 +- .../src/execution/client.ts | 22 ++++---- .../tsconfig.json | 3 +- yarn-project/protocol-contracts/package.json | 3 +- yarn-project/protocol-contracts/tsconfig.json | 3 +- .../pxe/src/kernel_prover/kernel_prover.ts | 9 ---- 14 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts diff --git a/boxes/boxes/vite/vite.config.ts b/boxes/boxes/vite/vite.config.ts index 3f5640d92b17..ef09a7d9e674 100644 --- a/boxes/boxes/vite/vite.config.ts +++ b/boxes/boxes/vite/vite.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { PolyfillOptions, nodePolyfills } from "vite-plugin-node-polyfills"; import topLevelAwait from "vite-plugin-top-level-await"; -import stripBlockPlugin from "vite-plugin-strip-block"; +import stripBlock from "vite-plugin-strip-block"; // Unfortunate, but needed due to https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/81 // Suspected to be because of the yarn workspace setup, but not sure @@ -31,9 +31,9 @@ export default defineConfig({ }, }, plugins: [ - stripBlockPlugin({ start: "testing-only:start", end: "testing-only:end" }), + stripBlock({ start: "testing-only-start", end: "testing-only-end" }), react(), - nodePolyfillsFix(), + nodePolyfillsFix({ include: ["buffer", "process", "path"] }), topLevelAwait(), ], optimizeDeps: { diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index 66d4573bdb0c..3006bd8fc8bb 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -59,7 +59,8 @@ "files": [ "dest", "src", - "!*.test.*" + "!*.test.*", + "!src/scripts/*" ], "types": "./dest/index.d.ts", "engines": { diff --git a/yarn-project/circuits.js/tsconfig.json b/yarn-project/circuits.js/tsconfig.json index fb67f66550e8..f37d6d829a88 100644 --- a/yarn-project/circuits.js/tsconfig.json +++ b/yarn-project/circuits.js/tsconfig.json @@ -16,5 +16,6 @@ "path": "../types" } ], - "include": ["src"] + "include": ["src"], + "exclude": ["src/scripts"] } diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 5581397e60cd..bcf6d96a20b9 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -16,7 +16,7 @@ import { } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { type DeployL1ContractsArgs, createL1Clients, getL1ContractsConfigEnvVars, l1Artifacts } from '@aztec/ethereum'; -import { startAnvil } from '@aztec/ethereum/test'; +import { EthCheatCodesWithState, startAnvil } from '@aztec/ethereum/test'; import { asyncMap } from '@aztec/foundation/async-map'; import { createLogger } from '@aztec/foundation/log'; import { resolver, reviver } from '@aztec/foundation/serialize'; @@ -178,7 +178,7 @@ class SnapshotManager implements ISnapshotManager { await restore(snapshotData, context); // Save the snapshot data. - const ethCheatCodes = new EthCheatCodes(context.aztecNodeConfig.l1RpcUrl); + const ethCheatCodes = new EthCheatCodesWithState(context.aztecNodeConfig.l1RpcUrl); const anvilStateFile = `${this.livePath}/anvil.dat`; await ethCheatCodes.dumpChainState(anvilStateFile); writeFileSync(`${this.livePath}/${name}.json`, JSON.stringify(snapshotData || {}, resolver)); @@ -411,7 +411,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise { - const res = await this.rpcCall('hardhat_dumpState', []); - if (res.error) { - throw new Error(`Error dumping state: ${res.error.message}`); - } - const jsonContent = JSON.stringify(res.result); - fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8'); - this.logger.verbose(`Dumped state to ${fileName}`); - } - - /** - * Loads the chain state from a file. - * @param fileName - The file name to load state from - */ - public async loadChainState(fileName: string): Promise { - const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8')); - const res = await this.rpcCall('hardhat_loadState', [data]); - if (res.error) { - throw new Error(`Error loading state: ${res.error.message}`); - } - this.logger.verbose(`Loaded state from ${fileName}`); - } - /** * Load the value at a storage slot of a contract address on eth * @param contract - The contract address diff --git a/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts new file mode 100644 index 000000000000..8a234f2a1631 --- /dev/null +++ b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts @@ -0,0 +1,51 @@ +import { createLogger } from '@aztec/foundation/log'; + +import fs from 'fs'; + +import { EthCheatCodes } from '../eth_cheat_codes.js'; + +/** + * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file. + * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser. + */ +export class EthCheatCodesWithState extends EthCheatCodes { + constructor( + /** + * The RPC URL to use for interacting with the chain + */ + public override rpcUrl: string, + /** + * The logger to use for the eth cheatcodes + */ + public override logger = createLogger('ethereum:cheat_codes'), + ) { + super(rpcUrl, logger); + } + + /** + * Dumps the current chain state to a file. + * @param fileName - The file name to dump state into + */ + public async dumpChainState(fileName: string): Promise { + const res = await this.rpcCall('hardhat_dumpState', []); + if (res.error) { + throw new Error(`Error dumping state: ${res.error.message}`); + } + const jsonContent = JSON.stringify(res.result); + fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8'); + this.logger.verbose(`Dumped state to ${fileName}`); + } + + /** + * Loads the chain state from a file. + * @param fileName - The file name to load state from + */ + public async loadChainState(fileName: string): Promise { + const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8')); + const res = await this.rpcCall('hardhat_loadState', [data]); + if (res.error) { + throw new Error(`Error loading state: ${res.error.message}`); + } + this.logger.verbose(`Loaded state from ${fileName}`); + } +} diff --git a/yarn-project/ethereum/src/test/index.ts b/yarn-project/ethereum/src/test/index.ts index e6e7d745ad64..cdb11e525890 100644 --- a/yarn-project/ethereum/src/test/index.ts +++ b/yarn-project/ethereum/src/test/index.ts @@ -1,2 +1,3 @@ export * from './start_anvil.js'; export * from './tx_delayer.js'; +export * from './eth_cheat_codes_with_state.js'; diff --git a/yarn-project/noir-protocol-circuits-types/package.json b/yarn-project/noir-protocol-circuits-types/package.json index aa936af00f96..3a16ad9a69e1 100644 --- a/yarn-project/noir-protocol-circuits-types/package.json +++ b/yarn-project/noir-protocol-circuits-types/package.json @@ -93,7 +93,8 @@ "dest", "src", "!*.test.*", - "artifacts" + "artifacts", + "!src/scripts/*" ], "types": "./dest/index.d.ts", "engines": { diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts index 900b1c3ad938..cfa768c17424 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/client.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/client.ts @@ -45,11 +45,13 @@ import { getPrivateKernelResetArtifactName } from '../utils/private_kernel_reset // Utility function with self-contained dynamic imports, so it can be stripped from browser bundles // This is only ever used in testing, so it's safe to do so +/* testing-only-start */ async function updateProtocolCircuitSampleInputs(circuitName: string, inputs: any) { const { updateProtocolCircuitSampleInputs } = await import('@aztec/foundation/testing/files'); const TOML = await import('@iarna/toml'); updateProtocolCircuitSampleInputs(circuitName, TOML.stringify(inputs)); } +/* testing-only-end */ /** * Executes the init private kernel. @@ -71,9 +73,9 @@ export async function executeInit( }; // Allow bundlers to remove this code - /* testing-only:start */ + /* testing-only-start */ await updateProtocolCircuitSampleInputs('private-kernel-init', inputs); - /* testing-only:end */ + /* testing-only-end */ const returnType = await executePrivateKernelInitWithACVM( inputs.tx_request, @@ -109,9 +111,9 @@ export async function executeInner( }; // Allow bundlers to remove this code - /* testing-only:start */ + /* testing-only-start */ await updateProtocolCircuitSampleInputs('private-kernel-inner', inputs); - /* testing-only:end */ + /* testing-only-end */ const returnType = await executePrivateKernelInnerWithACVM( inputs.previous_kernel, @@ -180,9 +182,9 @@ export async function executeTail( }; // Allow bundlers to remove this code - /* testing-only:start */ + /* testing-only-start */ await updateProtocolCircuitSampleInputs('private-kernel-tail', inputs); - /* testing-only:end */ + /* testing-only-end */ const returnType = await executePrivateKernelTailWithACVM( inputs.previous_kernel, @@ -208,9 +210,9 @@ export async function executeTailForPublic( }; // Allow bundlers to remove this code - /* testing-only:start */ + /* testing-only-start */ await updateProtocolCircuitSampleInputs('private-kernel-tail-to-public', inputs); - /* testing-only:end */ + /* testing-only-end */ const returnType = await executePrivateKernelTailToPublicWithACVM( inputs.previous_kernel, @@ -430,7 +432,7 @@ async function updateResetCircuitSampleInputs( }; // Allow bundlers to remove this code - /* testing-only:start */ + /* testing-only-start */ await updateProtocolCircuitSampleInputs('private-kernel-reset', inputs); - /* testing-only:end */ + /* testing-only-end */ } diff --git a/yarn-project/noir-protocol-circuits-types/tsconfig.json b/yarn-project/noir-protocol-circuits-types/tsconfig.json index 4544ee09c62c..99be5d0c203a 100644 --- a/yarn-project/noir-protocol-circuits-types/tsconfig.json +++ b/yarn-project/noir-protocol-circuits-types/tsconfig.json @@ -23,5 +23,6 @@ "path": "../merkle-tree" } ], - "include": ["src", "artifacts/*.d.json.ts", "artifacts/**/*.d.json.ts"] + "include": ["src", "artifacts/*.d.json.ts", "artifacts/**/*.d.json.ts"], + "exclude": ["src/scripts"] } diff --git a/yarn-project/protocol-contracts/package.json b/yarn-project/protocol-contracts/package.json index d12d967b95e5..a83311f5f46e 100644 --- a/yarn-project/protocol-contracts/package.json +++ b/yarn-project/protocol-contracts/package.json @@ -94,7 +94,8 @@ "dest", "src", "!*.test.*", - "artifacts" + "artifacts", + "!src/scripts/*" ], "engines": { "node": ">=18" diff --git a/yarn-project/protocol-contracts/tsconfig.json b/yarn-project/protocol-contracts/tsconfig.json index 96ab4e32557f..db070c81cb12 100644 --- a/yarn-project/protocol-contracts/tsconfig.json +++ b/yarn-project/protocol-contracts/tsconfig.json @@ -16,5 +16,6 @@ "path": "../types" } ], - "include": ["src", "artifacts/*.d.json.ts"] + "include": ["src", "artifacts/*.d.json.ts"], + "exclude": ["src/scripts"] } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index 8ec4759e3cf8..a43676a6bbe3 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -201,10 +201,7 @@ export class KernelProver { isPrivateOnlyTx, ); - // Allow bundlers to remove this code - /* testing-only:start */ pushTestData('private-kernel-inputs-init', proofInput); - /* testing-only:end */ output = await this.proofCreator.simulateProofInit(proofInput); @@ -223,10 +220,7 @@ export class KernelProver { ); const proofInput = new PrivateKernelInnerCircuitPrivateInputs(previousKernelData, privateCallData); - // Allow bundlers to remove this code - /* testing-only:start */ pushTestData('private-kernel-inputs-inner', proofInput); - /* testing-only:end */ output = await this.proofCreator.simulateProofInner(proofInput); @@ -279,10 +273,7 @@ export class KernelProver { const privateInputs = new PrivateKernelTailCircuitPrivateInputs(previousKernelData); - // Allow bundlers to remove this code - /* testing-only:start */ pushTestData('private-kernel-inputs-ordering', privateInputs); - /* testing-only:end */ const tailOutput = await this.proofCreator.simulateProofTail(privateInputs); if (tailOutput.publicInputs.forPublic) { From f2c881ff9df8ea5ab3a9ad5cb94a3d1cbb0671b0 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 12:06:20 +0000 Subject: [PATCH 53/57] removed await --- .../contract_class_registration.test.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts index 53a55d1eb872..040d421464b4 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts @@ -106,7 +106,7 @@ describe('e2e_deploy_contract contract class registration', () => { const tx = await (await broadcastPrivateFunction(wallet, artifact, selector)).send().wait(); const logs = await pxe.getContractClassLogs({ txHash: tx.txHash }); const logData = logs.logs[0].log.data; - await writeTestData('yarn-project/protocol-contracts/fixtures/PrivateFunctionBroadcastedEventData.hex', logData); + writeTestData('yarn-project/protocol-contracts/fixtures/PrivateFunctionBroadcastedEventData.hex', logData); const fetchedClass = await aztecNode.getContractClass(contractClass.id); const fetchedFunction = fetchedClass!.privateFunctions[0]!; @@ -120,10 +120,7 @@ describe('e2e_deploy_contract contract class registration', () => { const tx = await (await broadcastUnconstrainedFunction(wallet, artifact, selector)).send().wait(); const logs = await pxe.getContractClassLogs({ txHash: tx.txHash }); const logData = logs.logs[0].log.data; - await writeTestData( - 'yarn-project/protocol-contracts/fixtures/UnconstrainedFunctionBroadcastedEventData.hex', - logData, - ); + writeTestData('yarn-project/protocol-contracts/fixtures/UnconstrainedFunctionBroadcastedEventData.hex', logData); const fetchedClass = await aztecNode.getContractClass(contractClass.id); const fetchedFunction = fetchedClass!.unconstrainedFunctions[0]!; @@ -184,7 +181,7 @@ describe('e2e_deploy_contract contract class registration', () => { const block = await aztecNode.getBlockNumber(); const logs = await aztecNode.getPrivateLogs(block, 1); expect(logs.length).toBe(1); - await writeTestData( + writeTestData( 'yarn-project/protocol-contracts/fixtures/ContractInstanceDeployedEventData.hex', logs[0].toBuffer(), ); From ea4249ed8141577ebe5d9d5b16f0d29b055b4897 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 12:23:26 +0000 Subject: [PATCH 54/57] fixes --- .../src/prover/bb_private_kernel_prover.ts | 2 +- yarn-project/foundation/.eslintrc.cjs | 2 +- .../src/native_client_ivc_integration.test.ts | 2 +- .../src/artifacts/server.ts | 2 +- .../src/execution/server.ts | 31 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) 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 3059f826a571..2d70f5726ebb 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 @@ -1,7 +1,7 @@ import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types'; import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; import { - ClientIvcProof, + type ClientIvcProof, type PrivateKernelCircuitPublicInputs, type PrivateKernelInitCircuitPrivateInputs, type PrivateKernelInnerCircuitPrivateInputs, diff --git a/yarn-project/foundation/.eslintrc.cjs b/yarn-project/foundation/.eslintrc.cjs index ec3bcb348b7b..6388fe800a82 100644 --- a/yarn-project/foundation/.eslintrc.cjs +++ b/yarn-project/foundation/.eslintrc.cjs @@ -78,5 +78,5 @@ module.exports = { // this unfortunately doesn't block `fit` and `fdescribe` 'no-only-tests/no-only-tests': ['error'], }, - ignorePatterns: ['node_modules', 'dest*', 'dist', '*.js', '.eslintrc.cjs', '.eslintrc.*.cjs'], + ignorePatterns: ['node_modules', 'dest*', 'dist', '*.js', 'scripts*', '.eslintrc.cjs', '.eslintrc.*.cjs'], }; diff --git a/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts b/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts index 4d59ce3011e7..076e4518b757 100644 --- a/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts +++ b/yarn-project/ivc-integration/src/native_client_ivc_integration.test.ts @@ -5,7 +5,7 @@ import { verifyClientIvcProof, writeToOutputDirectory, } from '@aztec/bb-prover'; -import { ClientIvcProof } from '@aztec/circuits.js'; +import { type ClientIvcProof } from '@aztec/circuits.js'; import { createLogger } from '@aztec/foundation/log'; import { jest } from '@jest/globals'; diff --git a/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts index 46b2001d1339..4952f994f199 100644 --- a/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/artifacts/server.ts @@ -13,9 +13,9 @@ import PublicBaseRollupSimulatedJson from '../../artifacts/rollup_base_public_si import BlockMergeRollupJson from '../../artifacts/rollup_block_merge.json' assert { type: 'json' }; import BlockRootRollupJson from '../../artifacts/rollup_block_root.json' assert { type: 'json' }; import EmptyBlockRootRollupJson from '../../artifacts/rollup_block_root_empty.json' assert { type: 'json' }; +import BlockRootRollupSimulatedJson from '../../artifacts/rollup_block_root_simulated.json' assert { type: 'json' }; import MergeRollupJson from '../../artifacts/rollup_merge.json' assert { type: 'json' }; import RootRollupJson from '../../artifacts/rollup_root.json' assert { type: 'json' }; -import BlockRootRollupSimulatedJson from '../artifacts/rollup_block_root_simulated.json' assert { type: 'json' }; // These are all circuits that should generate proofs with the `recursive` flag. export type ServerProtocolArtifact = diff --git a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts index 3e136c01e06e..5396265eea0c 100644 --- a/yarn-project/noir-protocol-circuits-types/src/execution/server.ts +++ b/yarn-project/noir-protocol-circuits-types/src/execution/server.ts @@ -135,6 +135,20 @@ export function convertBlockRootRollupInputsToWitnessMap(inputs: BlockRootRollup return initialWitnessMap; } +/** + * Converts the inputs of the simulated block root rollup circuit into a witness map. + * @param inputs - The block root rollup inputs. + * @returns The witness map + */ +export function convertSimulatedBlockRootRollupInputsToWitnessMap(inputs: BlockRootRollupInputs): WitnessMap { + const mapped = mapBlockRootRollupInputsToNoir(inputs); + updateProtocolCircuitSampleInputs('rollup-block-root', TOML.stringify({ inputs: mapped })); + const initialWitnessMap = abiEncode(SimulatedServerCircuitArtifacts.BlockRootRollupArtifact.abi, { + inputs: mapped as any, + }); + return initialWitnessMap; +} + /** * Converts the inputs of the empty block root rollup circuit into a witness map. * @param inputs - The empty block root rollup inputs. @@ -290,6 +304,23 @@ export function convertEmptyBlockRootRollupOutputsFromWitnessMap( return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); } +/** + * Converts the outputs of the simulated block root rollup circuit from a witness map. + * @param outputs - The block root rollup outputs as a witness map. + * @returns The public inputs. + */ +export function convertSimulatedBlockRootRollupOutputsFromWitnessMap( + outputs: WitnessMap, +): BlockRootOrBlockMergePublicInputs { + // Decode the witness map into two fields, the return values and the inputs + const decodedInputs: DecodedInputs = abiDecode(SimulatedServerCircuitArtifacts.BlockRootRollupArtifact.abi, outputs); + + // Cast the inputs as the return type + const returnType = decodedInputs.return_value as RollupBlockRootReturnType; + + return mapBlockRootOrBlockMergePublicInputsFromNoir(returnType); +} + /** * Converts the outputs of the block root rollup circuit from a witness map. * @param outputs - The block root rollup outputs as a witness map. From ac0679d97f10983caa5ca8e2480d69fbbb729be1 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 21:41:39 +0000 Subject: [PATCH 55/57] changed cheatcodes --- .../src/composed/integration_l1_publisher.test.ts | 7 ++++--- yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts | 5 +++-- .../end-to-end/src/fixtures/snapshot_manager.ts | 7 +++---- yarn-project/end-to-end/src/fixtures/utils.ts | 3 +-- yarn-project/end-to-end/src/spartan/4epochs.test.ts | 5 +++-- .../end-to-end/src/spartan/gating-passive.test.ts | 5 +++-- yarn-project/end-to-end/src/spartan/reorg.test.ts | 5 +++-- .../ethereum/src/test/eth_cheat_codes_with_state.ts | 13 ------------- yarn-project/noir-contracts.js/package.json | 2 +- 9 files changed, 21 insertions(+), 31 deletions(-) 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 d8030191abb0..f03231342b9d 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 @@ -1,6 +1,6 @@ import { type ArchiveSource } from '@aztec/archiver'; import { getConfigEnvVars } from '@aztec/aztec-node'; -import { AztecAddress, EthCheatCodes, Fr, GlobalVariables, type L2Block, createLogger } from '@aztec/aztec.js'; +import { AztecAddress, Fr, GlobalVariables, type L2Block, createLogger } from '@aztec/aztec.js'; // eslint-disable-next-line no-restricted-imports import { type L2Tips, @@ -20,6 +20,7 @@ import { } from '@aztec/circuits.js'; import { fr } from '@aztec/circuits.js/testing'; import { type L1ContractAddresses, createEthereumChain } from '@aztec/ethereum'; +import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { range } from '@aztec/foundation/array'; import { Blob } from '@aztec/foundation/blob'; import { sha256, sha256ToField } from '@aztec/foundation/crypto'; @@ -99,7 +100,7 @@ describe('L1Publisher integration', () => { let coinbase: EthAddress; let feeRecipient: AztecAddress; - let ethCheatCodes: EthCheatCodes; + let ethCheatCodes: EthCheatCodesWithState; let worldStateSynchronizer: ServerWorldStateSynchronizer; // To update the test data, run "export AZTEC_GENERATE_TEST_DATA=1" in shell and run the tests again @@ -125,7 +126,7 @@ describe('L1Publisher integration', () => { { assumeProvenThrough: undefined }, )); - ethCheatCodes = new EthCheatCodes(config.l1RpcUrl); + ethCheatCodes = new EthCheatCodesWithState(config.l1RpcUrl); rollupAddress = getAddress(l1ContractAddresses.rollupAddress.toString()); outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString()); diff --git a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts index c033061b6d92..2d55474e7c89 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/p2p_network.ts @@ -1,7 +1,8 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { type AztecNodeConfig, type AztecNodeService } from '@aztec/aztec-node'; import { type AccountWalletWithSecretKey } from '@aztec/aztec.js'; -import { EthCheatCodes, MINIMUM_STAKE, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; +import { MINIMUM_STAKE, getL1ContractsConfigEnvVars } from '@aztec/ethereum'; +import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { type Logger, createLogger } from '@aztec/foundation/log'; import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts'; import { SpamContract } from '@aztec/noir-contracts.js/Spam'; @@ -184,7 +185,7 @@ export class P2PNetworkTest { const slotsInEpoch = await rollup.read.EPOCH_DURATION(); const timestamp = await rollup.read.getTimestampForSlot([slotsInEpoch]); - const cheatCodes = new EthCheatCodes(aztecNodeConfig.l1RpcUrl); + const cheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrl); try { await cheatCodes.warp(Number(timestamp)); } catch (err) { diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index bcf6d96a20b9..582520916554 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -7,7 +7,6 @@ import { CheatCodes, type CompleteAddress, type DeployL1Contracts, - EthCheatCodes, Fr, GrumpkinScalar, type Logger, @@ -294,7 +293,7 @@ async function setupFromFresh( aztecNodeConfig.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; aztecNodeConfig.validatorPrivateKey = `0x${validatorPrivKey!.toString('hex')}`; - const ethCheatCodes = new EthCheatCodes(aztecNodeConfig.l1RpcUrl); + const ethCheatCodes = new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrl); if (opts.l1StartTime) { await ethCheatCodes.warp(opts.l1StartTime); @@ -333,7 +332,7 @@ async function setupFromFresh( } const watcher = new AnvilTestWatcher( - new EthCheatCodes(aztecNodeConfig.l1RpcUrl), + new EthCheatCodesWithState(aztecNodeConfig.l1RpcUrl), deployL1ContractsValues.l1ContractAddresses.rollupAddress, deployL1ContractsValues.publicClient, ); @@ -431,7 +430,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise { }); it('transfer tokens for 4 epochs', async () => { - const ethCheatCodes = new EthCheatCodes(ETHEREUM_HOST); + const ethCheatCodes = new EthCheatCodesWithState(ETHEREUM_HOST); // Get 4 epochs const rollupCheatCodes = new RollupCheatCodes( ethCheatCodes, diff --git a/yarn-project/end-to-end/src/spartan/gating-passive.test.ts b/yarn-project/end-to-end/src/spartan/gating-passive.test.ts index 99d5b06dc2c7..99c8394b5f10 100644 --- a/yarn-project/end-to-end/src/spartan/gating-passive.test.ts +++ b/yarn-project/end-to-end/src/spartan/gating-passive.test.ts @@ -1,4 +1,5 @@ -import { EthCheatCodes, createCompatibleClient, sleep } from '@aztec/aztec.js'; +import { createCompatibleClient, sleep } from '@aztec/aztec.js'; +import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { createLogger } from '@aztec/foundation/log'; import { expect, jest } from '@jest/globals'; @@ -84,7 +85,7 @@ describe('a test that passively observes the network in the presence of network }); const client = await createCompatibleClient(PXE_URL, debugLogger); - const ethCheatCodes = new EthCheatCodes(ETHEREUM_HOST); + const ethCheatCodes = new EthCheatCodesWithState(ETHEREUM_HOST); const rollupCheatCodes = new RollupCheatCodes( ethCheatCodes, await client.getNodeInfo().then(n => n.l1ContractAddresses), diff --git a/yarn-project/end-to-end/src/spartan/reorg.test.ts b/yarn-project/end-to-end/src/spartan/reorg.test.ts index f524503a4cf7..ad221bbade78 100644 --- a/yarn-project/end-to-end/src/spartan/reorg.test.ts +++ b/yarn-project/end-to-end/src/spartan/reorg.test.ts @@ -1,4 +1,5 @@ -import { EthCheatCodes, sleep } from '@aztec/aztec.js'; +import { sleep } from '@aztec/aztec.js'; +import { EthCheatCodesWithState } from '@aztec/ethereum/test'; import { createLogger } from '@aztec/foundation/log'; import { expect, jest } from '@jest/globals'; @@ -59,7 +60,7 @@ describe('reorg test', () => { hostPort: HOST_ETHEREUM_PORT, }); testWallets = await setupTestWalletsWithTokens(PXE_URL, MINT_AMOUNT, debugLogger); - const ethCheatCodes = new EthCheatCodes(ETHEREUM_HOST); + const ethCheatCodes = new EthCheatCodesWithState(ETHEREUM_HOST); const rollupCheatCodes = new RollupCheatCodes( ethCheatCodes, await testWallets.pxe.getNodeInfo().then(n => n.l1ContractAddresses), diff --git a/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts index 8a234f2a1631..1f0f98083879 100644 --- a/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts +++ b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts @@ -9,19 +9,6 @@ import { EthCheatCodes } from '../eth_cheat_codes.js'; * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser. */ export class EthCheatCodesWithState extends EthCheatCodes { - constructor( - /** - * The RPC URL to use for interacting with the chain - */ - public override rpcUrl: string, - /** - * The logger to use for the eth cheatcodes - */ - public override logger = createLogger('ethereum:cheat_codes'), - ) { - super(rpcUrl, logger); - } - /** * Dumps the current chain state to a file. * @param fileName - The file name to dump state into diff --git a/yarn-project/noir-contracts.js/package.json b/yarn-project/noir-contracts.js/package.json index 3eed2ad6ae23..c54eb0a59654 100644 --- a/yarn-project/noir-contracts.js/package.json +++ b/yarn-project/noir-contracts.js/package.json @@ -81,4 +81,4 @@ "engines": { "node": ">=18" } -} \ No newline at end of file +} From 35cef66555a81aee019fc714bcfe5c7852f599e1 Mon Sep 17 00:00:00 2001 From: thunkar Date: Mon, 16 Dec 2024 22:29:14 +0000 Subject: [PATCH 56/57] bad merge --- .../src/utils/foreign_call_handler.ts | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts b/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts index e01c95a83f9e..5cf86ef55ebf 100644 --- a/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts +++ b/yarn-project/noir-protocol-circuits-types/src/utils/foreign_call_handler.ts @@ -1,4 +1,5 @@ -import { Fr } from '@aztec/circuits.js'; +import { BlockBlobPublicInputs, Fr, SpongeBlob } from '@aztec/circuits.js'; +import { Blob } from '@aztec/foundation/blob'; import { applyStringFormatting, createLogger } from '@aztec/foundation/log'; import { type ForeignCallInput, type ForeignCallOutput } from '@noir-lang/acvm_js'; @@ -8,6 +9,10 @@ function fromACVMField(field: string): Fr { return Fr.fromBuffer(Buffer.from(field.slice(2), 'hex')); } +function toACVMField(field: Fr): string { + return `0x${field.toBuffer().toString('hex')}`; +} + export function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise { // ForeignCallInput is actually a string[], so the args are string[][]. const log = createLogger('noir-protocol-circuits:oracle'); @@ -18,6 +23,41 @@ export function foreignCallHandler(name: string, args: ForeignCallInput[]): Prom const msg: string = msgRaw.map(acvmField => String.fromCharCode(fromACVMField(acvmField).toNumber())).join(''); const fieldsFr: Fr[] = fields.map((field: string) => fromACVMField(field)); log.verbose('debug_log ' + applyStringFormatting(msg, fieldsFr)); + } else if (name === 'evaluateBlobs') { + // TODO(#10323): this was added to save simulation time (~1min in ACVM, ~3mins in wasm -> 500ms). + // The use of bignum adds a lot of unconstrained code which overloads limits when simulating. + // If/when simulation times of unconstrained are improved, remove this. + // Create and evaulate our blobs: + const paddedBlobsAsFr: Fr[] = args[0].map((field: string) => fromACVMField(field)); + const kzgCommitments = args[1].map((field: string) => fromACVMField(field)); + const spongeBlob = SpongeBlob.fromFields( + args + .slice(2) + .flat() + .map((field: string) => fromACVMField(field)), + ); + const blobsAsFr = paddedBlobsAsFr.slice(0, spongeBlob.expectedFields); + // NB: the above used to be: + // const blobsAsFr: Fr[] = args[0].map((field: string) => fromACVMField(field)).filter(field => !field.isZero()); + // ...but we now have private logs which have a fixed number of fields and may have 0 values. + // TODO(Miranda): trim 0 fields from private logs + const blobs = Blob.getBlobs(blobsAsFr); + const blobPublicInputs = BlockBlobPublicInputs.fromBlobs(blobs); + // Checks on injected values: + const hash = spongeBlob.squeeze(); + blobs.forEach((blob, i) => { + const injected = kzgCommitments.slice(2 * i, 2 * i + 2); + const calculated = blob.commitmentToFields(); + if (!calculated[0].equals(injected[0]) || !calculated[1].equals(injected[1])) { + throw new Error(`Blob commitment mismatch. Real: ${calculated}, Injected: ${injected}`); + } + if (!hash.equals(blob.fieldsHash)) { + throw new Error( + `Injected blob fields do not match rolled up fields. Real hash: ${hash}, Injected hash: ${blob.fieldsHash}`, + ); + } + }); + return Promise.resolve([blobPublicInputs.toFields().map(toACVMField)]); } else { throw Error(`unexpected oracle during execution: ${name}`); } From a1c2c819bdac1a448ba2bf2bfd8c8ab73b5f0339 Mon Sep 17 00:00:00 2001 From: thunkar Date: Tue, 17 Dec 2024 06:58:28 +0000 Subject: [PATCH 57/57] fmt --- yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts index 1f0f98083879..8f28d8961b08 100644 --- a/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts +++ b/yarn-project/ethereum/src/test/eth_cheat_codes_with_state.ts @@ -1,5 +1,3 @@ -import { createLogger } from '@aztec/foundation/log'; - import fs from 'fs'; import { EthCheatCodes } from '../eth_cheat_codes.js';