From ed210a0272193aeef17847171104a44d5178cf7f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:24:42 +0000 Subject: [PATCH 1/6] remove plookup namespaced methods from cbind --- .../crypto/pedersen_commitment/c_bind.cpp | 32 +------------------ .../crypto/pedersen_commitment/c_bind.hpp | 12 ------- .../crypto/pedersen_commitment/c_bind_new.cpp | 26 --------------- .../crypto/pedersen_commitment/c_bind_new.hpp | 6 ---- 4 files changed, 1 insertion(+), 75 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index cbbe6a9f36e..f3b636a8e08 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -12,11 +12,6 @@ WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* r barretenberg::fr::serialize_to_buffer(r, result); } -WASM_EXPORT void pedersen_plookup_compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result) -{ - pedersen__compress_fields(left, right, result); -} - WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output) { std::vector to_compress; @@ -24,10 +19,7 @@ WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* outpu auto r = crypto::pedersen_hash::hash(to_compress); barretenberg::fr::serialize_to_buffer(r, output); } -WASM_EXPORT void pedersen_plookup_compress(uint8_t const* inputs_buffer, uint8_t* output) -{ - pedersen__compress(inputs_buffer, output); -} + WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index) { std::vector to_compress; @@ -38,12 +30,6 @@ WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer barretenberg::fr::serialize_to_buffer(r, output); } -WASM_EXPORT void pedersen_plookup_compress_with_hash_index(uint8_t const* inputs_buffer, - uint8_t* output, - uint32_t hash_index) -{ - pedersen__compress_with_hash_index(inputs_buffer, output, hash_index); -} WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) { std::vector to_compress; @@ -52,22 +38,6 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) serialize::write(output, pedersen_hash); } -WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output) -{ - pedersen__commit(inputs_buffer, output); -} - -WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer, - uint8_t* output, - uint32_t hash_index) -{ - std::vector to_compress; - read(inputs_buffer, to_compress); - crypto::GeneratorContext ctx; - ctx.offset = hash_index; - auto commitment = crypto::pedersen_commitment::commit_native(to_compress, ctx); - serialize::write(output, commitment); -} WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* 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 19b5de4404c..0ed52cc3fd8 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -1,5 +1,3 @@ -// TODO(@zac-wiliamson #2341 delete this file and rename c_bind_new to c_bind once we have migrated to new hash standard - #pragma once #include "barretenberg/common/mem.hpp" #include "barretenberg/common/serialize.hpp" @@ -9,20 +7,10 @@ WASM_EXPORT void pedersen__init(); WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result); -WASM_EXPORT void pedersen_plookup_compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result); WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output); -WASM_EXPORT void pedersen_plookup_compress(uint8_t const* inputs_buffer, uint8_t* output); WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index); -WASM_EXPORT void pedersen_plookup_compress_with_hash_index(uint8_t const* inputs_buffer, - uint8_t* output, - uint32_t hash_index); - WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output); -WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output); -WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer, - uint8_t* output, - uint32_t hash_index); WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r); diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp index cb9ea1ba944..3a2dd00fc28 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp @@ -17,10 +17,6 @@ WASM_EXPORT void pedersen___compress_fields(fr::in_buf left, fr::in_buf right, f barretenberg::fr::serialize_to_buffer(r, result); } -WASM_EXPORT void pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result) -{ - pedersen___compress_fields(left, right, result); -} WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output) { std::vector to_compress; @@ -29,11 +25,6 @@ WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf o barretenberg::fr::serialize_to_buffer(r, output); } -WASM_EXPORT void pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output) -{ - pedersen___compress(inputs_buffer, output); -} - WASM_EXPORT void pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output) @@ -55,23 +46,6 @@ WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf out serialize::write(output, pedersen_hash); } -WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output) -{ - pedersen___commit(inputs_buffer, output); -} - -WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - fr::out_buf output) -{ - std::vector to_compress; - read(inputs_buffer, to_compress); - const size_t generator_offset = ntohl(*hash_index); - crypto::GeneratorContext ctx; - ctx.offset = generator_offset; - auto commitment = crypto::pedersen_commitment::commit_native(to_compress, ctx); - serialize::write(output, commitment); -} WASM_EXPORT void pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r) { diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp index 559c8c51c57..7ab3f72e3e1 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp @@ -9,20 +9,14 @@ using namespace barretenberg; WASM_EXPORT void pedersen___init(); WASM_EXPORT void pedersen___compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result); -WASM_EXPORT void pedersen___plookup_compress_fields(fr::in_buf left, fr::in_buf right, fr::out_buf result); WASM_EXPORT void pedersen___compress(fr::vec_in_buf inputs_buffer, fr::out_buf output); -WASM_EXPORT void pedersen___plookup_compress(fr::vec_in_buf inputs_buffer, fr::out_buf output); WASM_EXPORT void pedersen___compress_with_hash_index(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output); WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf output); -WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output); -WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - fr::out_buf output); WASM_EXPORT void pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r); } \ No newline at end of file From 4fe1264db25e4c43a6843448d0c7373cb146b5db Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:25:03 +0000 Subject: [PATCH 2/6] regenerate exports --- barretenberg/exports.json | 84 ++------ barretenberg/ts/src/barretenberg_api/index.ts | 194 +++--------------- 2 files changed, 52 insertions(+), 226 deletions(-) diff --git a/barretenberg/exports.json b/barretenberg/exports.json index c786bb2cabd..876db3300ae 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -25,26 +25,6 @@ ], "isAsync": false }, - { - "functionName": "pedersen___plookup_compress_fields", - "inArgs": [ - { - "name": "left", - "type": "fr::in_buf" - }, - { - "name": "right", - "type": "fr::in_buf" - } - ], - "outArgs": [ - { - "name": "result", - "type": "fr::out_buf" - } - ], - "isAsync": false - }, { "functionName": "pedersen___compress", "inArgs": [ @@ -62,11 +42,15 @@ "isAsync": false }, { - "functionName": "pedersen___plookup_compress", + "functionName": "pedersen___compress_with_hash_index", "inArgs": [ { "name": "inputs_buffer", "type": "fr::vec_in_buf" + }, + { + "name": "hash_index", + "type": "const uint32_t *" } ], "outArgs": [ @@ -78,15 +62,11 @@ "isAsync": false }, { - "functionName": "pedersen___compress_with_hash_index", + "functionName": "pedersen___commit", "inArgs": [ { "name": "inputs_buffer", "type": "fr::vec_in_buf" - }, - { - "name": "hash_index", - "type": "const uint32_t *" } ], "outArgs": [ @@ -98,23 +78,29 @@ "isAsync": false }, { - "functionName": "pedersen___commit", + "functionName": "pedersen___buffer_to_field", "inArgs": [ { - "name": "inputs_buffer", - "type": "fr::vec_in_buf" + "name": "data", + "type": "const uint8_t *" } ], "outArgs": [ { - "name": "output", + "name": "r", "type": "fr::out_buf" } ], "isAsync": false }, { - "functionName": "pedersen___plookup_commit", + "functionName": "pedersen_hash_init", + "inArgs": [], + "outArgs": [], + "isAsync": false + }, + { + "functionName": "pedersen_hash", "inArgs": [ { "name": "inputs_buffer", @@ -130,7 +116,7 @@ "isAsync": false }, { - "functionName": "pedersen___plookup_commit_with_hash_index", + "functionName": "pedersen_hash_with_hash_index", "inArgs": [ { "name": "inputs_buffer", @@ -149,28 +135,6 @@ ], "isAsync": false }, - { - "functionName": "pedersen___buffer_to_field", - "inArgs": [ - { - "name": "data", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "r", - "type": "fr::out_buf" - } - ], - "isAsync": false - }, - { - "functionName": "pedersen_hash_init", - "inArgs": [], - "outArgs": [], - "isAsync": false - }, { "functionName": "pedersen_hash_pair", "inArgs": [ @@ -532,18 +496,6 @@ ], "isAsync": false }, - { - "functionName": "test_thread_abort", - "inArgs": [], - "outArgs": [], - "isAsync": false - }, - { - "functionName": "test_abort", - "inArgs": [], - "outArgs": [], - "isAsync": false - }, { "functionName": "common_init_slab_allocator", "inArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index c51d24998c1..b0fa54c714f 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,13 +1,7 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergBinder } from '../barretenberg_binder/index.js'; -import { - BufferDeserializer, - NumberDeserializer, - VectorDeserializer, - BoolDeserializer, - StringDeserializer, -} from '../serialize/index.js'; +import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer } from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; export class BarretenbergApi { @@ -27,27 +21,13 @@ export class BarretenbergApi { return result[0]; } - async pedersenPlookupCompressFields(left: Fr, right: Fr): Promise { - const result = await this.binder.callWasmExport('pedersen___compress_fields', [left, right], [Fr]); - return result[0]; - } - async pedersenCompress(inputsBuffer: Fr[]): Promise { const result = await this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]); return result[0]; } - async pedersenPlookupCompress(inputsBuffer: Fr[]): Promise { - const result = await this.binder.callWasmExport('pedersen___compress', [inputsBuffer], [Fr]); - return result[0]; - } - async pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport( - 'pedersen___compress_with_hash_index', - [inputsBuffer, hashIndex], - [Fr], - ); + const result = await this.binder.callWasmExport('pedersen___compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]); return result[0]; } @@ -56,20 +36,6 @@ export class BarretenbergApi { return result[0]; } - async pedersenPlookupCommit(inputsBuffer: Fr[]): Promise { - const result = await this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Fr]); - return result[0]; - } - - async pedersenPlookupCommitWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport( - 'pedersen___plookup_commit_with_hash_index', - [inputsBuffer, hashIndex], - [Fr], - ); - return result[0]; - } - async pedersenBufferToField(data: Uint8Array): Promise { const result = await this.binder.callWasmExport('pedersen___buffer_to_field', [data], [Fr]); return result[0]; @@ -80,6 +46,16 @@ export class BarretenbergApi { return; } + async pedersenHash(inputsBuffer: Fr[]): Promise { + const result = await this.binder.callWasmExport('pedersen_hash', [inputsBuffer], [Fr]); + return result[0]; + } + + async pedersenHashWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { + const result = await this.binder.callWasmExport('pedersen_hash_with_hash_index', [inputsBuffer, hashIndex], [Fr]); + return result[0]; + } + async pedersenHashPair(left: Fr, right: Fr): Promise { const result = await this.binder.callWasmExport('pedersen_hash_pair', [left, right], [Fr]); return result[0]; @@ -91,11 +67,7 @@ export class BarretenbergApi { } async pedersenHashMultipleWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport( - 'pedersen_hash_multiple_with_hash_index', - [inputsBuffer, hashIndex], - [Fr], - ); + const result = await this.binder.callWasmExport('pedersen_hash_multiple_with_hash_index', [inputsBuffer, hashIndex], [Fr]); return result[0]; } @@ -125,76 +97,37 @@ export class BarretenbergApi { } async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { - const result = await this.binder.callWasmExport( - 'schnorr_construct_signature', - [message, privateKey], - [Buffer32, Buffer32], - ); + const result = await this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]); return result as any; } async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { - const result = await this.binder.callWasmExport( - 'schnorr_verify_signature', - [message, pubKey, sigS, sigE], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]); return result[0]; } async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - [privateKey], - [Buffer128], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_create_multisig_public_key', [privateKey], [Buffer128]); return result[0]; } async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - [signerPubkeyBuf], - [Point, BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]); return result as any; } async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - [], - [Buffer128, Buffer128], - ); + const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]); return result as any; } - async schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fq, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): Promise<[Fq, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], - [Fq, BoolDeserializer()], - ); + async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { + const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fq, BoolDeserializer()]); return result as any; } - async schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fr[], - ): Promise<[Buffer32, Buffer32, boolean]> { - const result = await this.binder.callWasmExport( - 'schnorr_multisig_combine_signatures', - [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], - [Buffer32, Buffer32, BoolDeserializer()], - ); + async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): Promise<[Buffer32, Buffer32, boolean]> { + const result = await this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]); return result as any; } @@ -204,11 +137,7 @@ export class BarretenbergApi { } async examplesSimpleCreateAndVerifyProof(): Promise { - const result = await this.binder.callWasmExport( - 'examples_simple_create_and_verify_proof', - [], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('examples_simple_create_and_verify_proof', [], [BoolDeserializer()]); return result[0]; } @@ -217,27 +146,13 @@ export class BarretenbergApi { return result[0]; } - async testThreadAbort(): Promise { - const result = await this.binder.callWasmExport('test_thread_abort', [], []); - return; - } - - async testAbort(): Promise { - const result = await this.binder.callWasmExport('test_abort', [], []); - return; - } - async commonInitSlabAllocator(circuitSize: number): Promise { const result = await this.binder.callWasmExport('common_init_slab_allocator', [circuitSize], []); return; } async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { - const result = await this.binder.callWasmExport( - 'acir_get_circuit_sizes', - [constraintSystemBuf], - [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]); return result as any; } @@ -252,34 +167,17 @@ export class BarretenbergApi { } async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { - const result = await this.binder.callWasmExport( - 'acir_create_circuit', - [acirComposerPtr, constraintSystemBuf, sizeHint], - [], - ); + const result = await this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []); return; } async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { - const result = await this.binder.callWasmExport( - 'acir_init_proving_key', - [acirComposerPtr, constraintSystemBuf], - [], - ); + const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []); return; } - async acirCreateProof( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - isRecursive: boolean, - ): Promise { - const result = await this.binder.callWasmExport( - 'acir_create_proof', - [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], - [BufferDeserializer()], - ); + async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { + const result = await this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]); return result[0]; } @@ -294,51 +192,27 @@ export class BarretenbergApi { } async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport( - 'acir_get_verification_key', - [acirComposerPtr], - [BufferDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_verification_key', [acirComposerPtr], [BufferDeserializer()]); return result[0]; } async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport( - 'acir_verify_proof', - [acirComposerPtr, proofBuf, isRecursive], - [BoolDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]); return result[0]; } async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport( - 'acir_get_solidity_verifier', - [acirComposerPtr], - [StringDeserializer()], - ); + const result = await this.binder.callWasmExport('acir_get_solidity_verifier', [acirComposerPtr], [StringDeserializer()]); return result[0]; } - async acirSerializeProofIntoFields( - acirComposerPtr: Ptr, - proofBuf: Uint8Array, - numInnerPublicInputs: number, - ): Promise { - const result = await this.binder.callWasmExport( - 'acir_serialize_proof_into_fields', - [acirComposerPtr, proofBuf, numInnerPublicInputs], - [VectorDeserializer(Fr)], - ); + async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { + const result = await this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]); return result[0]; } async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { - const result = await this.binder.callWasmExport( - 'acir_serialize_verification_key_into_fields', - [acirComposerPtr], - [VectorDeserializer(Fr), Fr], - ); + const result = await this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]); return result as any; } } From 0b558754e1ea5c1ed7ebf955adab307c4cdee99b Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:25:13 +0000 Subject: [PATCH 3/6] fix tests --- .../ts/src/barretenberg_api/pedersen.test.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts index dba41ca9e35..c2bf4bb20c8 100644 --- a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts +++ b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts @@ -18,21 +18,11 @@ describe('pedersen', () => { expect(result).toEqual(new Fr(1521373897829389584529155077412196627698249315427143054350987371861781120260n)); }); - it('pedersenPlookupCompressFields', async () => { - const result = await api.pedersenPlookupCompressFields(new Fr(4n), new Fr(8n)); - expect(result).toEqual(new Fr(1521373897829389584529155077412196627698249315427143054350987371861781120260n)); - }); - it('pedersenCompress', async () => { const result = await api.pedersenCompress([new Fr(4n), new Fr(8n), new Fr(12n)]); expect(result).toEqual(new Fr(16354408412011670665169322571938780771784319449166930406648760506154417354381n)); }); - it('pedersenPlookupCompress', async () => { - const result = await api.pedersenPlookupCompress([new Fr(4n), new Fr(8n), new Fr(12n)]); - expect(result).toEqual(new Fr(16354408412011670665169322571938780771784319449166930406648760506154417354381n)); - }); - it('pedersenCompressWithHashIndex', async () => { const result = await api.pedersenCompressWithHashIndex([new Fr(4n), new Fr(8n)], 7); expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); @@ -43,11 +33,6 @@ describe('pedersen', () => { expect(result).toEqual(new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n)); }); - it('pedersenPlookupCommit', async () => { - const result = await api.pedersenPlookupCommit([new Fr(4n), new Fr(8n)]); - expect(result).toEqual(new Fr(7336965135159957330095956915667769834743631571088528744280187985812103412470n)); - }); - it('pedersenBufferToField', async () => { const result = await api.pedersenBufferToField( Buffer.from('Hello world! I am a buffer to be converted to a field!'), From 05b7efd67c8d2baea0da9790fc673ee48b96a83d Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:25:41 +0000 Subject: [PATCH 4/6] rename methods in yarn-project that call Plookup based pedersen methods --- .../account/defaults/entrypoint_payload.ts | 4 +- yarn-project/aztec.js/src/utils/authwit.ts | 4 +- .../barretenberg/crypto/pedersen/pedersen.ts | 53 ------------------- 3 files changed, 4 insertions(+), 57 deletions(-) diff --git a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts index 4b55d8e59ab..7c8c1417cc8 100644 --- a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts +++ b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts @@ -1,5 +1,5 @@ import { CircuitsWasm, Fr, GeneratorIndex } from '@aztec/circuits.js'; -import { pedersenPlookupCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; +import { pedersenCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; import { padArrayEnd } from '@aztec/foundation/collection'; import { FunctionCall, PackedArguments, emptyFunctionCall } from '@aztec/types'; @@ -69,7 +69,7 @@ export async function buildPayload(calls: FunctionCall[]): Promise<{ /** Compresses an entrypoint payload to a 32-byte buffer (useful for signing) */ export async function hashPayload(payload: EntrypointPayload) { - return pedersenPlookupCompressWithHashIndex( + return pedersenCompressWithHashIndex( await CircuitsWasm.get(), flattenPayload(payload).map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 7f38fd271f3..ca04db12928 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -1,5 +1,5 @@ import { AztecAddress, CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; -import { pedersenPlookupCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; +import { pedersenCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; import { FunctionCall, PackedArguments } from '@aztec/types'; // docs:start:authwit_computeAuthWitMessageHash @@ -12,7 +12,7 @@ import { FunctionCall, PackedArguments } from '@aztec/types'; */ export const computeAuthWitMessageHash = async (caller: AztecAddress, request: FunctionCall) => { const wasm = await CircuitsWasm.get(); - return pedersenPlookupCompressWithHashIndex( + return pedersenCompressWithHashIndex( wasm, [ caller.toField(), diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts index 6fd57d24571..69362c4f878 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts @@ -60,41 +60,6 @@ export function pedersenCompressInputs(wasm: IWasmModule, inputs: Buffer[]): Buf return Buffer.from(wasm.getMemorySlice(0, 32)); } -/** - * Commits to an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to compress. - * @returns The resulting 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenPlookupCommitInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer { - // If not done already, precompute constants. - wasm.call('pedersen__init'); - const inputVectors = serializeBufferArrayToVector(inputs); - wasm.writeMemory(0, inputVectors); - wasm.call('pedersen_plookup_commit', 0, 0); - return Buffer.from(wasm.getMemorySlice(0, 32)); -} - -/** - * Commits an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to compress. - * @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum). - * @returns The resulting 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenPlookupCommitWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer { - // If not done already, precompute constants. - wasm.call('pedersen__init'); - const inputVectors = serializeBufferArrayToVector(inputs); - wasm.writeMemory(0, inputVectors); - wasm.call('pedersen_plookup_commit_with_hash_index', 0, 0, hashIndex); - return Buffer.from(wasm.getMemorySlice(0, 32)); -} - /** * Compresses an array of buffers. * @param wasm - The barretenberg module. @@ -113,24 +78,6 @@ export function pedersenCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[ return Buffer.from(wasm.getMemorySlice(0, 32)); } -/** - * Compresses an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to compress. - * @param hashIndex - Hash index of the generator to use (See GeneratorIndex enum). - * @returns The resulting 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenPlookupCompressWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer { - // If not done already, precompute constants. - wasm.call('pedersen__init'); - const inputVectors = serializeBufferArrayToVector(inputs); - wasm.writeMemory(0, inputVectors); - wasm.call('pedersen_plookup_compress_with_hash_index', 0, 0, hashIndex); - return Buffer.from(wasm.getMemorySlice(0, 32)); -} - /** * Get a 32-byte pedersen hash from a buffer. * @param wasm - The barretenberg module. From 74f1e7805abad4f9eef4aa2da7771fd683d38814 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:54:00 +0000 Subject: [PATCH 5/6] empty commit From 752586b7edf088ee9eeb2de665d6f62a7a5e5392 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 25 Oct 2023 13:57:18 +0000 Subject: [PATCH 6/6] lint --- barretenberg/ts/src/barretenberg_api/index.ts | 150 +++++++++++++++--- 1 file changed, 126 insertions(+), 24 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index b0fa54c714f..3f4f3d7c695 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,7 +1,13 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergBinder } from '../barretenberg_binder/index.js'; -import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer } from '../serialize/index.js'; +import { + BufferDeserializer, + NumberDeserializer, + VectorDeserializer, + BoolDeserializer, + StringDeserializer, +} from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; export class BarretenbergApi { @@ -27,7 +33,11 @@ export class BarretenbergApi { } async pedersenCompressWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport('pedersen___compress_with_hash_index', [inputsBuffer, hashIndex], [Fr]); + const result = await this.binder.callWasmExport( + 'pedersen___compress_with_hash_index', + [inputsBuffer, hashIndex], + [Fr], + ); return result[0]; } @@ -67,7 +77,11 @@ export class BarretenbergApi { } async pedersenHashMultipleWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport('pedersen_hash_multiple_with_hash_index', [inputsBuffer, hashIndex], [Fr]); + const result = await this.binder.callWasmExport( + 'pedersen_hash_multiple_with_hash_index', + [inputsBuffer, hashIndex], + [Fr], + ); return result[0]; } @@ -97,37 +111,76 @@ export class BarretenbergApi { } async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { - const result = await this.binder.callWasmExport('schnorr_construct_signature', [message, privateKey], [Buffer32, Buffer32]); + const result = await this.binder.callWasmExport( + 'schnorr_construct_signature', + [message, privateKey], + [Buffer32, Buffer32], + ); return result as any; } async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { - const result = await this.binder.callWasmExport('schnorr_verify_signature', [message, pubKey, sigS, sigE], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'schnorr_verify_signature', + [message, pubKey, sigS, sigE], + [BoolDeserializer()], + ); return result[0]; } async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { - const result = await this.binder.callWasmExport('schnorr_multisig_create_multisig_public_key', [privateKey], [Buffer128]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + [privateKey], + [Buffer128], + ); return result[0]; } async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', [signerPubkeyBuf], [Point, BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + [signerPubkeyBuf], + [Point, BoolDeserializer()], + ); return result as any; } async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { - const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_1', [], [Buffer128, Buffer128]); + const result = await this.binder.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + [], + [Buffer128, Buffer128], + ); return result as any; } - async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_construct_signature_round_2', [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], [Fq, BoolDeserializer()]); + async schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fq, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): Promise<[Fq, boolean]> { + const result = await this.binder.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf], + [Fq, BoolDeserializer()], + ); return result as any; } - async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fr[]): Promise<[Buffer32, Buffer32, boolean]> { - const result = await this.binder.callWasmExport('schnorr_multisig_combine_signatures', [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], [Buffer32, Buffer32, BoolDeserializer()]); + async schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fr[], + ): Promise<[Buffer32, Buffer32, boolean]> { + const result = await this.binder.callWasmExport( + 'schnorr_multisig_combine_signatures', + [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf], + [Buffer32, Buffer32, BoolDeserializer()], + ); return result as any; } @@ -137,7 +190,11 @@ export class BarretenbergApi { } async examplesSimpleCreateAndVerifyProof(): Promise { - const result = await this.binder.callWasmExport('examples_simple_create_and_verify_proof', [], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'examples_simple_create_and_verify_proof', + [], + [BoolDeserializer()], + ); return result[0]; } @@ -152,7 +209,11 @@ export class BarretenbergApi { } async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { - const result = await this.binder.callWasmExport('acir_get_circuit_sizes', [constraintSystemBuf], [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_circuit_sizes', + [constraintSystemBuf], + [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()], + ); return result as any; } @@ -167,17 +228,34 @@ export class BarretenbergApi { } async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { - const result = await this.binder.callWasmExport('acir_create_circuit', [acirComposerPtr, constraintSystemBuf, sizeHint], []); + const result = await this.binder.callWasmExport( + 'acir_create_circuit', + [acirComposerPtr, constraintSystemBuf, sizeHint], + [], + ); return; } async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { - const result = await this.binder.callWasmExport('acir_init_proving_key', [acirComposerPtr, constraintSystemBuf], []); + const result = await this.binder.callWasmExport( + 'acir_init_proving_key', + [acirComposerPtr, constraintSystemBuf], + [], + ); return; } - async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport('acir_create_proof', [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], [BufferDeserializer()]); + async acirCreateProof( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + isRecursive: boolean, + ): Promise { + const result = await this.binder.callWasmExport( + 'acir_create_proof', + [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive], + [BufferDeserializer()], + ); return result[0]; } @@ -192,27 +270,51 @@ export class BarretenbergApi { } async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport('acir_get_verification_key', [acirComposerPtr], [BufferDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_verification_key', + [acirComposerPtr], + [BufferDeserializer()], + ); return result[0]; } async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { - const result = await this.binder.callWasmExport('acir_verify_proof', [acirComposerPtr, proofBuf, isRecursive], [BoolDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_verify_proof', + [acirComposerPtr, proofBuf, isRecursive], + [BoolDeserializer()], + ); return result[0]; } async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { - const result = await this.binder.callWasmExport('acir_get_solidity_verifier', [acirComposerPtr], [StringDeserializer()]); + const result = await this.binder.callWasmExport( + 'acir_get_solidity_verifier', + [acirComposerPtr], + [StringDeserializer()], + ); return result[0]; } - async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { - const result = await this.binder.callWasmExport('acir_serialize_proof_into_fields', [acirComposerPtr, proofBuf, numInnerPublicInputs], [VectorDeserializer(Fr)]); + async acirSerializeProofIntoFields( + acirComposerPtr: Ptr, + proofBuf: Uint8Array, + numInnerPublicInputs: number, + ): Promise { + const result = await this.binder.callWasmExport( + 'acir_serialize_proof_into_fields', + [acirComposerPtr, proofBuf, numInnerPublicInputs], + [VectorDeserializer(Fr)], + ); return result[0]; } async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { - const result = await this.binder.callWasmExport('acir_serialize_verification_key_into_fields', [acirComposerPtr], [VectorDeserializer(Fr), Fr]); + const result = await this.binder.callWasmExport( + 'acir_serialize_verification_key_into_fields', + [acirComposerPtr], + [VectorDeserializer(Fr), Fr], + ); return result as any; } }