From 92411e321e5854d6b102a9856d600dde76d7a265 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 17:34:21 +0000 Subject: [PATCH 1/6] fixed serde of honk recursion flag for wasm --- barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 2 +- barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp | 2 +- 2 files changed, 2 insertions(+), 2 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 677220bb8569..78455796bae3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -14,7 +14,7 @@ #include WASM_EXPORT void acir_get_circuit_sizes( - uint8_t const* acir_vec, bool const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup) + uint8_t const* acir_vec, uint32_t const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup) { auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), *honk_recursion); 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 2ccaab46f423..61ebc81678cb 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -7,7 +7,7 @@ using namespace bb; WASM_EXPORT void acir_get_circuit_sizes(uint8_t const* constraint_system_buf, - bool const* honk_recursion, + uint32_t const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup); From 2277d6d63b79031261448d855bb501751c3f3ab9 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 5 Sep 2024 11:20:34 +0000 Subject: [PATCH 2/6] [skip ci] fix the honkRecursion bool serde --- barretenberg/ts/src/barretenberg_api/index.ts | 8 +++++++- barretenberg/ts/src/main.ts | 18 +++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index b55c29b5f9c6..e32500d9e895 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -332,7 +332,13 @@ export class BarretenbergApi { constraintSystemBuf: Uint8Array, honkRecursion: boolean, ): Promise<[number, number, number]> { - const inArgs = [constraintSystemBuf, honkRecursion].map(serializeBufferable); + console.log('type of honkRecursion: ', typeof honkRecursion); + console.log('in index.ts: honkRecursion: ', honkRecursion); + const honkRecursionUint32: number = honkRecursion ? 1 : 0; + console.log('in index.ts: honkRecursion: ', honkRecursion); + console.log('in index.ts: honkRecursionUint32: ', honkRecursionUint32); + + const inArgs = [constraintSystemBuf, honkRecursionUint32].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; const result = await this.wasm.callWasmExport( 'acir_get_circuit_sizes', diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 2fe41eeebf8c..3a278f53f825 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -56,9 +56,9 @@ async function init(bytecodePath: string, crsPath: string, subgroupSizeOverride const circuitSize = await getGates(bytecodePath, honkRecursion, api); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin const subgroupSize = Math.max(subgroupSizeOverride, Math.pow(2, Math.ceil(Math.log2(circuitSize)))); - if (subgroupSize > MAX_CIRCUIT_SIZE) { - throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`); - } + // if (subgroupSize > MAX_CIRCUIT_SIZE) { + // throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`); + // } debug(`circuit size: ${circuitSize}`); debug(`subgroup size: ${subgroupSize}`); @@ -67,7 +67,7 @@ async function init(bytecodePath: string, crsPath: string, subgroupSizeOverride const crs = await Crs.new(subgroupSize + 1, crsPath); // Important to init slab allocator as first thing, to ensure maximum memory efficiency. - await api.commonInitSlabAllocator(subgroupSize); + // await api.commonInitSlabAllocator(subgroupSize); // Load CRS into wasm global CRS state. // TODO: Make RawBuffer be default behavior, and have a specific Vector type for when wanting length prefixed. @@ -189,8 +189,8 @@ export async function prove(bytecodePath: string, witnessPath: string, crsPath: export async function gateCount(bytecodePath: string, honkRecursion: boolean) { const api = await Barretenberg.new({ threads: 1 }); try { - const numberOfGates = await getGates(bytecodePath, honkRecursion, api); - + const numberOfGates = await getGates(bytecodePath, honkRecursion as boolean, api); + console.log(numberOfGates); // Create an 8-byte buffer and write the number into it. // Writing number directly to stdout will result in a variable sized // input depending on the size. @@ -326,7 +326,7 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string) { } export async function proveUltraHonk(bytecodePath: string, witnessPath: string, crsPath: string, outputPath: string) { - const { api } = await init(bytecodePath, crsPath, -1, true); + const { api } = await init(bytecodePath, crsPath, -1, false); try { debug(`creating proof...`); const bytecode = getBytecode(bytecodePath); @@ -489,10 +489,10 @@ program .command('gates') .description('Print gate count to standard output.') .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/program.json') - .option('-hr, --honk-recursion ', 'Specify whether to use UltraHonk recursion', 'false') + .option('-hr, --honk-recursion', 'Specify whether to use UltraHonk recursion') .action(async ({ bytecodePath: bytecodePath, honkRecursion: honkRecursion }) => { handleGlobalOptions(); - await gateCount(bytecodePath, honkRecursion); + await gateCount(bytecodePath, !!honkRecursion); }); program From 389162a46cfa3a080d4a0f557c40597d2aded554 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 5 Sep 2024 14:18:06 +0000 Subject: [PATCH 3/6] change things back to bool [skip ci] --- .../cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 10 ++++++---- .../cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp | 2 +- barretenberg/ts/src/barretenberg_api/index.ts | 8 +------- barretenberg/ts/src/main.ts | 2 +- 4 files changed, 9 insertions(+), 13 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 78455796bae3..9b11e5c356e9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -14,7 +14,7 @@ #include WASM_EXPORT void acir_get_circuit_sizes( - uint8_t const* acir_vec, uint32_t const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup) + uint8_t const* acir_vec, bool const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup) { auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), *honk_recursion); @@ -91,9 +91,10 @@ WASM_EXPORT void acir_fold_and_verify_program_stack(uint8_t const* acir_vec, uin auto witness_stack = acir_format::witness_buf_to_witness_stack(from_buffer>(witness_vec)); ProgramStack program_stack{ constraint_systems, witness_stack }; + info("program stack size: ", constraint_systems.size()); ClientIVC ivc; - ivc.trace_structure = TraceStructure::SMALL_TEST; + ivc.trace_structure = TraceStructure::NONE; while (!program_stack.empty()) { auto stack_item = program_stack.back(); @@ -202,15 +203,16 @@ WASM_EXPORT void acir_serialize_verification_key_into_fields(in_ptr acir_compose WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, uint8_t** out) { auto constraint_system = - acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), /*honk_recursion=*/true); + acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), /*honk_recursion=*/false); auto witness = acir_format::witness_buf_to_witness_data(from_buffer>(witness_vec)); auto builder = - acir_format::create_circuit(constraint_system, 0, witness, /*honk_recursion=*/true); + acir_format::create_circuit(constraint_system, 0, witness, /*honk_recursion=*/false); UltraProver prover{ builder }; auto proof = prover.construct_proof(); *out = to_heap_buffer(to_buffer(proof)); + info("end of acir_prove_ultra_honk"); } WASM_EXPORT void acir_verify_ultra_honk(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) 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 61ebc81678cb..2ccaab46f423 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -7,7 +7,7 @@ using namespace bb; WASM_EXPORT void acir_get_circuit_sizes(uint8_t const* constraint_system_buf, - uint32_t const* honk_recursion, + bool const* honk_recursion, uint32_t* exact, uint32_t* total, uint32_t* subgroup); diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index e32500d9e895..b55c29b5f9c6 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -332,13 +332,7 @@ export class BarretenbergApi { constraintSystemBuf: Uint8Array, honkRecursion: boolean, ): Promise<[number, number, number]> { - console.log('type of honkRecursion: ', typeof honkRecursion); - console.log('in index.ts: honkRecursion: ', honkRecursion); - const honkRecursionUint32: number = honkRecursion ? 1 : 0; - console.log('in index.ts: honkRecursion: ', honkRecursion); - console.log('in index.ts: honkRecursionUint32: ', honkRecursionUint32); - - const inArgs = [constraintSystemBuf, honkRecursionUint32].map(serializeBufferable); + const inArgs = [constraintSystemBuf, honkRecursion].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; const result = await this.wasm.callWasmExport( 'acir_get_circuit_sizes', diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 3a278f53f825..0741bea1cb10 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -326,7 +326,7 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string) { } export async function proveUltraHonk(bytecodePath: string, witnessPath: string, crsPath: string, outputPath: string) { - const { api } = await init(bytecodePath, crsPath, -1, false); + const { api } = await init(bytecodePath, crsPath, -1, /* honkRecursion= */ true); try { debug(`creating proof...`); const bytecode = getBytecode(bytecodePath); From a5f65fad162823772b2b356dacc3ab7b87117bec Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 5 Sep 2024 14:32:14 +0000 Subject: [PATCH 4/6] clean up --- .../cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 8 +++----- barretenberg/ts/src/main.ts | 6 +++--- 2 files changed, 6 insertions(+), 8 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 9b11e5c356e9..677220bb8569 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -91,10 +91,9 @@ WASM_EXPORT void acir_fold_and_verify_program_stack(uint8_t const* acir_vec, uin auto witness_stack = acir_format::witness_buf_to_witness_stack(from_buffer>(witness_vec)); ProgramStack program_stack{ constraint_systems, witness_stack }; - info("program stack size: ", constraint_systems.size()); ClientIVC ivc; - ivc.trace_structure = TraceStructure::NONE; + ivc.trace_structure = TraceStructure::SMALL_TEST; while (!program_stack.empty()) { auto stack_item = program_stack.back(); @@ -203,16 +202,15 @@ WASM_EXPORT void acir_serialize_verification_key_into_fields(in_ptr acir_compose WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, uint8_t** out) { auto constraint_system = - acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), /*honk_recursion=*/false); + acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec), /*honk_recursion=*/true); auto witness = acir_format::witness_buf_to_witness_data(from_buffer>(witness_vec)); auto builder = - acir_format::create_circuit(constraint_system, 0, witness, /*honk_recursion=*/false); + acir_format::create_circuit(constraint_system, 0, witness, /*honk_recursion=*/true); UltraProver prover{ builder }; auto proof = prover.construct_proof(); *out = to_heap_buffer(to_buffer(proof)); - info("end of acir_prove_ultra_honk"); } WASM_EXPORT void acir_verify_ultra_honk(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 0741bea1cb10..32f6d35fa5f4 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -189,8 +189,8 @@ export async function prove(bytecodePath: string, witnessPath: string, crsPath: export async function gateCount(bytecodePath: string, honkRecursion: boolean) { const api = await Barretenberg.new({ threads: 1 }); try { - const numberOfGates = await getGates(bytecodePath, honkRecursion as boolean, api); - console.log(numberOfGates); + const numberOfGates = await getGates(bytecodePath, honkRecursion, api); + debug(`number of gates: : ${numberOfGates}`); // Create an 8-byte buffer and write the number into it. // Writing number directly to stdout will result in a variable sized // input depending on the size. @@ -492,7 +492,7 @@ program .option('-hr, --honk-recursion', 'Specify whether to use UltraHonk recursion') .action(async ({ bytecodePath: bytecodePath, honkRecursion: honkRecursion }) => { handleGlobalOptions(); - await gateCount(bytecodePath, !!honkRecursion); + await gateCount(bytecodePath, honkRecursion); }); program From 7dc7a2d92dd844db598945e48199a1e912762810 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 5 Sep 2024 14:34:04 +0000 Subject: [PATCH 5/6] put the commented out stuff back --- barretenberg/ts/src/main.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 32f6d35fa5f4..8ece0e2cdf86 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -56,9 +56,9 @@ async function init(bytecodePath: string, crsPath: string, subgroupSizeOverride const circuitSize = await getGates(bytecodePath, honkRecursion, api); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): remove subgroupSizeOverride hack for goblin const subgroupSize = Math.max(subgroupSizeOverride, Math.pow(2, Math.ceil(Math.log2(circuitSize)))); - // if (subgroupSize > MAX_CIRCUIT_SIZE) { - // throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`); - // } + if (subgroupSize > MAX_CIRCUIT_SIZE) { + throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`); + } debug(`circuit size: ${circuitSize}`); debug(`subgroup size: ${subgroupSize}`); @@ -67,7 +67,7 @@ async function init(bytecodePath: string, crsPath: string, subgroupSizeOverride const crs = await Crs.new(subgroupSize + 1, crsPath); // Important to init slab allocator as first thing, to ensure maximum memory efficiency. - // await api.commonInitSlabAllocator(subgroupSize); + await api.commonInitSlabAllocator(subgroupSize); // 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 3e385d7e79b4b34041f03c2d776c6c1cddc29e0d Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Thu, 5 Sep 2024 15:23:08 +0000 Subject: [PATCH 6/6] add default value for honkRecursion flag --- barretenberg/ts/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 8ece0e2cdf86..6b17d0434951 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -489,7 +489,7 @@ program .command('gates') .description('Print gate count to standard output.') .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/program.json') - .option('-hr, --honk-recursion', 'Specify whether to use UltraHonk recursion') + .option('-hr, --honk-recursion', 'Specify whether to use UltraHonk recursion', false) .action(async ({ bytecodePath: bytecodePath, honkRecursion: honkRecursion }) => { handleGlobalOptions(); await gateCount(bytecodePath, honkRecursion);