From 5f8e846f513247ab81f697a543c2a8a57598b491 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 20 Mar 2024 20:33:06 +0000 Subject: [PATCH 1/5] fix: revert refactoring fragile cbinds --- .../cpp/src/barretenberg/crypto/blake2s/c_bind.hpp | 6 ++++++ .../barretenberg/crypto/pedersen_commitment/c_bind.hpp | 8 +++++++- .../cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp | 5 ++++- .../cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp | 5 ++++- .../cpp/src/barretenberg/crypto/schnorr/c_bind.hpp | 9 +++++---- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp index c1e14c07a00e..cf124a5a6c9e 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp @@ -3,5 +3,11 @@ #include #include +extern "C" { + +using namespace bb; + WASM_EXPORT void blake2s(uint8_t const* data, out_buf32 r); + WASM_EXPORT void blake2s_to_field_(uint8_t const* data, fr::out_buf r); +} diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index d90b4234cab4..a4a37b9eac54 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -3,4 +3,10 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -WASM_EXPORT void pedersen_commit(bb::fr::vec_in_buf inputs_buffer, bb::grumpkin::g1::affine_element::out_buf output); \ No newline at end of file +extern "C" { + +using namespace bb; +using affine_element = grumpkin::g1::affine_element; + +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp index cb39f6a6a425..ecd51260201e 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp @@ -3,6 +3,9 @@ #include "barretenberg/common/wasm_export.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" +extern "C" { + WASM_EXPORT void pedersen_hash(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); WASM_EXPORT void pedersen_hashes(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); -WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output); \ No newline at end of file +WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp index 9915e0825766..c7dc58555485 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp @@ -3,5 +3,8 @@ #include "barretenberg/common/wasm_export.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" +extern "C" { + WASM_EXPORT void poseidon_hash(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); -WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); \ No newline at end of file +WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index 9e4991ff7c35..ba2049cc1e77 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -3,11 +3,11 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "multisig.hpp" -using namespace bb; -using namespace bb::crypto; +extern "C" { +using namespace bb; using affine_element = grumpkin::g1::affine_element; -using multisig = schnorr_multisig; +using multisig = crypto::schnorr_multisig; WASM_EXPORT void schnorr_compute_public_key(fr::in_buf private_key, affine_element::out_buf public_key_buf); WASM_EXPORT void schnorr_negate_public_key(affine_element::in_buf public_key_buffer, affine_element::out_buf output); @@ -42,4 +42,5 @@ WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message, fq::vec_in_buf round_two_buf, out_buf32 s, out_buf32 e, - bool* success); \ No newline at end of file + bool* success); +} From 7d42587a84f86de382d28dee6b46d99c7a28f85b Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 20 Mar 2024 20:35:46 +0000 Subject: [PATCH 2/5] bindings --- .../crypto/pedersen_hash/c_bind.hpp | 8 +- .../barretenberg/crypto/poseidon2/c_bind.hpp | 6 +- .../barretenberg/crypto/schnorr/c_bind.hpp | 2 +- barretenberg/exports.json | 8 +- barretenberg/ts/src/barretenberg_api/index.ts | 1094 ----------------- 5 files changed, 14 insertions(+), 1104 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp index ecd51260201e..e25cc79d1f32 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp @@ -5,7 +5,9 @@ extern "C" { -WASM_EXPORT void pedersen_hash(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); -WASM_EXPORT void pedersen_hashes(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); -WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output); +using namespace bb; + +WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output); +WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output); +WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, fr::out_buf output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp index c7dc58555485..e113b523dd18 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp @@ -5,6 +5,8 @@ extern "C" { -WASM_EXPORT void poseidon_hash(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); -WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); +using namespace bb; + +WASM_EXPORT void poseidon_hash(fr::vec_in_buf inputs_buffer, fr::out_buf output); +WASM_EXPORT void poseidon_hashes(fr::vec_in_buf inputs_buffer, fr::out_buf output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index ba2049cc1e77..51fd3f33a8db 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -7,7 +7,7 @@ extern "C" { using namespace bb; using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr_multisig; +using multisig = crypto::schnorr_multisig; WASM_EXPORT void schnorr_compute_public_key(fr::in_buf private_key, affine_element::out_buf public_key_buf); WASM_EXPORT void schnorr_negate_public_key(affine_element::in_buf public_key_buffer, affine_element::out_buf output); diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 13425b898cda..5f2c9256ea8c 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -80,13 +80,13 @@ "inArgs": [ { "name": "inputs_buffer", - "type": "fr::vec_in_buf" + "type": "bb::fr::vec_in_buf" } ], "outArgs": [ { "name": "output", - "type": "fr::out_buf" + "type": "bb::fr::out_buf" } ], "isAsync": false @@ -96,13 +96,13 @@ "inArgs": [ { "name": "inputs_buffer", - "type": "fr::vec_in_buf" + "type": "bb::fr::vec_in_buf" } ], "outArgs": [ { "name": "output", - "type": "fr::out_buf" + "type": "bb::fr::out_buf" } ], "isAsync": false diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index f74134d54675..e69de29bb2d1 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,1094 +0,0 @@ -// WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { BarretenbergWasmWorker, BarretenbergWasm } from '../barretenberg_wasm/index.js'; -import { - BufferDeserializer, - NumberDeserializer, - VectorDeserializer, - BoolDeserializer, - StringDeserializer, - serializeBufferable, - OutputType, -} from '../serialize/index.js'; -import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; - -export class BarretenbergApi { - constructor(protected wasm: BarretenbergWasmWorker) {} - - async pedersenCommit(inputsBuffer: Fr[]): Promise { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'pedersen_commit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { - const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'pedersen_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Promise { - const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'pedersen_hashes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Promise { - const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'pedersen_hash_buffer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async poseidonHash(inputsBuffer: Fr[]): Promise { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'poseidon_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async poseidonHashes(inputsBuffer: Fr[]): Promise { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'poseidon_hashes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async blake2s(data: Uint8Array): Promise { - const inArgs = [data].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32]; - const result = await this.wasm.callWasmExport( - 'blake2s', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async blake2sToField(data: Uint8Array): Promise { - const inArgs = [data].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'blake2s_to_field_', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async schnorrComputePublicKey(privateKey: Fr): Promise { - const inArgs = [privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'schnorr_compute_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async schnorrNegatePublicKey(publicKeyBuffer: Point): Promise { - const inArgs = [publicKeyBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'schnorr_negate_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { - const inArgs = [message, privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = await this.wasm.callWasmExport( - 'schnorr_construct_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { - const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_verify_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { - const inArgs = [privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer128]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { - const inArgs = [signerPubkeyBuf].map(serializeBufferable); - const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fq, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): Promise<[Fq, boolean]> { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( - serializeBufferable, - ); - const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fq[], - ): Promise<[Buffer32, Buffer32, boolean]> { - const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_combine_signatures', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { - const inArgs = [input, iv, key, length].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'aes_encrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { - const inArgs = [input, iv, key, length].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'aes_decrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): Promise { - const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'srs_init_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): Promise { - const inArgs = [pointsBuf, numPoints].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'srs_init_grumpkin_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async examplesSimpleCreateAndVerifyProof(): Promise { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'examples_simple_create_and_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async testThreads(threads: number, iterations: number): Promise { - const inArgs = [threads, iterations].map(serializeBufferable); - const outTypes: OutputType[] = [NumberDeserializer()]; - const result = await this.wasm.callWasmExport( - 'test_threads', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async commonInitSlabAllocator(circuitSize: number): Promise { - const inArgs = [circuitSize].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'common_init_slab_allocator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { - const inArgs = [constraintSystemBuf].map(serializeBufferable); - const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_circuit_sizes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - async acirNewAcirComposer(sizeHint: number): Promise { - const inArgs = [sizeHint].map(serializeBufferable); - const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport( - 'acir_new_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirNewGoblinAcirComposer(): Promise { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport( - 'acir_new_goblin_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirDeleteAcirComposer(acirComposerPtr: Ptr): Promise { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_delete_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_create_circuit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_init_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirCreateProof( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - ): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_create_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGoblinAccumulate( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - ): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_accumulate', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGoblinProve( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - ): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_prove', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_load_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirInitVerificationKey(acirComposerPtr: Ptr): Promise { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_init_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Promise { - const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_verify_accumulator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_verify', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [StringDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_solidity_verifier', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirSerializeProofIntoFields( - acirComposerPtr: Ptr, - proofBuf: Uint8Array, - numInnerPublicInputs: number, - ): Promise { - const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); - const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = await this.wasm.callWasmExport( - 'acir_serialize_proof_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = await this.wasm.callWasmExport( - 'acir_serialize_verification_key_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } -} -export class BarretenbergApiSync { - constructor(protected wasm: BarretenbergWasm) {} - - pedersenCommit(inputsBuffer: Fr[]): Point { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'pedersen_commit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - pedersenHash(inputsBuffer: Fr[], hashIndex: number): Fr { - const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'pedersen_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Fr { - const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'pedersen_hashes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Fr { - const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'pedersen_hash_buffer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - poseidonHash(inputsBuffer: Fr[]): Fr { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'poseidon_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - poseidonHashes(inputsBuffer: Fr[]): Fr { - const inArgs = [inputsBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'poseidon_hashes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - blake2s(data: Uint8Array): Buffer32 { - const inArgs = [data].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32]; - const result = this.wasm.callWasmExport( - 'blake2s', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - blake2sToField(data: Uint8Array): Fr { - const inArgs = [data].map(serializeBufferable); - const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'blake2s_to_field_', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - schnorrComputePublicKey(privateKey: Fr): Point { - const inArgs = [privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'schnorr_compute_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - schnorrNegatePublicKey(publicKeyBuffer: Point): Point { - const inArgs = [publicKeyBuffer].map(serializeBufferable); - const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'schnorr_negate_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] { - const inArgs = [message, privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = this.wasm.callWasmExport( - 'schnorr_construct_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean { - const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_verify_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Buffer128 { - const inArgs = [privateKey].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer128]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] { - const inArgs = [signerPubkeyBuf].map(serializeBufferable); - const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fq, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): [Fq, boolean] { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( - serializeBufferable, - ); - const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fq[], - ): [Buffer32, Buffer32, boolean] { - const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); - const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_combine_signatures', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { - const inArgs = [input, iv, key, length].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'aes_encrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { - const inArgs = [input, iv, key, length].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'aes_decrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): void { - const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'srs_init_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): void { - const inArgs = [pointsBuf, numPoints].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'srs_init_grumpkin_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - examplesSimpleCreateAndVerifyProof(): boolean { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'examples_simple_create_and_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - testThreads(threads: number, iterations: number): number { - const inArgs = [threads, iterations].map(serializeBufferable); - const outTypes: OutputType[] = [NumberDeserializer()]; - const result = this.wasm.callWasmExport( - 'test_threads', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - commonInitSlabAllocator(circuitSize: number): void { - const inArgs = [circuitSize].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'common_init_slab_allocator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] { - const inArgs = [constraintSystemBuf].map(serializeBufferable); - const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_circuit_sizes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } - - acirNewAcirComposer(sizeHint: number): Ptr { - const inArgs = [sizeHint].map(serializeBufferable); - const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport( - 'acir_new_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirNewGoblinAcirComposer(): Ptr { - const inArgs = [].map(serializeBufferable); - const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport( - 'acir_new_goblin_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirDeleteAcirComposer(acirComposerPtr: Ptr): void { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_delete_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void { - const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_create_circuit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void { - const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_init_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_create_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_accumulate', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_prove', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { - const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_load_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirInitVerificationKey(acirComposerPtr: Ptr): void { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_init_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return; - } - - acirGetVerificationKey(acirComposerPtr: Ptr): Uint8Array { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Uint8Array { - const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_verify_accumulator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_verify', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirGetSolidityVerifier(acirComposerPtr: Ptr): string { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [StringDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_solidity_verifier', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] { - const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); - const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = this.wasm.callWasmExport( - 'acir_serialize_proof_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - - acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] { - const inArgs = [acirComposerPtr].map(serializeBufferable); - const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = this.wasm.callWasmExport( - 'acir_serialize_verification_key_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out as any; - } -} From 5a3ff2f6be4762214afe7204a0b1678adffc9238 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 20 Mar 2024 20:37:39 +0000 Subject: [PATCH 3/5] fix: revert refactoring fragile cbinds --- barretenberg/exports.json | 8 +- barretenberg/ts/src/barretenberg_api/index.ts | 703 ++++++++++++++++++ 2 files changed, 707 insertions(+), 4 deletions(-) diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 5f2c9256ea8c..13425b898cda 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -80,13 +80,13 @@ "inArgs": [ { "name": "inputs_buffer", - "type": "bb::fr::vec_in_buf" + "type": "fr::vec_in_buf" } ], "outArgs": [ { "name": "output", - "type": "bb::fr::out_buf" + "type": "fr::out_buf" } ], "isAsync": false @@ -96,13 +96,13 @@ "inArgs": [ { "name": "inputs_buffer", - "type": "bb::fr::vec_in_buf" + "type": "fr::vec_in_buf" } ], "outArgs": [ { "name": "output", - "type": "bb::fr::out_buf" + "type": "fr::out_buf" } ], "isAsync": false diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index e69de29bb2d1..a4ac69d005e4 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -0,0 +1,703 @@ +// WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { BarretenbergWasmWorker, BarretenbergWasm } from '../barretenberg_wasm/index.js'; +import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer, serializeBufferable, OutputType } from '../serialize/index.js'; +import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; + + +export class BarretenbergApi { + constructor(protected wasm: BarretenbergWasmWorker) {} + + + async pedersenCommit(inputsBuffer: Fr[]): Promise { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = await this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { + const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Promise { + const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('pedersen_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Promise { + const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async poseidonHash(inputsBuffer: Fr[]): Promise { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('poseidon_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async poseidonHashes(inputsBuffer: Fr[]): Promise { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('poseidon_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async blake2s(data: Uint8Array): Promise { + const inArgs = [data].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32]; + const result = await this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async blake2sToField(data: Uint8Array): Promise { + const inArgs = [data].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = await this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async schnorrComputePublicKey(privateKey: Fr): Promise { + const inArgs = [privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = await this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async schnorrNegatePublicKey(publicKeyBuffer: Point): Promise { + const inArgs = [publicKeyBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = await this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { + const inArgs = [message, privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32, Buffer32]; + const result = await this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { + const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { + const inArgs = [privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer128]; + const result = await this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { + const inArgs = [signerPubkeyBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Point, BoolDeserializer()]; + const result = await this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer128, Buffer128]; + const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Fq, BoolDeserializer()]; + const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): Promise<[Buffer32, Buffer32, boolean]> { + const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; + const result = await this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { + const inArgs = [input, iv, key, length].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { + const inArgs = [input, iv, key, length].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): Promise { + const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): Promise { + const inArgs = [pointsBuf, numPoints].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async examplesSimpleCreateAndVerifyProof(): Promise { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async testThreads(threads: number, iterations: number): Promise { + const inArgs = [threads, iterations].map(serializeBufferable); + const outTypes: OutputType[] = [NumberDeserializer()]; + const result = await this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async commonInitSlabAllocator(circuitSize: number): Promise { + const inArgs = [circuitSize].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { + const inArgs = [constraintSystemBuf].map(serializeBufferable); + const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; + const result = await this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + async acirNewAcirComposer(sizeHint: number): Promise { + const inArgs = [sizeHint].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = await this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirNewGoblinAcirComposer(): Promise { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = await this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirDeleteAcirComposer(acirComposerPtr: Ptr): Promise { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('acir_goblin_prove', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirInitVerificationKey(acirComposerPtr: Ptr): Promise { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = await this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Promise { + const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport('acir_goblin_verify_accumulator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport('acir_goblin_verify', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [StringDeserializer()]; + const result = await this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { + const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); + const outTypes: OutputType[] = [VectorDeserializer(Fr)]; + const result = await this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; + const result = await this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } +} +export class BarretenbergApiSync { + constructor(protected wasm: BarretenbergWasm) {} + + + pedersenCommit(inputsBuffer: Fr[]): Point { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + pedersenHash(inputsBuffer: Fr[], hashIndex: number): Fr { + const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Fr { + const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('pedersen_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Fr { + const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + poseidonHash(inputsBuffer: Fr[]): Fr { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('poseidon_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + poseidonHashes(inputsBuffer: Fr[]): Fr { + const inArgs = [inputsBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('poseidon_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + blake2s(data: Uint8Array): Buffer32 { + const inArgs = [data].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32]; + const result = this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + blake2sToField(data: Uint8Array): Fr { + const inArgs = [data].map(serializeBufferable); + const outTypes: OutputType[] = [Fr]; + const result = this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + schnorrComputePublicKey(privateKey: Fr): Point { + const inArgs = [privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + schnorrNegatePublicKey(publicKeyBuffer: Point): Point { + const inArgs = [publicKeyBuffer].map(serializeBufferable); + const outTypes: OutputType[] = [Point]; + const result = this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] { + const inArgs = [message, privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32, Buffer32]; + const result = this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean { + const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Buffer128 { + const inArgs = [privateKey].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer128]; + const result = this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] { + const inArgs = [signerPubkeyBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Point, BoolDeserializer()]; + const result = this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer128, Buffer128]; + const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): [Fq, boolean] { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Fq, BoolDeserializer()]; + const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): [Buffer32, Buffer32, boolean] { + const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); + const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; + const result = this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { + const inArgs = [input, iv, key, length].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { + const inArgs = [input, iv, key, length].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): void { + const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): void { + const inArgs = [pointsBuf, numPoints].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + examplesSimpleCreateAndVerifyProof(): boolean { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + testThreads(threads: number, iterations: number): number { + const inArgs = [threads, iterations].map(serializeBufferable); + const outTypes: OutputType[] = [NumberDeserializer()]; + const result = this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + commonInitSlabAllocator(circuitSize: number): void { + const inArgs = [circuitSize].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] { + const inArgs = [constraintSystemBuf].map(serializeBufferable); + const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; + const result = this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } + + acirNewAcirComposer(sizeHint: number): Ptr { + const inArgs = [sizeHint].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirNewGoblinAcirComposer(): Ptr { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirDeleteAcirComposer(acirComposerPtr: Ptr): void { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void { + const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void { + const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('acir_goblin_prove', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { + const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirInitVerificationKey(acirComposerPtr: Ptr): void { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = []; + const result = this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return; + } + + acirGetVerificationKey(acirComposerPtr: Ptr): Uint8Array { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport('acir_goblin_verify_accumulator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport('acir_goblin_verify', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGetSolidityVerifier(acirComposerPtr: Ptr): string { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [StringDeserializer()]; + const result = this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] { + const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); + const outTypes: OutputType[] = [VectorDeserializer(Fr)]; + const result = this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] { + const inArgs = [acirComposerPtr].map(serializeBufferable); + const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; + const result = this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out as any; + } +} From 37c80725dafe1cf1b6220852041a587d7bb83dd2 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 20 Mar 2024 20:39:42 +0000 Subject: [PATCH 4/5] fix --- barretenberg/ts/src/barretenberg_api/index.ts | 591 +++++++++++++++--- 1 file changed, 491 insertions(+), 100 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index a4ac69d005e4..f74134d54675 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,18 +1,28 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergWasmWorker, BarretenbergWasm } from '../barretenberg_wasm/index.js'; -import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer, serializeBufferable, OutputType } from '../serialize/index.js'; +import { + BufferDeserializer, + NumberDeserializer, + VectorDeserializer, + BoolDeserializer, + StringDeserializer, + serializeBufferable, + OutputType, +} from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; - export class BarretenbergApi { constructor(protected wasm: BarretenbergWasmWorker) {} - async pedersenCommit(inputsBuffer: Fr[]): Promise { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_commit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -20,7 +30,11 @@ export class BarretenbergApi { async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -28,7 +42,11 @@ export class BarretenbergApi { async pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Promise { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('pedersen_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_hashes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -36,7 +54,11 @@ export class BarretenbergApi { async pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Promise { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_hash_buffer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -44,7 +66,11 @@ export class BarretenbergApi { async poseidonHash(inputsBuffer: Fr[]): Promise { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('poseidon_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'poseidon_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -52,7 +78,11 @@ export class BarretenbergApi { async poseidonHashes(inputsBuffer: Fr[]): Promise { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('poseidon_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'poseidon_hashes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -60,7 +90,11 @@ export class BarretenbergApi { async blake2s(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = await this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'blake2s', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -68,7 +102,11 @@ export class BarretenbergApi { async blake2sToField(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'blake2s_to_field_', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -76,7 +114,11 @@ export class BarretenbergApi { async schnorrComputePublicKey(privateKey: Fr): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_compute_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -84,7 +126,11 @@ export class BarretenbergApi { async schnorrNegatePublicKey(publicKeyBuffer: Point): Promise { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_negate_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -92,7 +138,11 @@ export class BarretenbergApi { async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = await this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_construct_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -100,7 +150,11 @@ export class BarretenbergApi { async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_verify_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -108,7 +162,11 @@ export class BarretenbergApi { async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = await this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -116,7 +174,11 @@ export class BarretenbergApi { async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -124,23 +186,48 @@ export class BarretenbergApi { async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + async schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fq, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): Promise<[Fq, boolean]> { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( + serializeBufferable, + ); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): Promise<[Buffer32, Buffer32, boolean]> { + async schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fq[], + ): Promise<[Buffer32, Buffer32, boolean]> { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_combine_signatures', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -148,7 +235,11 @@ export class BarretenbergApi { async aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'aes_encrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -156,7 +247,11 @@ export class BarretenbergApi { async aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'aes_decrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -164,7 +259,11 @@ export class BarretenbergApi { async srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): Promise { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'srs_init_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -172,7 +271,11 @@ export class BarretenbergApi { async srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): Promise { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'srs_init_grumpkin_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -180,7 +283,11 @@ export class BarretenbergApi { async examplesSimpleCreateAndVerifyProof(): Promise { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'examples_simple_create_and_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -188,7 +295,11 @@ export class BarretenbergApi { async testThreads(threads: number, iterations: number): Promise { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = await this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'test_threads', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -196,7 +307,11 @@ export class BarretenbergApi { async commonInitSlabAllocator(circuitSize: number): Promise { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'common_init_slab_allocator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -204,7 +319,11 @@ export class BarretenbergApi { async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_circuit_sizes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -212,7 +331,11 @@ export class BarretenbergApi { async acirNewAcirComposer(sizeHint: number): Promise { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_new_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -220,7 +343,11 @@ export class BarretenbergApi { async acirNewGoblinAcirComposer(): Promise { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_new_goblin_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -228,7 +355,11 @@ export class BarretenbergApi { async acirDeleteAcirComposer(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_delete_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -236,7 +367,11 @@ export class BarretenbergApi { async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_create_circuit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -244,31 +379,59 @@ export class BarretenbergApi { async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_init_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } - async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + async acirCreateProof( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_create_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + async acirGoblinAccumulate( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_goblin_accumulate', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + async acirGoblinProve( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_goblin_prove', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -276,7 +439,11 @@ export class BarretenbergApi { async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_load_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -284,7 +451,11 @@ export class BarretenbergApi { async acirInitVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_init_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -292,7 +463,11 @@ export class BarretenbergApi { async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -300,7 +475,11 @@ export class BarretenbergApi { async acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Promise { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -308,7 +487,11 @@ export class BarretenbergApi { async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -316,7 +499,11 @@ export class BarretenbergApi { async acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('acir_goblin_verify_accumulator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_goblin_verify_accumulator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -324,7 +511,11 @@ export class BarretenbergApi { async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('acir_goblin_verify', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_goblin_verify', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -332,15 +523,27 @@ export class BarretenbergApi { async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_solidity_verifier', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { + async acirSerializeProofIntoFields( + acirComposerPtr: Ptr, + proofBuf: Uint8Array, + numInnerPublicInputs: number, + ): Promise { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = await this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_serialize_proof_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -348,7 +551,11 @@ export class BarretenbergApi { async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = await this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_serialize_verification_key_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -356,11 +563,14 @@ export class BarretenbergApi { export class BarretenbergApiSync { constructor(protected wasm: BarretenbergWasm) {} - pedersenCommit(inputsBuffer: Fr[]): Point { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_commit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -368,7 +578,11 @@ export class BarretenbergApiSync { pedersenHash(inputsBuffer: Fr[], hashIndex: number): Fr { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -376,7 +590,11 @@ export class BarretenbergApiSync { pedersenHashes(inputsBuffer: Fr[], hashIndex: number): Fr { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('pedersen_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_hashes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -384,7 +602,11 @@ export class BarretenbergApiSync { pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Fr { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_hash_buffer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -392,7 +614,11 @@ export class BarretenbergApiSync { poseidonHash(inputsBuffer: Fr[]): Fr { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('poseidon_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'poseidon_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -400,7 +626,11 @@ export class BarretenbergApiSync { poseidonHashes(inputsBuffer: Fr[]): Fr { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('poseidon_hashes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'poseidon_hashes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -408,7 +638,11 @@ export class BarretenbergApiSync { blake2s(data: Uint8Array): Buffer32 { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'blake2s', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -416,7 +650,11 @@ export class BarretenbergApiSync { blake2sToField(data: Uint8Array): Fr { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'blake2s_to_field_', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -424,7 +662,11 @@ export class BarretenbergApiSync { schnorrComputePublicKey(privateKey: Fr): Point { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_compute_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -432,7 +674,11 @@ export class BarretenbergApiSync { schnorrNegatePublicKey(publicKeyBuffer: Point): Point { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_negate_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -440,7 +686,11 @@ export class BarretenbergApiSync { schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_construct_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -448,7 +698,11 @@ export class BarretenbergApiSync { schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_verify_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -456,7 +710,11 @@ export class BarretenbergApiSync { schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Buffer128 { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -464,7 +722,11 @@ export class BarretenbergApiSync { schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -472,23 +734,48 @@ export class BarretenbergApiSync { schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): [Fq, boolean] { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fq, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): [Fq, boolean] { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( + serializeBufferable, + ); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): [Buffer32, Buffer32, boolean] { + schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fq[], + ): [Buffer32, Buffer32, boolean] { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_combine_signatures', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -496,7 +783,11 @@ export class BarretenbergApiSync { aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'aes_encrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -504,7 +795,11 @@ export class BarretenbergApiSync { aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'aes_decrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -512,7 +807,11 @@ export class BarretenbergApiSync { srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): void { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'srs_init_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -520,7 +819,11 @@ export class BarretenbergApiSync { srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): void { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'srs_init_grumpkin_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -528,7 +831,11 @@ export class BarretenbergApiSync { examplesSimpleCreateAndVerifyProof(): boolean { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'examples_simple_create_and_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -536,7 +843,11 @@ export class BarretenbergApiSync { testThreads(threads: number, iterations: number): number { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'test_threads', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -544,7 +855,11 @@ export class BarretenbergApiSync { commonInitSlabAllocator(circuitSize: number): void { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'common_init_slab_allocator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -552,7 +867,11 @@ export class BarretenbergApiSync { acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_circuit_sizes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -560,7 +879,11 @@ export class BarretenbergApiSync { acirNewAcirComposer(sizeHint: number): Ptr { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_new_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -568,7 +891,11 @@ export class BarretenbergApiSync { acirNewGoblinAcirComposer(): Ptr { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_new_goblin_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -576,7 +903,11 @@ export class BarretenbergApiSync { acirDeleteAcirComposer(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_delete_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -584,7 +915,11 @@ export class BarretenbergApiSync { acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_create_circuit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -592,7 +927,11 @@ export class BarretenbergApiSync { acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_init_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -600,7 +939,11 @@ export class BarretenbergApiSync { acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_create_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -608,7 +951,11 @@ export class BarretenbergApiSync { acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_goblin_accumulate', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -616,7 +963,11 @@ export class BarretenbergApiSync { acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_goblin_prove', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -624,7 +975,11 @@ export class BarretenbergApiSync { acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_load_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -632,7 +987,11 @@ export class BarretenbergApiSync { acirInitVerificationKey(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_init_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -640,7 +999,11 @@ export class BarretenbergApiSync { acirGetVerificationKey(acirComposerPtr: Ptr): Uint8Array { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -648,7 +1011,11 @@ export class BarretenbergApiSync { acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -656,7 +1023,11 @@ export class BarretenbergApiSync { acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -664,7 +1035,11 @@ export class BarretenbergApiSync { acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('acir_goblin_verify_accumulator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_goblin_verify_accumulator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -672,7 +1047,11 @@ export class BarretenbergApiSync { acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('acir_goblin_verify', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_goblin_verify', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -680,7 +1059,11 @@ export class BarretenbergApiSync { acirGetSolidityVerifier(acirComposerPtr: Ptr): string { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_solidity_verifier', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -688,7 +1071,11 @@ export class BarretenbergApiSync { acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_serialize_proof_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -696,7 +1083,11 @@ export class BarretenbergApiSync { acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_serialize_verification_key_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } From 5677d9ec85add9a7a86122f974bade0a66a24730 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 20 Mar 2024 20:44:34 +0000 Subject: [PATCH 5/5] use ns crypto --- barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index 79cc4b44767e..b5fc5570e86a 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -3,6 +3,8 @@ #include "schnorr.hpp" using namespace bb; +using namespace bb::crypto; + using affine_element = grumpkin::g1::affine_element; using multisig = crypto::schnorr_multisig; using multisig_public_key = typename multisig::MultiSigPublicKey;