From 2c569cf6a481b78843a03f93409c100dd00b0fa1 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Fri, 7 Apr 2023 00:23:22 +0200 Subject: [PATCH] Aztec3 Specific Work in Barretenberg (#142) * Split Pedersen Hash & Commitment Gadgets (#95) * [SQUASHED] Pedersen refactor into hash and commitment. Use lookup pedersen for merkle tree, fixed-base pedersen for commitments. --------- Co-authored-by: Suyash Bagad Port `copy_as_new_witness`. Port `must_imply`. `operator++`. Port changes from `common`. Port `ecc/groups`. * [CPM] add missing dependencies to libbarretenberg.a (#154) --------- * Increase Pedersen Generator indices and subindices. (#169) * Remove a3 specific types. (#252) * Address Luke's Comments on `aztec3 -> master` (#263) * Add must_imply tests. * Added a test for `field_t::copy_as_new_witness` * add test for `conditional_assign` * Added `infinity` test. * Add `add_affine_test`. * Tests for Array Object in `stdlib` (#262) * basic array tests. * Add `composer_type` while hashing/compressing a vkey. * Add `contains_recursive_proof` to Recursive VK (#268) * feat: debug utility for serialization (#290) * feat: enable asan config * `array_push` for Generic Type (#291) * Add Indexed Merkle Tree (#281) * remove ts (consulted with Adam and we're good to go). (#292) * Add cout for verification_key struct (#295) * compute tree (#298) * [SQUASHED] fixing `push_array_to_array` method. (#304) * feat(memory_tree|a3): add sibling path calculations (#301) * feat(memory_tree): frontier paths * fix array and resolve merge conflicts (#305) * Mc/hash vk (#306) * Increase number of sub-generators to 128. * Build a3crypto.wasm (#311) * More Tests on A3 `stdlib` methods (#316) * test: more vk tests to compare circuit/native/vk_data (#310) * Mc/hash vk (#306) * inc num_generators_per_hash_index to 128. (#309) * fix. (#318) * Added test for `compute_tree_native`. (#319) * Install instructions for apt on ubuntu (#312) * Fix address compilation. (#329) --------- Co-authored-by: David Banks <47112877+dbanks12@users.noreply.github.com> Co-authored-by: Michael Connor Co-authored-by: dbanks12 Co-authored-by: Santiago Palladino Co-authored-by: ludamad Co-authored-by: Maddiaa <47148561+cheethas@users.noreply.github.com> Co-authored-by: Santiago Palladino Co-authored-by: ludamad Co-authored-by: cheethas --- README.md | 17 +- cpp/CMakeLists.txt | 11 + cpp/dockerfiles/Dockerfile.wasm-linux-clang | 5 +- cpp/scripts/bb-tests | 4 +- cpp/src/CMakeLists.txt | 56 +- cpp/src/barretenberg/common/container.hpp | 12 + cpp/src/barretenberg/common/map.hpp | 18 +- cpp/src/barretenberg/common/serialize.hpp | 67 ++ cpp/src/barretenberg/common/streams.hpp | 25 +- cpp/src/barretenberg/crypto/CMakeLists.txt | 4 +- cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp | 38 + .../crypto/generators/CMakeLists.txt | 1 + .../fixed_base_scalar_mul.hpp | 7 +- .../generator_data.cpp | 35 +- .../generator_data.hpp | 4 +- .../generator_data.test.cpp} | 9 +- .../crypto/pedersen/CMakeLists.txt | 1 - .../barretenberg/crypto/pedersen/pedersen.hpp | 25 - .../crypto/pedersen/pedersen_lookup.test.cpp | 143 ---- .../crypto/pedersen_commitment/CMakeLists.txt | 1 + .../c_bind.cpp | 46 +- .../c_bind.hpp | 12 +- .../convert_buffer_to_field.hpp | 6 +- .../pedersen.cpp | 40 +- .../crypto/pedersen_commitment/pedersen.hpp | 31 + .../pedersen_commitment/pedersen_lookup.cpp | 146 ++++ .../pedersen_commitment/pedersen_lookup.hpp | 32 + .../pedersen_lookup.test.cpp | 253 ++++++ .../sidon_set/sidon_set.hpp | 2 +- .../sidon_set/sidon_set.test.cpp | 2 +- .../crypto/pedersen_hash/CMakeLists.txt | 1 + .../crypto/pedersen_hash/c_bind.cpp | 67 ++ .../crypto/pedersen_hash/c_bind.hpp | 28 + .../crypto/pedersen_hash/pedersen.cpp | 71 ++ .../crypto/pedersen_hash/pedersen.hpp | 17 + .../pedersen_lookup.cpp | 65 +- .../pedersen_lookup.hpp | 31 +- .../crypto/schnorr/CMakeLists.txt | 2 +- .../barretenberg/crypto/schnorr/schnorr.tcc | 6 +- .../dsl/acir_format/CMakeLists.txt | 2 +- .../barretenberg/dsl/acir_format/pedersen.cpp | 5 +- .../barretenberg/ecc/curves/bn254/fr.test.cpp | 29 + .../barretenberg/ecc/curves/bn254/g1.test.cpp | 22 + cpp/src/barretenberg/ecc/fields/field.hpp | 5 + .../barretenberg/ecc/fields/field_impl.hpp | 12 + .../ecc/groups/affine_element.hpp | 3 + .../ecc/groups/affine_element_impl.hpp | 15 + cpp/src/barretenberg/ecc/groups/element.hpp | 2 +- .../barretenberg/ecc/groups/element_impl.hpp | 7 + .../honk/composer/standard_honk_composer.hpp | 4 + .../honk/transcript/transcript.hpp | 4 +- .../proofs/join_split/CMakeLists.txt | 2 +- .../join_split/compute_signing_data.cpp | 4 +- .../proofs/join_split/join_split.test.cpp | 8 +- .../proofs/join_split/join_split_tx.cpp | 2 +- .../proofs/join_split/verify_signature.hpp | 4 +- .../proofs/mock/CMakeLists.txt | 2 +- .../proofs/mock/mock_circuit.hpp | 5 +- .../proofs/notes/CMakeLists.txt | 2 +- .../proofs/notes/circuit/account/commit.hpp | 2 +- .../claim/complete_partial_commitment.hpp | 4 +- .../notes/circuit/claim/compute_nullifier.hpp | 3 +- .../claim/create_partial_commitment.hpp | 5 +- .../value/complete_partial_commitment.hpp | 7 +- .../notes/circuit/value/compute_nullifier.cpp | 2 +- .../value/create_partial_commitment.hpp | 4 +- .../notes/native/account/account_note.cpp | 6 +- .../notes/native/account/account_note.hpp | 2 +- .../compute_account_alias_hash_nullifier.hpp | 6 +- .../compute_account_public_key_nullifier.hpp | 6 +- .../proofs/notes/native/bridge_call_data.hpp | 2 +- .../proofs/notes/native/claim/claim_note.hpp | 2 +- .../notes/native/claim/claim_note_tx_data.hpp | 2 +- .../claim/complete_partial_commitment.hpp | 6 +- .../notes/native/claim/compute_nullifier.hpp | 4 +- .../claim/create_partial_commitment.hpp | 4 +- .../value/complete_partial_commitment.hpp | 6 +- .../notes/native/value/compute_nullifier.cpp | 6 +- .../value/create_partial_commitment.hpp | 6 +- .../proofs/notes/native/value/value_note.hpp | 2 +- .../join_split_example/proofs/verify.hpp | 15 +- cpp/src/barretenberg/plonk/CMakeLists.txt | 2 +- .../composer/plookup_tables/pedersen.hpp | 48 +- .../turbo_plonk_composer_helper.hpp | 4 +- .../splitting_tmp/standard_plonk_composer.hpp | 4 + .../standard_plonk_composer.test.cpp | 4 +- .../splitting_tmp/turbo_plonk_composer.hpp | 4 + .../turbo_plonk_composer.test.cpp | 21 +- .../splitting_tmp/ultra_plonk_composer.hpp | 6 + .../ultra_plonk_composer.test.cpp | 19 +- .../plonk/composer/standard_composer.hpp | 5 +- .../plonk/composer/standard_composer.test.cpp | 6 +- .../plonk/composer/turbo_composer.hpp | 5 +- .../plonk/composer/turbo_composer.test.cpp | 20 +- .../plonk/composer/ultra_composer.hpp | 5 +- .../plonk/composer/ultra_composer.test.cpp | 18 +- .../plonk/proof_system/constants.hpp | 5 - .../plonk/proof_system/types/proof.hpp | 35 +- .../verification_key/verification_key.cpp | 91 +++ .../verification_key/verification_key.hpp | 33 + .../verification_key.test.cpp | 150 +++- .../barretenberg/proof_system/CMakeLists.txt | 2 +- .../standard_circuit_constructor.test.cpp | 4 +- .../turbo_circuit_constructor.test.cpp | 17 +- .../ultra_circuit_constructor.hpp | 3 +- .../proof_system/types/merkle_hash_type.hpp | 6 + .../types/pedersen_commitment_type.hpp | 6 + cpp/src/barretenberg/stdlib/CMakeLists.txt | 1 + .../stdlib/commitment/CMakeLists.txt | 1 + .../stdlib/commitment/pedersen/CMakeLists.txt | 1 + .../pedersen/pedersen.bench.cpp | 15 +- .../stdlib/commitment/pedersen/pedersen.cpp | 140 ++++ .../stdlib/commitment/pedersen/pedersen.hpp | 59 ++ .../pedersen/pedersen.test.cpp | 187 +---- .../commitment/pedersen/pedersen_plookup.cpp | 145 ++++ .../commitment/pedersen/pedersen_plookup.hpp | 43 ++ .../pedersen/pedersen_plookup.test.cpp | 183 +++++ .../stdlib/encryption/ecdsa/ecdsa.hpp | 15 + .../stdlib/encryption/schnorr/CMakeLists.txt | 2 +- .../stdlib/encryption/schnorr/schnorr.cpp | 7 +- .../encryption/schnorr/schnorr.test.cpp | 2 +- .../stdlib/hash/blake3s/blake3s.test.cpp | 13 +- .../stdlib/hash/keccak/keccak.test.cpp | 12 - .../stdlib/hash/pedersen/CMakeLists.txt | 2 +- .../stdlib/hash/pedersen/pedersen.cpp | 159 ++-- .../stdlib/hash/pedersen/pedersen.hpp | 55 +- .../stdlib/hash/pedersen/pedersen_plookup.cpp | 61 +- .../stdlib/hash/pedersen/pedersen_plookup.hpp | 23 +- .../stdlib/merkle_tree/CMakeLists.txt | 44 +- .../barretenberg/stdlib/merkle_tree/hash.hpp | 70 +- .../stdlib/merkle_tree/hash.test.cpp | 46 +- .../stdlib/merkle_tree/hash_path.hpp | 7 +- .../stdlib/merkle_tree/membership.hpp | 33 +- .../stdlib/merkle_tree/membership.test.cpp | 70 ++ .../stdlib/merkle_tree/memory_tree.cpp | 22 +- .../stdlib/merkle_tree/memory_tree.hpp | 4 +- .../stdlib/merkle_tree/memory_tree.test.cpp | 43 +- .../stdlib/merkle_tree/merkle_tree.bench.cpp | 2 +- .../stdlib/merkle_tree/merkle_tree.cpp | 14 +- .../stdlib/merkle_tree/merkle_tree.hpp | 4 +- .../nullifier_tree/nullifier_leaf.hpp | 66 ++ .../nullifier_tree/nullifier_memory_tree.cpp | 65 ++ .../nullifier_tree/nullifier_memory_tree.hpp | 94 +++ .../nullifier_memory_tree.test.cpp | 203 +++++ .../nullifier_tree/nullifier_tree.cpp | 85 ++ .../nullifier_tree/nullifier_tree.hpp | 45 ++ .../nullifier_tree/nullifier_tree.test.cpp | 140 ++++ .../stdlib/primitives/address/address.hpp | 142 ++++ .../stdlib/primitives/bigfield/bigfield.hpp | 6 +- .../primitives/bigfield/bigfield_impl.hpp | 24 +- .../stdlib/primitives/bool/bool.cpp | 79 ++ .../stdlib/primitives/bool/bool.hpp | 4 + .../stdlib/primitives/bool/bool.test.cpp | 163 +++- .../stdlib/primitives/field/array.hpp | 179 +++++ .../stdlib/primitives/field/array.test.cpp | 727 ++++++++++++++++++ .../stdlib/primitives/field/field.hpp | 29 +- .../stdlib/primitives/field/field.test.cpp | 80 +- .../stdlib/primitives/group/group.hpp | 8 +- .../stdlib/primitives/group/group.test.cpp | 4 +- .../primitives/plookup/plookup.test.cpp | 34 +- .../stdlib/primitives/point/point.hpp | 15 + .../primitives/safe_uint/safe_uint.test.cpp | 3 +- .../stdlib/recursion/CMakeLists.txt | 2 +- .../aggregation_state/aggregation_state.hpp | 74 ++ .../native_aggregation_state.hpp | 63 ++ .../recursion/transcript/transcript.hpp | 8 +- .../verification_key/verification_key.hpp | 85 +- .../verification_key.test.cpp | 90 +++ .../stdlib/recursion/verifier/verifier.hpp | 35 +- .../recursion/verifier/verifier.test.cpp | 106 +-- .../verifier/verifier_turbo.test.cpp | 96 +-- cpp/src/barretenberg/stdlib/types/types.hpp | 6 +- .../barretenberg/transcript/CMakeLists.txt | 2 +- .../barretenberg/transcript/transcript.cpp | 8 +- ts/src/crypto/index.ts | 1 - ts/src/crypto/pedersen/index.ts | 1 - ts/src/crypto/pedersen/pedersen.test.ts | 33 - ts/src/crypto/pedersen/pedersen.ts | 93 --- ts/src/wasm/barretenberg.wasm | 1 - ts/src/wasm/barretenberg_wasm.test.ts | 46 -- ts/src/wasm/index.ts | 1 - ts/src/wasm/serialize.ts | 70 -- 182 files changed, 5225 insertions(+), 1381 deletions(-) create mode 100644 cpp/src/barretenberg/crypto/generators/CMakeLists.txt rename cpp/src/barretenberg/crypto/{pedersen => generators}/fixed_base_scalar_mul.hpp (89%) rename cpp/src/barretenberg/crypto/{pedersen => generators}/generator_data.cpp (90%) rename cpp/src/barretenberg/crypto/{pedersen => generators}/generator_data.hpp (97%) rename cpp/src/barretenberg/crypto/{pedersen/pedersen.test.cpp => generators/generator_data.test.cpp} (93%) delete mode 100644 cpp/src/barretenberg/crypto/pedersen/CMakeLists.txt delete mode 100644 cpp/src/barretenberg/crypto/pedersen/pedersen.hpp delete mode 100644 cpp/src/barretenberg/crypto/pedersen/pedersen_lookup.test.cpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_commitment/CMakeLists.txt rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/c_bind.cpp (64%) rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/c_bind.hpp (76%) rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/convert_buffer_to_field.hpp (92%) rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/pedersen.cpp (68%) create mode 100644 cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.hpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_commitment/pedersen_lookup.cpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_commitment/pedersen_lookup.hpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_commitment/pedersen_lookup.test.cpp rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/sidon_set/sidon_set.hpp (99%) rename cpp/src/barretenberg/crypto/{pedersen => pedersen_commitment}/sidon_set/sidon_set.test.cpp (99%) create mode 100644 cpp/src/barretenberg/crypto/pedersen_hash/CMakeLists.txt create mode 100644 cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_hash/pedersen.cpp create mode 100644 cpp/src/barretenberg/crypto/pedersen_hash/pedersen.hpp rename cpp/src/barretenberg/crypto/{pedersen => pedersen_hash}/pedersen_lookup.cpp (70%) rename cpp/src/barretenberg/crypto/{pedersen => pedersen_hash}/pedersen_lookup.hpp (64%) create mode 100644 cpp/src/barretenberg/proof_system/types/merkle_hash_type.hpp create mode 100644 cpp/src/barretenberg/proof_system/types/pedersen_commitment_type.hpp create mode 100644 cpp/src/barretenberg/stdlib/commitment/CMakeLists.txt create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/CMakeLists.txt rename cpp/src/barretenberg/stdlib/{hash => commitment}/pedersen/pedersen.bench.cpp (92%) create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.cpp create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.hpp rename cpp/src/barretenberg/stdlib/{hash => commitment}/pedersen/pedersen.test.cpp (68%) create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.cpp create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp create mode 100644 cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.test.cpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.cpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.test.cpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.cpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.hpp create mode 100644 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp create mode 100644 cpp/src/barretenberg/stdlib/primitives/address/address.hpp create mode 100644 cpp/src/barretenberg/stdlib/primitives/field/array.hpp create mode 100644 cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp create mode 100644 cpp/src/barretenberg/stdlib/recursion/aggregation_state/aggregation_state.hpp create mode 100644 cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp create mode 100644 cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp delete mode 100644 ts/src/crypto/index.ts delete mode 100644 ts/src/crypto/pedersen/index.ts delete mode 100644 ts/src/crypto/pedersen/pedersen.test.ts delete mode 100644 ts/src/crypto/pedersen/pedersen.ts delete mode 120000 ts/src/wasm/barretenberg.wasm delete mode 100644 ts/src/wasm/barretenberg_wasm.test.ts delete mode 100644 ts/src/wasm/index.ts delete mode 100644 ts/src/wasm/serialize.ts diff --git a/README.md b/README.md index 802392f5fc3..ef207aa92b8 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,17 @@ - libomp (if multithreading is required. Multithreading can be disabled using the compiler flag `-DMULTITHREADING 0`) - wasm-opt (part of the [Binaryen](https://github.com/WebAssembly/binaryen) toolkit) +To install on Ubuntu, run: +``` +sudo apt-get install cmake clang clang-format ninja-build binaryen +``` + ### Installing openMP (Linux) +Install from source: + ``` -RUN git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \ +git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \ && cd llvm-project && mkdir build-openmp && cd build-openmp \ && cmake ../openmp -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMP_ENABLE_SHARED=OFF \ && cmake --build . --parallel \ @@ -22,6 +29,14 @@ RUN git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git && cd ../.. && rm -rf llvm-project ``` +Or install from a package manager, on Ubuntu: + +``` +sudo apt-get install libomp-dev +``` + +> Note: on a fresh Ubuntu Kinetic installation, installing OpenMP from source yields a `Could NOT find OpenMP_C (missing: OpenMP_omp_LIBRARY) (found version "5.0")` error when trying to build Barretenberg. Installing from apt worked fine. + ### Getting started Run the bootstrap script. (The bootstrap script will build both the native and wasm versions of barretenberg) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index b978b04d53f..582d7285374 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -18,6 +18,8 @@ option(BENCHMARKS "Build benchmarks" ON) option(FUZZING "Build fuzzing harnesses" OFF) option(DISABLE_TBB "Intel Thread Building Blocks" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) +option(SERIALIZE_CANARY "Build with serialize canary" OFF) +option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF) option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF) option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON) option(USE_TURBO "Enable the use of TurboPlonk in barretenberg." OFF) @@ -39,6 +41,15 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "a set(DISABLE_TBB 0) endif() +if(ENABLE_ASAN) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) +endif() + +if(SERIALIZE_CANARY) + add_definitions(-DENABLE_SERIALIZE_CANARY) +endif() + if(FUZZING) add_definitions(-DFUZZING=1) diff --git a/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/cpp/dockerfiles/Dockerfile.wasm-linux-clang index f4a19bba534..d1c41f0ce7a 100644 --- a/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -5,10 +5,11 @@ WORKDIR /usr/src/barretenberg/cpp/src RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv - WORKDIR /usr/src/barretenberg/cpp COPY . . -# Build both honk_tests barretenberg.wasm +# Build both honk_tests barretenberg.wasm primitives.wasm # This ensures that we aren't using features that would be incompatible with WASM for Honk -RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm +RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target primitives.wasm FROM alpine:3.17 COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm +COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/primitives.wasm /usr/src/barretenberg/cpp/build/bin/primitives.wasm COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/ diff --git a/cpp/scripts/bb-tests b/cpp/scripts/bb-tests index b8df6e338fb..ba012981ead 100644 --- a/cpp/scripts/bb-tests +++ b/cpp/scripts/bb-tests @@ -2,7 +2,7 @@ crypto_aes128_tests crypto_blake2s_tests crypto_blake3s_tests crypto_ecdsa_tests -crypto_pedersen_tests +crypto_pedersen_commitment_tests crypto_schnorr_tests crypto_sha256_tests ecc_tests @@ -18,7 +18,7 @@ stdlib_blake2s_tests stdlib_blake3s_tests stdlib_ecdsa_tests stdlib_merkle_tree_tests -stdlib_pedersen_tests +stdlib_pedersen_commitment_tests stdlib_schnorr_tests stdlib_sha256_tests transcript_tests diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index 3a40b2a908a..a90789f9c64 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -76,7 +76,9 @@ if(WASM) $ $ $ - $ + $ + $ + $ $ $ $ @@ -84,7 +86,8 @@ if(WASM) $ $ $ - $ + $ + $ $ $ $ @@ -92,6 +95,9 @@ if(WASM) $ $ $ + $ + $ + $ ) # With binaryen installed, it seems its wasm backend optimiser gets invoked automatically. @@ -105,12 +111,35 @@ if(WASM) -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 ) + # Repeat the above but for the smaller primitives.wasm + # Used in packages where we don't need the full contents of barretenberg + add_executable( + primitives.wasm + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + ) + + target_link_options( + primitives.wasm + PRIVATE + -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 + ) + # TODO(blaine): Figure out how to Asyncify the wasm output. # Binaryen's Asyncify transform produces wasm that has too many local variables to run in a WebAssembly # instance. This likely would be "solved" by enabling the optimizations to reduce the number of locals, # but using any optimization level results in a wasm file that takes an unusable amount of time to solve the # most simple prood. - # find_program(WASM_OPT wasm-opt) # if(NOT WASM_OPT) @@ -124,6 +153,13 @@ if(WASM) # VERBATIM # ) + add_custom_command( + TARGET primitives.wasm + POST_BUILD + COMMAND wasm-opt "$" -O2 -o "$" + VERBATIM + ) + if(INSTALL_BARRETENBERG) install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() @@ -142,7 +178,9 @@ if(WASM) $ $ $ - $ + $ + $ + $ $ $ $ @@ -150,7 +188,8 @@ if(WASM) $ $ $ - $ + $ + $ $ $ $ @@ -174,7 +213,9 @@ else() $ $ $ - $ + $ + $ + $ $ $ $ @@ -182,7 +223,8 @@ else() $ $ $ - $ + $ + $ $ $ $ diff --git a/cpp/src/barretenberg/common/container.hpp b/cpp/src/barretenberg/common/container.hpp index 6418be1461d..1c87bb1224a 100644 --- a/cpp/src/barretenberg/common/container.hpp +++ b/cpp/src/barretenberg/common/container.hpp @@ -48,4 +48,16 @@ InnerCont flatten(Cont const& in) result.insert(result.end(), e.begin(), e.end()); } return result; +} + +// Return the first index at which a given item can be found in the vector. +// Only safe for vectors with length less than the size_t overflow size. +template long index_of(std::vector const& vec, T const& item) +{ + auto const& begin = vec.begin(); + auto const& end = vec.end(); + + auto const& itr = std::find(begin, end, item); + + return itr == end ? -1 : std::distance(begin, itr); } \ No newline at end of file diff --git a/cpp/src/barretenberg/common/map.hpp b/cpp/src/barretenberg/common/map.hpp index a78c81ca628..79205f2bda5 100644 --- a/cpp/src/barretenberg/common/map.hpp +++ b/cpp/src/barretenberg/common/map.hpp @@ -10,13 +10,29 @@ template