Skip to content

Commit

Permalink
feat: naive attempt to bind the honk solidity verifier function to th…
Browse files Browse the repository at this point in the history
…e ts interface (#9432)

Attempts to plumb the honk solidity verifier into the WASM output and
expose it in the ts API
  • Loading branch information
signorecello authored Nov 13, 2024
1 parent 3830e2a commit fc27eaf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
20 changes: 19 additions & 1 deletion barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "barretenberg/serialize/msgpack.hpp"
#include "barretenberg/srs/global_crs.hpp"
#include "honk_contract.hpp"
#include <cstdint>
#include <memory>

Expand Down Expand Up @@ -320,6 +321,23 @@ WASM_EXPORT void acir_write_vk_ultra_honk(uint8_t const* acir_vec, bool const* r
*out = to_heap_buffer(to_buffer(vk));
}

WASM_EXPORT void get_honk_solidity_verifier_vk(uint8_t const* acir_vec, bool const* recursive, uint8_t** out)
{
using DeciderProvingKey = DeciderProvingKey_<UltraFlavor>;
using VerificationKey = UltraFlavor::VerificationKey;

auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/true);
auto builder =
acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, *recursive, 0, {}, /*honk_recursion=*/true);

DeciderProvingKey proving_key(builder);
VerificationKey vk(proving_key.proving_key);

auto str = get_honk_solidity_verifier(&vk);
*out = to_heap_buffer(str);
}

WASM_EXPORT void acir_proof_as_fields_ultra_honk(uint8_t const* proof_buf, fr::vec_out_buf out)
{
auto proof = from_buffer<std::vector<bb::fr>>(from_buffer<std::vector<uint8_t>>(proof_buf));
Expand All @@ -342,4 +360,4 @@ WASM_EXPORT void acir_vk_as_fields_mega_honk(uint8_t const* vk_buf, fr::vec_out_
auto verification_key = std::make_shared<VerificationKey>(from_buffer<VerificationKey>(vk_buf));
std::vector<bb::fr> vkey_as_fields = verification_key->to_field_elements();
*out_vkey = to_heap_buffer(vkey_as_fields);
}
}
15 changes: 15 additions & 0 deletions barretenberg/ts/src/barretenberg/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,20 @@ export class UltraPlonkBackend {
return await this.api.acirVerifyProof(this.acirComposer, proof);
}

/** @description Returns the verification key */
async getVerificationKey(): Promise<Uint8Array> {
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirGetVerificationKey(this.acirComposer);
}

/** @description Returns a solidity verifier */
async getSolidityVerifier(): Promise<string> {
await this.instantiate();
await this.api.acirInitVerificationKey(this.acirComposer);
return await this.api.acirGetSolidityVerifier(this.acirComposer);
}

async destroy(): Promise<void> {
if (!this.api) {
return;
Expand Down Expand Up @@ -218,6 +226,13 @@ export class UltraHonkBackend {
return await this.api.acirWriteVkUltraHonk(this.acirUncompressedBytecode, this.circuitOptions.recursive);
}

/** @description Returns a solidity verifier */
async getSolidityVerifier(): Promise<string> {
await this.instantiate();
await this.api.acirWriteVkUltraHonk(this.acirUncompressedBytecode, this.circuitOptions.recursive);
return await this.api.getHonkSolidityVerifier(this.acirUncompressedBytecode, this.circuitOptions.recursive);
}

// TODO(https://github.com/noir-lang/noir/issues/5661): Update this to handle Honk recursive aggregation in the browser once it is ready in the backend itself
async generateRecursiveProofArtifacts(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
12 changes: 12 additions & 0 deletions barretenberg/ts/src/barretenberg_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,18 @@ export class BarretenbergApi {
return out[0];
}

async getHonkSolidityVerifier(acirVec: Uint8Array, recursive: boolean): Promise<string> {
const inArgs = [acirVec, recursive].map(serializeBufferable);
const outTypes: OutputType[] = [BufferDeserializer()];
const result = await this.wasm.callWasmExport(
'get_honk_solidity_verifier_vk',
inArgs,
outTypes.map(t => t.SIZE_IN_BYTES),
);
const out = result.map((r, i) => outTypes[i].fromBuffer(r));
return out[0];
}

async acirProofAsFieldsUltraHonk(proofBuf: Uint8Array): Promise<Fr[]> {
const inArgs = [proofBuf].map(serializeBufferable);
const outTypes: OutputType[] = [VectorDeserializer(Fr)];
Expand Down

0 comments on commit fc27eaf

Please sign in to comment.