Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: honkRecursion serde for cpp bindings #8387

Merged
merged 11 commits into from
Sep 5, 2024
8 changes: 5 additions & 3 deletions barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<uint8_t>>(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();
Expand Down Expand Up @@ -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<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/true);
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

auto builder =
acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, witness, /*honk_recursion=*/true);
acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, witness, /*honk_recursion=*/false);

UltraProver prover{ builder };
auto proof = prover.construct_proof();
*out = to_heap_buffer(to_buffer</*include_size=*/true>(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)
Expand Down
18 changes: 9 additions & 9 deletions barretenberg/ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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, /* honkRecursion= */ true);
try {
debug(`creating proof...`);
const bytecode = getBytecode(bytecodePath);
Expand Down Expand Up @@ -489,10 +489,10 @@ program
.command('gates')
.description('Print gate count to standard output.')
.option('-b, --bytecode-path <path>', 'Specify the bytecode path', './target/program.json')
.option('-hr, --honk-recursion <bool>', '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
Expand Down