From 87eeb715014996ec329de969df85684083b18f83 Mon Sep 17 00:00:00 2001 From: Charlie Lye Date: Tue, 7 Nov 2023 20:33:48 +0000 Subject: [PATCH] chore!: Replace computing hashes in circuits wasm, with computing them in ts via bb.js pedersen call. (#3114) * This was originally going to use our TS pedersen lib to do all pedersen computations, but wasm is 10x faster, so we still want to use wasm. * Introduce `elliptic` version of pedersen as it can be much faster than `@noble/curves` (WARNING: Jest totally messes with benchmarks and can't be trusted for timings with this stuff). Leaving noble version in for now in case want to revisit, but not exported via index. The `elliptic` version is also just there as reference (maybe useful in future). * The pedersen api required being passed a wasm, and that wasm was obtained via async call. This creates a tonne of async function overhead and is generally a bit of a faff. * This adds `foundation/crypto/pedersen/pedersen.wasm.ts` (and defaults to using it via index.ts) that mimics our pure TS pedersen api, but uses the bb.js wasm. * Adds a hand rolled synchronous pedersen bind caller to bb.js (I should probably bring back making bindgen produce the sync api, but also figured might adopt Adams msgpack approach so not worth effort). * `foundation/crypto/pedersen` leverages top-level await to load the wasm as a global, so we can remove a tonne of async await calls. * We cleanup some of the c_binds in barretenberg. * We still use circuits.wasm for a couple of more complex calls ive not tackled yet, e.g. `hashVK`. * We now have dependency on bb.js, pulled in via `portal` yarn thingy. *What does this mean for releases?* (edit: This would probably have broken canary. This PR disabled canary. https://github.com/AztecProtocol/aztec-packages/pull/3244) * Pulls the bbmalloc WASM_EXPORTS into own header so it doesn't mess with the bindgen util. * Broke some circular import dependencies as I was hitting weird errors. * All pedersen calls now made on `foundation/crypto/pedersen`, got rid of `circuits/barretenberg/crypto/pedersen` wrapper. * Enable colorizing debug output in e2e tests via `DEBUG_COLOR=1`. * Change some `test()` to `it()` (was faffing with other test runner when profiling pedersen). * Timer uses `performance.now` rather than `Date.getTime()` * Introduces `madge` as a tool to detect circular deps. TODO in subsequent PR's. * Move all the hashing functions in `abis.ts` to exist as hash functions on the various types. * Implement hash functions for e.g. vkHash and a couple others that were to complicated for doing right now. * Move the types out of circuits.js into types project. * Ultimately remove need for circuits.js / circuits.wasm? --- .circleci/config.yml | 1 + .../cpp/src/barretenberg/barretenberg.hpp | 1 + .../common/{mem.cpp => bbmalloc.cpp} | 3 +- .../cpp/src/barretenberg/common/bbmalloc.hpp | 7 + .../cpp/src/barretenberg/common/mem.hpp | 5 +- .../crypto/pedersen_commitment/c_bind.cpp | 7 +- .../crypto/pedersen_commitment/c_bind.hpp | 15 +- .../crypto/pedersen_commitment/c_bind_new.cpp | 18 - .../crypto/pedersen_commitment/c_bind_new.hpp | 12 - .../pedersen_commitment/pedersen.test.cpp | 37 +- .../crypto/pedersen_hash/c_bind.cpp | 4 +- .../crypto/pedersen_hash/c_bind.hpp | 4 +- .../crypto/pedersen_hash/c_bind_new.cpp | 17 - .../barretenberg/crypto/schnorr/c_bind.cpp | 103 +- .../barretenberg/crypto/schnorr/c_bind.hpp | 2 +- .../crypto/schnorr/c_bind_new.cpp | 150 --- .../commitment/pedersen/pedersen.test.cpp | 2 +- barretenberg/exports.json | 6 +- barretenberg/scripts/c_bind_files.txt | 2 +- barretenberg/scripts/decls_json.py | 7 - .../out => barretenberg/scripts/exports.json | 0 barretenberg/ts/src/barretenberg_api/index.ts | 8 +- .../ts/src/barretenberg_api/pedersen.test.ts | 29 - .../ts/src/barretenberg_api/schnorr.test.ts | 10 +- .../barretenberg_wasm_base/index.ts | 4 + .../barretenberg_wasm_main/index.ts | 8 + barretenberg/ts/src/benchmark/timer.ts | 10 +- barretenberg/ts/src/index.ts | 1 + .../ts/src}/pedersen/index.ts | 0 barretenberg/ts/src/pedersen/pedersen.test.ts | 33 + barretenberg/ts/src/pedersen/pedersen.ts | 57 + barretenberg/ts/src/types/fields.ts | 22 +- build-system/scripts/add_timestamps | 2 +- build-system/scripts/cond_spot_run_compose | 2 +- build-system/scripts/spot_run_script | 3 +- build_manifest.yml | 1 + .../acir-simulator/src/acvm/serialize.ts | 4 +- .../src/client/client_execution_context.ts | 13 +- .../src/client/execution_note_cache.ts | 7 +- .../src/client/private_execution.test.ts | 57 +- .../src/client/simulator.test.ts | 19 +- .../src/client/view_data_oracle.ts | 5 +- .../src/common/packed_args_cache.ts | 4 +- .../acir-simulator/src/public/execution.ts | 36 +- .../acir-simulator/src/public/index.test.ts | 36 +- .../src/public/public_execution_context.ts | 2 +- yarn-project/acir-simulator/src/test/utils.ts | 10 +- yarn-project/acir-simulator/src/utils.ts | 14 +- .../aztec-node/src/aztec-node/server.ts | 7 +- .../aztec-sandbox/src/examples/token.ts | 2 +- .../account/defaults/default_entrypoint.ts | 6 +- .../account/defaults/entrypoint_payload.ts | 15 +- yarn-project/aztec.js/src/account/utils.ts | 2 +- .../aztec.js/src/contract/batch_call.ts | 4 +- .../aztec.js/src/contract/contract.test.ts | 4 +- .../aztec.js/src/contract/contract.ts | 3 +- .../src/contract_deployer/deploy_method.ts | 2 +- .../src/contract_deployer/deploy_sent_tx.ts | 9 +- yarn-project/aztec.js/src/utils/authwit.ts | 12 +- .../aztec.js/src/utils/cheat_codes.ts | 10 +- yarn-project/aztec.js/src/utils/secrets.ts | 7 +- yarn-project/aztec.js/src/wallet/index.ts | 4 +- .../aztec.js/src/wallet/signerless_wallet.ts | 5 +- .../token/src/tests/token.contract.test.ts | 56 +- .../src/abis/__snapshots__/abis.test.ts.snap | 96 ++ .../circuits.js/src/abis/abis.test.ts | 149 ++- yarn-project/circuits.js/src/abis/abis.ts | 334 ++++-- .../src/barretenberg/crypto/grumpkin/index.ts | 2 + .../src/barretenberg/crypto/index.ts | 1 - .../barretenberg/crypto/pedersen/pedersen.ts | 72 -- .../src/contract/contract_deployment_info.ts | 14 +- .../contract/contract_tree/contract_tree.ts | 4 +- .../src/structs/complete_address.test.ts | 20 +- .../src/structs/complete_address.ts | 16 +- .../src/structs/public_call_request.ts | 10 +- .../circuits.js/src/utils/serialize.ts | 6 +- yarn-project/cli/src/index.ts | 2 +- yarn-project/cli/src/test/utils.test.ts | 2 +- yarn-project/end-to-end/package.json | 2 +- .../scripts/docker-compose-browser.yml | 2 + .../scripts/docker-compose-no-sandbox.yml | 1 + .../end-to-end/scripts/docker-compose-p2p.yml | 2 + .../end-to-end/scripts/docker-compose.yml | 3 +- .../end-to-end/src/e2e_2_pxes.test.ts | 2 +- .../end-to-end/src/e2e_block_building.test.ts | 8 +- .../end-to-end/src/e2e_cheat_codes.test.ts | 2 +- .../src/e2e_cross_chain_messaging.test.ts | 14 +- .../src/e2e_escrow_contract.test.ts | 4 +- .../src/e2e_lending_contract.test.ts | 22 +- .../e2e_multiple_accounts_1_enc_key.test.ts | 2 +- .../src/e2e_non_contract_account.test.ts | 3 +- .../end-to-end/src/e2e_ordering.test.ts | 2 +- .../e2e_public_cross_chain_messaging.test.ts | 8 +- .../e2e_public_to_private_messaging.test.ts | 2 +- .../src/e2e_sandbox_example.test.ts | 4 +- .../end-to-end/src/e2e_token_contract.test.ts | 56 +- .../src/guides/dapp_testing.test.ts | 8 +- .../writing_an_account_contract.test.ts | 2 +- .../src/integration_archiver_l1_to_l2.test.ts | 2 +- yarn-project/end-to-end/src/shared/browser.ts | 6 +- yarn-project/end-to-end/src/shared/cli.ts | 2 +- .../src/shared/cross_chain_test_harness.ts | 4 +- .../end-to-end/src/shared/uniswap_l1_l2.ts | 38 +- .../src/simulators/lending_simulator.ts | 15 +- yarn-project/foundation/package.json | 6 + .../foundation/src/abi/function_selector.ts | 5 +- .../src/async-map/async_map.test.ts | 2 +- yarn-project/foundation/src/crypto/index.ts | 1 + .../src/crypto/pedersen/index.test.ts | 14 +- .../foundation/src/crypto/pedersen/index.ts | 310 +---- .../src/crypto/pedersen/pedersen.elliptic.ts | 584 ++++++++++ .../src/crypto/pedersen/pedersen.noble.ts | 573 ++++++++++ .../src/crypto/pedersen/pedersen.wasm.ts | 28 + .../json-rpc/client/json_rpc_client.test.ts | 2 +- .../foundation/src/json-rpc/convert.test.ts | 18 +- .../json-rpc/server/json_rpc_server.test.ts | 8 +- yarn-project/foundation/src/timer/timer.ts | 13 +- yarn-project/merkle-tree/src/pedersen.ts | 9 +- .../src/sparse_tree/sparse_tree.test.ts | 8 +- .../test/standard_indexed_tree.test.ts | 8 +- .../src/standard_tree/standard_tree.test.ts | 8 +- .../src/test/standard_based_test_suite.ts | 8 +- .../merkle-tree/src/test/test_suite.ts | 8 +- .../noir-protocol-circuits/src/index.test.ts | 24 +- .../src/noir_test_gen.test.ts | 7 +- yarn-project/package.json | 1 + yarn-project/pxe/src/contract_tree/index.ts | 12 +- .../pxe/src/kernel_prover/proof_creator.ts | 6 +- .../src/note_processor/note_processor.test.ts | 11 +- .../pxe/src/note_processor/note_processor.ts | 7 +- .../pxe/src/pxe_service/pxe_service.ts | 10 +- .../src/pxe_service/test/pxe_test_suite.ts | 8 +- .../pxe/src/synchronizer/synchronizer.ts | 5 +- .../block_builder/solo_block_builder.test.ts | 12 +- .../src/block_builder/solo_block_builder.ts | 19 +- .../src/sequencer/public_processor.test.ts | 2 +- .../src/sequencer/public_processor.ts | 14 +- .../sequencer-client/src/sequencer/utils.ts | 5 +- .../src/simulator/public_executor.ts | 9 +- yarn-project/types/src/mocks.ts | 4 +- yarn-project/types/src/packed_arguments.ts | 6 +- .../server_world_state_synchronizer.test.ts | 8 +- .../world-state/src/world-state-db/index.ts | 244 +--- .../src/world-state-db/merkle_tree_db.ts | 242 ++++ .../src/world-state-db/merkle_trees.ts | 22 +- yarn-project/yarn-project-base/Dockerfile | 21 +- yarn-project/yarn.lock | 1011 ++++++++++++++++- 147 files changed, 3559 insertions(+), 1656 deletions(-) rename barretenberg/cpp/src/barretenberg/common/{mem.cpp => bbmalloc.cpp} (80%) create mode 100644 barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp delete mode 100644 barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp rename yarn-project/circuits.js/out => barretenberg/scripts/exports.json (100%) delete mode 100644 barretenberg/ts/src/barretenberg_api/pedersen.test.ts rename {yarn-project/circuits.js/src/barretenberg/crypto => barretenberg/ts/src}/pedersen/index.ts (100%) create mode 100644 barretenberg/ts/src/pedersen/pedersen.test.ts create mode 100644 barretenberg/ts/src/pedersen/pedersen.ts delete mode 100644 yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts create mode 100644 yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts create mode 100644 yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts create mode 100644 yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts create mode 100644 yarn-project/world-state/src/world-state-db/merkle_tree_db.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 30c3aa2ffb0..35b9bdee375 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1177,6 +1177,7 @@ workflows: requires: - circuits-wasm-linux-clang - l1-contracts + - bb-js <<: *defaults - yarn-project: requires: diff --git a/barretenberg/cpp/src/barretenberg/barretenberg.hpp b/barretenberg/cpp/src/barretenberg/barretenberg.hpp index 30c143a6af6..eaa55743c88 100644 --- a/barretenberg/cpp/src/barretenberg/barretenberg.hpp +++ b/barretenberg/cpp/src/barretenberg/barretenberg.hpp @@ -1,6 +1,7 @@ #pragma once // External Barretenberg C++ API +#include "common/bbmalloc.hpp" #include "common/container.hpp" #include "common/map.hpp" #include "common/mem.hpp" diff --git a/barretenberg/cpp/src/barretenberg/common/mem.cpp b/barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp similarity index 80% rename from barretenberg/cpp/src/barretenberg/common/mem.cpp rename to barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp index d119eaf24a4..d9c061acb12 100644 --- a/barretenberg/cpp/src/barretenberg/common/mem.cpp +++ b/barretenberg/cpp/src/barretenberg/common/bbmalloc.cpp @@ -1,6 +1,5 @@ -#include "./mem.hpp" +#include "./bbmalloc.hpp" #include "./slab_allocator.hpp" -#include "./wasm_export.hpp" WASM_EXPORT void* bbmalloc(size_t size) { diff --git a/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp b/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp new file mode 100644 index 00000000000..6a53df3756e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/common/bbmalloc.hpp @@ -0,0 +1,7 @@ +#pragma once +#include "./wasm_export.hpp" +#include + +WASM_EXPORT void* bbmalloc(size_t size); + +WASM_EXPORT void bbfree(void* ptr); diff --git a/barretenberg/cpp/src/barretenberg/common/mem.hpp b/barretenberg/cpp/src/barretenberg/common/mem.hpp index d97ccd495ea..fe4a6351e9e 100644 --- a/barretenberg/cpp/src/barretenberg/common/mem.hpp +++ b/barretenberg/cpp/src/barretenberg/common/mem.hpp @@ -75,7 +75,4 @@ inline void aligned_free(void* mem) // info("Total allocated space (uordblks): ", minfo.uordblks); // info("Total free space (fordblks): ", minfo.fordblks); // info("Top-most, releasable space (keepcost): ", minfo.keepcost); -// } - -WASM_EXPORT void* bbmalloc(size_t size); -WASM_EXPORT void bbfree(void* ptr); +// } \ No newline at end of file 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 8dc747c3b89..67188995545 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -3,11 +3,16 @@ #include "barretenberg/common/serialize.hpp" #include "pedersen.hpp" -WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) +extern "C" { + +using namespace barretenberg; + +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) { std::vector to_commit; read(inputs_buffer, to_commit); grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); serialize::write(output, pedersen_commitment); +} } \ No newline at end of file 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 3c07abe2c9b..3de155cae2b 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -1,7 +1,12 @@ #pragma once -#include "barretenberg/common/mem.hpp" -#include "barretenberg/common/serialize.hpp" -#include "barretenberg/common/streams.hpp" -#include "barretenberg/common/timer.hpp" +#include "barretenberg/common/wasm_export.hpp" +#include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output); +extern "C" { + +using namespace barretenberg; +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_commitment/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp deleted file mode 100644 index 9892f95c9d6..00000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "c_bind_new.hpp" -#include "../pedersen_hash/pedersen.hpp" -#include "barretenberg/common/serialize.hpp" -#include "pedersen.hpp" - -extern "C" { - -using namespace barretenberg; - -WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) -{ - std::vector to_commit; - read(inputs_buffer, to_commit); - grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); - - serialize::write(output, pedersen_commitment); -} -} \ No newline at end of file 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 deleted file mode 100644 index 84f56c20155..00000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "barretenberg/common/wasm_export.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" - -extern "C" { - -using namespace barretenberg; -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_commitment/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp index 84c5fc2e68f..821f42ac1b1 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/pedersen.test.cpp @@ -1,4 +1,5 @@ #include "pedersen.hpp" +#include "barretenberg/common/timer.hpp" #include "barretenberg/crypto/generators/generator_data.hpp" #include @@ -16,4 +17,38 @@ TEST(Pedersen, Commitment) EXPECT_EQ(r, expected); } -} // namespace crypto \ No newline at end of file +TEST(Pedersen, CommitmentWithZero) +{ + auto x = pedersen_commitment::Fq::zero(); + auto y = pedersen_commitment::Fq::one(); + auto r = pedersen_commitment::commit_native({ x, y }); + auto expected = + grumpkin::g1::affine_element(fr(uint256_t("054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402")), + fr(uint256_t("209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126"))); + EXPECT_EQ(r, expected); +} + +TEST(Pedersen, CommitmentProf) +{ + GTEST_SKIP() << "Skipping mini profiler."; + auto x = fr::random_element(); + auto y = fr::random_element(); + Timer t; + for (int i = 0; i < 10000; ++i) { + pedersen_commitment::commit_native({ x, y }); + } + info(t.nanoseconds() / 1000 / 10000); +} + +// Useful for pasting into ts version of pedersen. +TEST(Pedersen, GeneratorPrinter) +{ + GTEST_SKIP() << "Skipping generator-for-ts printer."; + pedersen_commitment::GeneratorContext ctx; + auto generators = ctx.generators->get_default_generators()->get(128); + for (auto g : generators) { + info("[", g.x, "n, ", g.y, "n],"); + } +} + +}; // namespace crypto \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp index 3dd91cb3171..6f51283ed9b 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp @@ -5,12 +5,12 @@ extern "C" { -WASM_EXPORT void pedersen__hash_with_hash_index(uint8_t const* inputs_buffer, uint32_t hash_index, uint8_t* output) +WASM_EXPORT void pedersen_hash(uint8_t const* inputs_buffer, uint32_t const* hash_index, uint8_t* output) { std::vector to_hash; read(inputs_buffer, to_hash); crypto::GeneratorContext ctx; - ctx.offset = static_cast(hash_index); + ctx.offset = static_cast(ntohl(*hash_index)); auto r = crypto::pedersen_hash::hash(to_hash, ctx); barretenberg::fr::serialize_to_buffer(r, output); } 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 fdd7d51797a..869418762d2 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp @@ -7,7 +7,5 @@ extern "C" { using namespace barretenberg; -WASM_EXPORT void pedersen_hash_with_hash_index(fr::vec_in_buf inputs_buffer, - uint32_t const* hash_index, - fr::out_buf output); +WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp deleted file mode 100644 index 6a157492d34..00000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "barretenberg/common/mem.hpp" -#include "barretenberg/common/serialize.hpp" -#include "c_bind.hpp" -#include "pedersen.hpp" - -extern "C" { - -WASM_EXPORT void pedersen_hash_with_hash_index(uint8_t const* inputs_buffer, - uint32_t const* hash_index, - uint8_t* output) -{ - std::vector to_hash; - read(inputs_buffer, to_hash); - auto r = crypto::pedersen_hash::hash(to_hash, ntohl(*hash_index)); - barretenberg::fr::serialize_to_buffer(r, output); -} -} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index ce31a6928a0..b1ceb606a33 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -1,16 +1,22 @@ +#include "c_bind.hpp" #include "multisig.hpp" #include "schnorr.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +extern "C" { -WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) +using namespace barretenberg; +using affine_element = grumpkin::g1::affine_element; +using multisig = crypto::schnorr::multisig; +using multisig_public_key = typename multisig::MultiSigPublicKey; + +WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) { auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; serialize::write(public_key_buf, pub_key); } -WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) +WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) { // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public // key. @@ -18,31 +24,35 @@ WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* ou serialize::write(output, -account_public_key); } -WASM_EXPORT void construct_signature( - uint8_t const* message, size_t msg_len, uint8_t const* private_key, uint8_t* s, uint8_t* e) +WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, + uint8_t const* private_key, + uint8_t* s, + uint8_t* e) { + auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - auto sig = crypto::schnorr::construct_signature(std::string((char*)message, msg_len), - key_pair); + auto sig = crypto::schnorr::construct_signature(message, key_pair); write(s, sig.s); write(e, sig.e); } -WASM_EXPORT bool verify_signature( - uint8_t const* message, size_t msg_len, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e) +WASM_EXPORT void schnorr_verify_signature( + uint8_t const* message_buf, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e, bool* result) { auto pubk = from_buffer(pub_key); - std::array s, e; + auto message = from_buffer(message_buf); + std::array s; + std::array e; std::copy(sig_s, sig_s + 32, s.begin()); std::copy(sig_e, sig_e + 32, e.begin()); crypto::schnorr::signature sig = { s, e }; - return crypto::schnorr::verify_signature( - std::string((char*)message, msg_len), pubk, sig); + *result = + crypto::schnorr::verify_signature(message, pubk, sig); } -WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) +WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) { using multisig = crypto::schnorr::multisig; using multisig_public_key = typename multisig::MultiSigPublicKey; @@ -55,23 +65,26 @@ WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, serialize::write(multisig_pubkey_buf, agg_pubkey); } -WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, - uint8_t* combined_key_buf) +WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, + affine_element::out_buf combined_key_buf, + bool* success) { using multisig = crypto::schnorr::multisig; - std::vector pubkeys = - from_buffer>(signer_pubkey_buf); + auto pubkeys = from_buffer>(signer_pubkey_buf); + + auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); - if (auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); combined_key) { + if (combined_key) { serialize::write(combined_key_buf, *combined_key); - return true; + *success = true; } else { - return false; + serialize::write(combined_key_buf, affine_element::one()); + *success = false; } } -WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, - uint8_t* round_one_private_output_buf) +WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, + uint8_t* round_one_private_output_buf) { using multisig = crypto::schnorr::multisig; @@ -80,15 +93,16 @@ WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_ serialize::write(round_one_private_output_buf, private_output); } -WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, - size_t msg_len, - uint8_t* const private_key, - uint8_t* const signer_round_one_private_buf, - uint8_t* const signer_pubkeys_buf, - uint8_t* const round_one_public_buf, - uint8_t* round_two_buf) +WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* message_buf, + uint8_t const* private_key, + uint8_t const* signer_round_one_private_buf, + uint8_t const* signer_pubkeys_buf, + uint8_t const* round_one_public_buf, + uint8_t* round_two_buf, + bool* success) { using multisig = crypto::schnorr::multisig; + auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; @@ -97,39 +111,40 @@ WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, auto round_one_outputs = from_buffer>(round_one_public_buf); auto round_one_private = from_buffer(signer_round_one_private_buf); - auto round_two_output = multisig::construct_signature_round_2( - std::string((char*)message, msg_len), key_pair, round_one_private, signer_pubkeys, round_one_outputs); + auto round_two_output = + multisig::construct_signature_round_2(message, key_pair, round_one_private, signer_pubkeys, round_one_outputs); if (round_two_output.has_value()) { write(round_two_buf, *round_two_output); - return true; + *success = true; } else { - return false; + *success = false; } } -WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message, - size_t msg_len, - uint8_t* const signer_pubkeys_buf, - uint8_t* const round_one_buf, - uint8_t* const round_two_buf, - uint8_t* s, - uint8_t* e) +WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, + uint8_t const* signer_pubkeys_buf, + uint8_t const* round_one_buf, + uint8_t const* round_two_buf, + uint8_t* s, + uint8_t* e, + bool* success) { using multisig = crypto::schnorr::multisig; + auto message = from_buffer(message_buf); auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); auto round_one_outputs = from_buffer>(round_one_buf); auto round_two_outputs = from_buffer>(round_two_buf); - auto sig = multisig::combine_signatures( - std::string((char*)message, msg_len), signer_pubkeys, round_one_outputs, round_two_outputs); + auto sig = multisig::combine_signatures(message, signer_pubkeys, round_one_outputs, round_two_outputs); if (sig.has_value()) { write(s, (*sig).s); write(e, (*sig).e); - return true; + *success = true; } else { - return false; + *success = false; } } +} diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index b6dc905876c..cb65671fafc 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -39,7 +39,7 @@ WASM_EXPORT void schnorr_multisig_construct_signature_round_2( WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message, multisig::MultiSigPublicKey::vec_in_buf signer_pubkeys_buf, multisig::RoundOnePublicOutput::vec_in_buf round_one_buf, - fr::vec_in_buf round_two_buf, + fq::vec_in_buf round_two_buf, out_buf32 s, out_buf32 e, bool* success); diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp deleted file mode 100644 index b1ceb606a33..00000000000 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "c_bind.hpp" -#include "multisig.hpp" -#include "schnorr.hpp" - -extern "C" { - -using namespace barretenberg; -using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr::multisig; -using multisig_public_key = typename multisig::MultiSigPublicKey; - -WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) -{ - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - serialize::write(public_key_buf, pub_key); -} - -WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) -{ - // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public - // key. - auto account_public_key = from_buffer(public_key_buffer); - serialize::write(output, -account_public_key); -} - -WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, - uint8_t const* private_key, - uint8_t* s, - uint8_t* e) -{ - auto message = from_buffer(message_buf); - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - auto sig = crypto::schnorr::construct_signature(message, key_pair); - write(s, sig.s); - write(e, sig.e); -} - -WASM_EXPORT void schnorr_verify_signature( - uint8_t const* message_buf, uint8_t const* pub_key, uint8_t const* sig_s, uint8_t const* sig_e, bool* result) -{ - auto pubk = from_buffer(pub_key); - auto message = from_buffer(message_buf); - std::array s; - std::array e; - std::copy(sig_s, sig_s + 32, s.begin()); - std::copy(sig_e, sig_e + 32, e.begin()); - crypto::schnorr::signature sig = { s, e }; - *result = - crypto::schnorr::verify_signature(message, pubk, sig); -} - -WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) -{ - using multisig = crypto::schnorr::multisig; - using multisig_public_key = typename multisig::MultiSigPublicKey; - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - - auto agg_pubkey = multisig_public_key(key_pair); - - serialize::write(multisig_pubkey_buf, agg_pubkey); -} - -WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, - affine_element::out_buf combined_key_buf, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - auto pubkeys = from_buffer>(signer_pubkey_buf); - - auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); - - if (combined_key) { - serialize::write(combined_key_buf, *combined_key); - *success = true; - } else { - serialize::write(combined_key_buf, affine_element::one()); - *success = false; - } -} - -WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, - uint8_t* round_one_private_output_buf) -{ - using multisig = crypto::schnorr::multisig; - - auto [public_output, private_output] = multisig::construct_signature_round_1(); - serialize::write(round_one_public_output_buf, public_output); - serialize::write(round_one_private_output_buf, private_output); -} - -WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* message_buf, - uint8_t const* private_key, - uint8_t const* signer_round_one_private_buf, - uint8_t const* signer_pubkeys_buf, - uint8_t const* round_one_public_buf, - uint8_t* round_two_buf, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - auto message = from_buffer(message_buf); - auto priv_key = from_buffer(private_key); - grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - - auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); - auto round_one_outputs = from_buffer>(round_one_public_buf); - - auto round_one_private = from_buffer(signer_round_one_private_buf); - auto round_two_output = - multisig::construct_signature_round_2(message, key_pair, round_one_private, signer_pubkeys, round_one_outputs); - - if (round_two_output.has_value()) { - write(round_two_buf, *round_two_output); - *success = true; - } else { - *success = false; - } -} - -WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, - uint8_t const* signer_pubkeys_buf, - uint8_t const* round_one_buf, - uint8_t const* round_two_buf, - uint8_t* s, - uint8_t* e, - bool* success) -{ - using multisig = crypto::schnorr::multisig; - - auto message = from_buffer(message_buf); - auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); - auto round_one_outputs = from_buffer>(round_one_buf); - auto round_two_outputs = from_buffer>(round_two_buf); - - auto sig = multisig::combine_signatures(message, signer_pubkeys, round_one_outputs, round_two_outputs); - - if (sig.has_value()) { - write(s, (*sig).s); - write(e, (*sig).e); - *success = true; - } else { - *success = false; - } -} -} diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp index a1b3e58cf4a..e60c8c4731f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp @@ -1,6 +1,6 @@ #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/common/test.hpp" -#include "barretenberg/crypto/pedersen_commitment/c_bind_new.hpp" +#include "barretenberg/crypto/pedersen_commitment/c_bind.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" diff --git a/barretenberg/exports.json b/barretenberg/exports.json index ab37a26ec83..0c6856e3c87 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -1,6 +1,6 @@ [ { - "functionName": "pedersen___commit", + "functionName": "pedersen_commit", "inArgs": [ { "name": "inputs_buffer", @@ -16,7 +16,7 @@ "isAsync": false }, { - "functionName": "pedersen_hash_with_hash_index", + "functionName": "pedersen_hash", "inArgs": [ { "name": "inputs_buffer", @@ -255,7 +255,7 @@ }, { "name": "round_two_buf", - "type": "fr::vec_in_buf" + "type": "fq::vec_in_buf" } ], "outArgs": [ diff --git a/barretenberg/scripts/c_bind_files.txt b/barretenberg/scripts/c_bind_files.txt index c0fe8b60f46..a84057549ba 100644 --- a/barretenberg/scripts/c_bind_files.txt +++ b/barretenberg/scripts/c_bind_files.txt @@ -1,4 +1,4 @@ -./cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp +./cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp ./cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp ./cpp/src/barretenberg/crypto/blake2s/c_bind.hpp ./cpp/src/barretenberg/crypto/schnorr/c_bind.hpp diff --git a/barretenberg/scripts/decls_json.py b/barretenberg/scripts/decls_json.py index d01fba39dd2..2b1753220ba 100755 --- a/barretenberg/scripts/decls_json.py +++ b/barretenberg/scripts/decls_json.py @@ -33,13 +33,6 @@ def process_files(files: List[str]) -> List[dict]: idx = clang.cindex.Index.create() for path in files: tu = idx.parse(path, args=[ - '-isystem', '/usr/include/c++/10', - '-isystem', '/usr/include/x86_64-linux-gnu/c++/10', - '-isystem', '/usr/include/c++/10/backward', - '-isystem', '/usr/lib/llvm-15/lib/clang/15.0.7/include', - '-isystem', '/usr/local/include', - '-isystem', '/usr/include/x86_64-linux-gnu', - '-isystem', '/usr/include', "-I./cpp/src", '-std=gnu++20', '-Wall', '-Wextra']) for diag in tu.diagnostics: diff --git a/yarn-project/circuits.js/out b/barretenberg/scripts/exports.json similarity index 100% rename from yarn-project/circuits.js/out rename to barretenberg/scripts/exports.json diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index d7e5af84411..5612d740654 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -18,12 +18,12 @@ export class BarretenbergApi { } async pedersenCommit(inputsBuffer: Fr[]): Promise { - const result = await this.binder.callWasmExport('pedersen___commit', [inputsBuffer], [Point]); + const result = await this.binder.callWasmExport('pedersen_commit', [inputsBuffer], [Point]); return result[0]; } - async pedersenHashWithHashIndex(inputsBuffer: Fr[], hashIndex: number): Promise { - const result = await this.binder.callWasmExport('pedersen_hash_with_hash_index', [inputsBuffer, hashIndex], [Fr]); + async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { + const result = await this.binder.callWasmExport('pedersen_hash', [inputsBuffer, hashIndex], [Fr]); return result[0]; } @@ -111,7 +111,7 @@ export class BarretenbergApi { message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], - roundTwoBuf: Fr[], + roundTwoBuf: Fq[], ): Promise<[Buffer32, Buffer32, boolean]> { const result = await this.binder.callWasmExport( 'schnorr_multisig_combine_signatures', diff --git a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts b/barretenberg/ts/src/barretenberg_api/pedersen.test.ts deleted file mode 100644 index 1a3c2379989..00000000000 --- a/barretenberg/ts/src/barretenberg_api/pedersen.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Barretenberg } from '../barretenberg/index.js'; -import { Fr, Point } from '../types/index.js'; - -describe('pedersen', () => { - let api: Barretenberg; - - beforeAll(async () => { - api = await Barretenberg.new(1); - }, 30000); - - afterAll(async () => { - await api.destroy(); - }); - - it('pedersenHashWithHashIndex', async () => { - const result = await api.pedersenHashWithHashIndex([new Fr(4n), new Fr(8n)], 7); - expect(result).toEqual(new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n)); - }); - - it('pedersenCommit', async () => { - const result = await api.pedersenCommit([new Fr(4n), new Fr(8n), new Fr(12n)]); - expect(result).toEqual( - new Point( - new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n), - new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n), - ), - ); - }); -}); diff --git a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts index 6b161cfb1c9..e98e5583afa 100644 --- a/barretenberg/ts/src/barretenberg_api/schnorr.test.ts +++ b/barretenberg/ts/src/barretenberg_api/schnorr.test.ts @@ -1,5 +1,5 @@ import { TextEncoder } from 'util'; -import { Buffer128, Buffer32, Fr, Point } from '../types/index.js'; +import { Buffer128, Buffer32, Fq, Fr, Point } from '../types/index.js'; import { Barretenberg } from '../barretenberg/index.js'; import { asyncMap } from '../async_map/index.js'; @@ -48,7 +48,7 @@ describe('schnorr', () => { it('should create + verify multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fr.random()); + const pks = [...Array(numSigners)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one @@ -84,7 +84,7 @@ describe('schnorr', () => { }); it('should identify invalid multi signature', async () => { - const pks = [...Array(3)].map(() => Fr.random()); + const pks = [...Array(3)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); const [combinedKey] = await api.schnorrMultisigValidateAndCombineSignerPubkeys(pubKeys); @@ -95,7 +95,7 @@ describe('schnorr', () => { it('should not construct invalid multi signature', async () => { // set up multisig accounts const numSigners = 7; - const pks = [...Array(numSigners)].map(() => Fr.random()); + const pks = [...Array(numSigners)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // round one @@ -164,7 +164,7 @@ describe('schnorr', () => { }); it('should not create combined key from public keys containing invalid key', async () => { - const pks = [...Array(5)].map(() => Fr.random()); + const pks = [...Array(5)].map(() => Fq.random()); const pubKeys = await asyncMap(pks, pk => api.schnorrMultisigCreateMultisigPublicKey(pk)); // not a valid point diff --git a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts index bbd27ea4f02..76a5d337353 100644 --- a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_base/index.ts @@ -4,6 +4,10 @@ import { killSelf } from '../helpers/index.js'; const debug = createDebug('bb.js:wasm'); +/** + * Base implementation of BarretenbergWasm. + * Contains code that is common to the "main thread" implementation and the "child thread" implementation. + */ export class BarretenbergWasmBase { protected memStore: { [key: string]: Uint8Array } = {}; protected memory!: WebAssembly.Memory; diff --git a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts index 29365e311b5..9cc157552da 100644 --- a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts @@ -9,6 +9,11 @@ import { BarretenbergWasmBase } from '../barretenberg_wasm_base/index.js'; const debug = createDebug('bb.js:wasm'); +/** + * This is the "main thread" implementation of BarretenbergWasm. + * It spawns a bunch of "child thread" implementations. + * In a browser context, this still runs on a worker, as it will block waiting on child threads. + */ export class BarretenbergWasmMain extends BarretenbergWasmBase { static MAX_THREADS = 32; private workers: Worker[] = []; @@ -102,4 +107,7 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase { } } +/** + * The comlink type that asyncifies the BarretenbergWasmMain api. + */ export type BarretenbergWasmMainWorker = Remote; diff --git a/barretenberg/ts/src/benchmark/timer.ts b/barretenberg/ts/src/benchmark/timer.ts index b74be9819ea..81dfe37f127 100644 --- a/barretenberg/ts/src/benchmark/timer.ts +++ b/barretenberg/ts/src/benchmark/timer.ts @@ -14,7 +14,11 @@ export class Timer { private start: number; constructor() { - this.start = new Date().getTime(); + this.start = performance.now(); + } + + public us() { + return this.ms() * 1000; } /** @@ -25,7 +29,7 @@ export class Timer { * @returns The elapsed time in milliseconds. */ public ms() { - return new Date().getTime() - this.start; + return performance.now() - this.start; } /** @@ -36,6 +40,6 @@ export class Timer { * @returns The elapsed time in seconds. */ public s() { - return (new Date().getTime() - this.start) / 1000; + return this.ms() / 1000; } } diff --git a/barretenberg/ts/src/index.ts b/barretenberg/ts/src/index.ts index 0998072f1de..b088e2a2ce5 100644 --- a/barretenberg/ts/src/index.ts +++ b/barretenberg/ts/src/index.ts @@ -1,3 +1,4 @@ export { Crs } from './crs/index.js'; export { Barretenberg } from './barretenberg/index.js'; export { RawBuffer, Fr } from './types/index.js'; +export { Pedersen } from './pedersen/index.js'; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts b/barretenberg/ts/src/pedersen/index.ts similarity index 100% rename from yarn-project/circuits.js/src/barretenberg/crypto/pedersen/index.ts rename to barretenberg/ts/src/pedersen/index.ts diff --git a/barretenberg/ts/src/pedersen/pedersen.test.ts b/barretenberg/ts/src/pedersen/pedersen.test.ts new file mode 100644 index 00000000000..12721e3d630 --- /dev/null +++ b/barretenberg/ts/src/pedersen/pedersen.test.ts @@ -0,0 +1,33 @@ +import { Pedersen } from './pedersen.js'; +import { Timer } from '../benchmark/timer.js'; +import { Fr } from '../types/index.js'; + +describe('pedersen sync', () => { + it('pedersenHash', async () => { + const pedersen = await Pedersen.new(); + const result = pedersen.pedersenHash([new Fr(4n).toBuffer(), new Fr(8n).toBuffer()], 7); + expect(result).toEqual( + new Fr(2152386650411553803409271316104075950536496387580531018130718456431861859990n).toBuffer(), + ); + }); + + it('pedersenCommit', async () => { + const pedersen = await Pedersen.new(); + const result = pedersen.pedersenCommit([new Fr(4n).toBuffer(), new Fr(8n).toBuffer(), new Fr(12n).toBuffer()]); + expect(result).toEqual([ + new Fr(18374309251862457296563484909553154519357910650678202211610516068880120638872n).toBuffer(), + new Fr(2572141322478528249692953821523229170092797347760799983831061874108357705739n).toBuffer(), + ]); + }); + + it.skip('pedersenCommit perf test', async () => { + const pedersen = await Pedersen.new(); + const loops = 1000; + const fields = Array.from({ length: loops * 2 }).map(() => Fr.random()); + const t = new Timer(); + for (let i = 0; i < loops; ++i) { + pedersen.pedersenCommit([fields[i * 2].toBuffer(), fields[i * 2 + 1].toBuffer()]); + } + console.log(t.us() / loops); + }); +}); diff --git a/barretenberg/ts/src/pedersen/pedersen.ts b/barretenberg/ts/src/pedersen/pedersen.ts new file mode 100644 index 00000000000..be9028cbd86 --- /dev/null +++ b/barretenberg/ts/src/pedersen/pedersen.ts @@ -0,0 +1,57 @@ +import { BarretenbergWasmMain } from '../barretenberg_wasm/barretenberg_wasm_main/index.js'; +import { numToUInt32BE, serializeBufferArrayToVector } from '../serialize/serialize.js'; + +export class Pedersen { + constructor(public wasm: BarretenbergWasmMain) {} + + static async new() { + const wasm = new BarretenbergWasmMain(); + await wasm.init(1); + return new Pedersen(wasm); + } + + pedersenHash(inputs: Uint8Array[], hashIndex = 0) { + const SCRATCH_SPACE_SIZE = 1024; + + const data = serializeBufferArrayToVector(inputs); + + let inputPtr = 0; + if (data.length > SCRATCH_SPACE_SIZE - 4) { + inputPtr = this.wasm.call('bbmalloc', data.length); + } + this.wasm.writeMemory(inputPtr, data); + this.wasm.writeMemory(SCRATCH_SPACE_SIZE - 4, numToUInt32BE(hashIndex)); + + const outputPtr = 0; + this.wasm.call('pedersen_hash', inputPtr, SCRATCH_SPACE_SIZE - 4, outputPtr); + const hashOutput = this.wasm.getMemorySlice(0, 32); + + if (inputPtr !== 0) { + this.wasm.call('bbfree', inputPtr); + } + + return hashOutput; + } + + pedersenCommit(inputs: Uint8Array[]) { + const SCRATCH_SPACE_SIZE = 1024; + + const data = serializeBufferArrayToVector(inputs); + + let inputPtr = 0; + if (data.length > SCRATCH_SPACE_SIZE) { + inputPtr = this.wasm.call('bbmalloc', data.length); + } + this.wasm.writeMemory(inputPtr, data); + + const outputPtr = 0; + this.wasm.call('pedersen_commit', inputPtr, outputPtr); + const hashOutput = this.wasm.getMemorySlice(0, 64); + + if (inputPtr !== 0) { + this.wasm.call('bbfree', inputPtr); + } + + return [hashOutput.slice(0, 32), hashOutput.slice(32, 64)]; + } +} diff --git a/barretenberg/ts/src/types/fields.ts b/barretenberg/ts/src/types/fields.ts index a0b095813d3..a54cbe5a328 100644 --- a/barretenberg/ts/src/types/fields.ts +++ b/barretenberg/ts/src/types/fields.ts @@ -7,10 +7,16 @@ export class Fr { static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n; static MAX_VALUE = this.MODULUS - 1n; static SIZE_IN_BYTES = 32; - - constructor(public readonly value: bigint) { - if (value > Fr.MAX_VALUE) { - throw new Error(`Fr out of range ${value}.`); + value: Uint8Array; + + constructor(value: Uint8Array | bigint) { + if (typeof value === 'bigint') { + if (value > Fr.MAX_VALUE) { + throw new Error(`Fr out of range ${value}.`); + } + this.value = toBufferBE(value); + } else { + this.value = value; } } @@ -21,7 +27,7 @@ export class Fr { static fromBuffer(buffer: Uint8Array | BufferReader) { const reader = BufferReader.asReader(buffer); - return new this(toBigIntBE(reader.readBytes(this.SIZE_IN_BYTES))); + return new this(reader.readBytes(this.SIZE_IN_BYTES)); } static fromBufferReduce(buffer: Uint8Array | BufferReader) { @@ -34,7 +40,7 @@ export class Fr { } toBuffer() { - return toBufferBE(this.value, Fr.SIZE_IN_BYTES); + return this.value; } toString() { @@ -42,11 +48,11 @@ export class Fr { } equals(rhs: Fr) { - return this.value === rhs.value; + return this.value.every((v, i) => v === rhs.value[i]); } isZero() { - return this.value === 0n; + return this.value.every(v => v === 0); } } diff --git a/build-system/scripts/add_timestamps b/build-system/scripts/add_timestamps index 4eeab6f56db..8b658925ba5 100755 --- a/build-system/scripts/add_timestamps +++ b/build-system/scripts/add_timestamps @@ -1,4 +1,4 @@ #!/bin/bash while IFS= read -r line; do - echo "$(date '+%Y-%m-%d %H:%M:%S') $line" + printf '%(%Y-%m-%d %H:%M:%S)T %s\n' -1 "$line" done diff --git a/build-system/scripts/cond_spot_run_compose b/build-system/scripts/cond_spot_run_compose index b10cc9decf5..1d8b5c66788 100755 --- a/build-system/scripts/cond_spot_run_compose +++ b/build-system/scripts/cond_spot_run_compose @@ -7,4 +7,4 @@ CPUS=$2 shift 2 export TAG_POSTFIX=$JOB_NAME -cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ +cond_spot_run_script $REPOSITORY $CPUS cond_run_compose $REPOSITORY $@ 2>&1 | add_timestamps diff --git a/build-system/scripts/spot_run_script b/build-system/scripts/spot_run_script index 69707de660f..33a0fc3dfb0 100755 --- a/build-system/scripts/spot_run_script +++ b/build-system/scripts/spot_run_script @@ -11,6 +11,7 @@ set -eu CONTENT_HASH=$1 CPUS=$2 shift 2 +IP= # On any sort of exit (error or not). function on_exit { @@ -38,5 +39,5 @@ if [ -z "$IP" ]; then exit 1 fi -# Run script remotely on spot instance, capturing success or failure. +# Run script remotely on spot instance, returning success or failure. remote_run_script $IP $@ \ No newline at end of file diff --git a/build_manifest.yml b/build_manifest.yml index cd3606db039..c8ef6d2c53f 100644 --- a/build_manifest.yml +++ b/build_manifest.yml @@ -78,6 +78,7 @@ yarn-project-base: dependencies: - circuits-wasm-linux-clang - l1-contracts + - bb.js yarn-project: buildDir: yarn-project diff --git a/yarn-project/acir-simulator/src/acvm/serialize.ts b/yarn-project/acir-simulator/src/acvm/serialize.ts index 18776741e40..bfb63d3ffbd 100644 --- a/yarn-project/acir-simulator/src/acvm/serialize.ts +++ b/yarn-project/acir-simulator/src/acvm/serialize.ts @@ -187,12 +187,12 @@ export function toAcvmCallPrivateStackItem(item: PrivateCallStackItem): ACVMFiel * @param item - The public call stack item to serialize to be passed onto Noir. * @returns The fields expected by the enqueue_public_function_call_oracle Aztec.nr function. */ -export async function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): Promise { +export function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): ACVMField[] { return [ toACVMField(item.contractAddress), ...toACVMFunctionData(item.functionData), ...toACVMCallContext(item.callContext), - toACVMField(await item.getArgsHash()), + toACVMField(item.getArgsHash()), ]; } diff --git a/yarn-project/acir-simulator/src/client/client_execution_context.ts b/yarn-project/acir-simulator/src/client/client_execution_context.ts index 5236304a716..579771f109d 100644 --- a/yarn-project/acir-simulator/src/client/client_execution_context.ts +++ b/yarn-project/acir-simulator/src/client/client_execution_context.ts @@ -1,6 +1,5 @@ import { CallContext, - CircuitsWasm, ContractDeploymentData, FunctionData, FunctionSelector, @@ -172,7 +171,7 @@ export class ClientExecutionContext extends ViewDataOracle { * @param args - Arguments to pack */ public packArguments(args: Fr[]): Promise { - return this.packedArgsCache.pack(args); + return Promise.resolve(this.packedArgsCache.pack(args)); } /** @@ -223,11 +222,10 @@ export class ClientExecutionContext extends ViewDataOracle { .join(', ')}`, ); - const wasm = await CircuitsWasm.get(); notes.forEach(n => { if (n.index !== undefined) { - const siloedNoteHash = siloCommitment(wasm, n.contractAddress, n.innerNoteHash); - const uniqueSiloedNoteHash = computeUniqueCommitment(wasm, n.nonce, siloedNoteHash); + const siloedNoteHash = siloCommitment(n.contractAddress, n.innerNoteHash); + const uniqueSiloedNoteHash = computeUniqueCommitment(n.nonce, siloedNoteHash); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) // Should always be uniqueSiloedNoteHash when publicly created notes include nonces. const noteHashForReadRequest = n.nonce.isZero() ? siloedNoteHash : uniqueSiloedNoteHash; @@ -269,8 +267,9 @@ export class ClientExecutionContext extends ViewDataOracle { * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address). * @param innerNoteHash - The inner note hash of the new note. */ - public async notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) { - await this.noteCache.nullifyNote(this.contractAddress, innerNullifier, innerNoteHash); + public notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr) { + this.noteCache.nullifyNote(this.contractAddress, innerNullifier, innerNoteHash); + return Promise.resolve(); } /** diff --git a/yarn-project/acir-simulator/src/client/execution_note_cache.ts b/yarn-project/acir-simulator/src/client/execution_note_cache.ts index 9ed21b0cb80..de471d914f1 100644 --- a/yarn-project/acir-simulator/src/client/execution_note_cache.ts +++ b/yarn-project/acir-simulator/src/client/execution_note_cache.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, EMPTY_NULLIFIED_COMMITMENT } from '@aztec/circuits.js'; +import { EMPTY_NULLIFIED_COMMITMENT } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/abis'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -41,9 +41,8 @@ export class ExecutionNoteCache { * @param innerNoteHash - Inner note hash of the note. If this value equals EMPTY_NULLIFIED_COMMITMENT, it means the * note being nullified is from a previous transaction (and thus not a new note). */ - public async nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, innerNoteHash: Fr) { - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, contractAddress, innerNullifier); + public nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, innerNoteHash: Fr) { + const siloedNullifier = siloNullifier(contractAddress, innerNullifier); const nullifiers = this.getNullifiers(contractAddress); nullifiers.add(siloedNullifier.value); this.nullifiers.set(contractAddress.toBigInt(), nullifiers); diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index 2b20f2fd241..61ac920141e 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -21,11 +21,11 @@ import { computeVarArgsHash, siloCommitment, } from '@aztec/circuits.js/abis'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { makeContractDeploymentData } from '@aztec/circuits.js/factories'; import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { asyncMap } from '@aztec/foundation/async-map'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -57,7 +57,6 @@ jest.setTimeout(60_000); const createMemDown = () => (memdown as any)() as MemDown; describe('Private Execution test suite', () => { - let circuitsWasm: CircuitsWasm; let oracle: MockProxy; let acirSimulator: AcirSimulator; @@ -87,7 +86,7 @@ describe('Private Execution test suite', () => { contractDeploymentData: ContractDeploymentData.empty(), }; - const runSimulator = async ({ + const runSimulator = ({ artifact, args = [], msgSender = AztecAddress.ZERO, @@ -102,7 +101,7 @@ describe('Private Execution test suite', () => { args?: any[]; txContext?: Partial>; }) => { - const packedArguments = await PackedArguments.fromArgs(encodeArguments(artifact, args), circuitsWasm); + const packedArguments = PackedArguments.fromArgs(encodeArguments(artifact, args)); const functionData = FunctionData.fromAbi(artifact); const txRequest = TxExecutionRequest.from({ origin: contractAddress, @@ -128,7 +127,7 @@ describe('Private Execution test suite', () => { } if (!trees[name]) { const db = levelup(createMemDown()); - const pedersen = new Pedersen(circuitsWasm); + const pedersen = new Pedersen(); trees[name] = await newTree(StandardTree, db, pedersen, name, treeHeights[name]); } await trees[name].appendLeaves(leaves.map(l => l.toBuffer())); @@ -143,16 +142,9 @@ describe('Private Execution test suite', () => { return trees[name]; }; - const hashFields = (data: Fr[]) => - Fr.fromBuffer( - pedersenHashInputs( - circuitsWasm, - data.map(f => f.toBuffer()), - ), - ); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); logger = createDebugLogger('aztec:test:private_execution'); ownerCompleteAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); @@ -202,7 +194,7 @@ describe('Private Execution test suite', () => { // array index at the output of the final kernel/ordering circuit are used to derive nonce via: // `hash(firstNullifier, noteHashIndex)` const noteHashIndex = Math.floor(Math.random()); // mock index in TX's final newNoteHashes array - const nonce = computeCommitmentNonce(circuitsWasm, mockFirstNullifier, noteHashIndex); + const nonce = computeCommitmentNonce(mockFirstNullifier, noteHashIndex); const note = new Note([new Fr(amount), owner.toField(), Fr.random()]); const innerNoteHash = hashFields(note.items); return { @@ -235,7 +227,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; - expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); const newCommitments = result.callStackItem.publicInputs.newCommitments.filter(field => !field.equals(Fr.ZERO)); expect(newCommitments).toHaveLength(1); @@ -253,7 +245,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const newNote = result.newNotes[0]; - expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(newNote.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); const newCommitments = result.callStackItem.publicInputs.newCommitments.filter(field => !field.equals(Fr.ZERO)); expect(newCommitments).toHaveLength(1); @@ -268,8 +260,8 @@ describe('Private Execution test suite', () => { const amountToTransfer = 100n; const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); - const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); + const recipientStorageSlot = computeSlotForMapping(new Fr(1n), recipient.toField()); const notes = [buildNote(60n, owner, storageSlot), buildNote(80n, owner, storageSlot)]; oracle.getNotes.mockResolvedValue(notes); @@ -315,7 +307,7 @@ describe('Private Execution test suite', () => { const balance = 160n; const artifact = getFunctionArtifact(StatefulTestContractArtifact, 'destroy_and_create'); - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const notes = [buildNote(balance, owner, storageSlot)]; oracle.getNotes.mockResolvedValue(notes); @@ -383,7 +375,7 @@ describe('Private Execution test suite', () => { let argsHash: Fr; let testCodeGenArtifact: FunctionArtifact; - beforeAll(async () => { + beforeAll(() => { // These args should match the ones hardcoded in importer contract // eslint-disable-next-line camelcase const dummyNote = { amount: 1, secret_hash: 2 }; @@ -392,7 +384,7 @@ describe('Private Execution test suite', () => { args = [1, true, 1, [1, 2], dummyNote, deepStruct]; testCodeGenArtifact = getFunctionArtifact(TestContractArtifact, 'test_code_gen'); const serializedArgs = encodeArguments(testCodeGenArtifact, args); - argsHash = await computeVarArgsHash(await CircuitsWasm.get(), serializedArgs); + argsHash = computeVarArgsHash(serializedArgs); }); it('test function should be directly callable', async () => { @@ -442,7 +434,7 @@ describe('Private Execution test suite', () => { const secretForL1ToL2MessageConsumption = new Fr(1n); const secretHashForRedeemingNotes = new Fr(2n); const canceller = EthAddress.random(); - const preimage = await buildL1ToL2Message( + const preimage = buildL1ToL2Message( getFunctionSelector('mint_private(bytes32,uint256,address)').substring(2), [secretHashForRedeemingNotes, new Fr(bridgedAmount), canceller.toField()], contractAddress, @@ -479,14 +471,13 @@ describe('Private Execution test suite', () => { const amount = 100n; const artifact = getFunctionArtifact(TokenContractArtifact, 'redeem_shield'); - const wasm = await CircuitsWasm.get(); const secret = new Fr(1n); - const secretHash = computeSecretMessageHash(wasm, secret); + const secretHash = computeSecretMessageHash(secret); const note = new Note([new Fr(amount), secretHash]); const noteHash = hashFields(note.items); const storageSlot = new Fr(5); const innerNoteHash = hashFields([storageSlot, noteHash]); - const siloedNoteHash = siloCommitment(wasm, contractAddress, innerNoteHash); + const siloedNoteHash = siloCommitment(contractAddress, innerNoteHash); oracle.getNotes.mockResolvedValue([ { contractAddress, @@ -560,7 +551,7 @@ describe('Private Execution test suite', () => { const publicCallRequestHash = computeCallStackItemHash( await CircuitsWasm.get(), - await publicCallRequest.toPublicCallStackItem(), + publicCallRequest.toPublicCallStackItem(), ); expect(result.enqueuedPublicFunctionCalls).toHaveLength(1); @@ -606,7 +597,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const noteAndSlot = result.newNotes[0]; - expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); @@ -614,7 +605,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const innerNoteHash = await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, noteAndSlot.note); expect(commitment).toEqual(innerNoteHash); @@ -677,7 +668,7 @@ describe('Private Execution test suite', () => { expect(execInsert.newNotes).toHaveLength(1); const noteAndSlot = execInsert.newNotes[0]; - expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); @@ -687,7 +678,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); const innerNoteHash = await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, noteAndSlot.note); expect(commitment).toEqual(innerNoteHash); @@ -725,7 +716,7 @@ describe('Private Execution test suite', () => { expect(result.newNotes).toHaveLength(1); const noteAndSlot = result.newNotes[0]; - expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm)); + expect(noteAndSlot.storageSlot).toEqual(computeSlotForMapping(new Fr(1n), owner.toField())); expect(noteAndSlot.note.items[0]).toEqual(new Fr(amountToTransfer)); @@ -733,7 +724,7 @@ describe('Private Execution test suite', () => { expect(newCommitments).toHaveLength(1); const commitment = newCommitments[0]; - const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField(), circuitsWasm); + const storageSlot = computeSlotForMapping(new Fr(1n), owner.toField()); expect(commitment).toEqual( await acirSimulator.computeInnerNoteHash(contractAddress, storageSlot, noteAndSlot.note), ); @@ -759,7 +750,7 @@ describe('Private Execution test suite', () => { artifact.returnTypes = [{ kind: 'array', length: 2, type: { kind: 'field' } }]; // Generate a partial address, pubkey, and resulting address - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); const args = [completeAddress.address]; const pubKey = completeAddress.publicKey; diff --git a/yarn-project/acir-simulator/src/client/simulator.test.ts b/yarn-project/acir-simulator/src/client/simulator.test.ts index d1b5cade92f..e24d2de37a2 100644 --- a/yarn-project/acir-simulator/src/client/simulator.test.ts +++ b/yarn-project/acir-simulator/src/client/simulator.test.ts @@ -1,8 +1,8 @@ -import { CircuitsWasm, CompleteAddress } from '@aztec/circuits.js'; +import { CompleteAddress } from '@aztec/circuits.js'; import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { ABIParameterVisibility } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { TokenContractArtifact } from '@aztec/noir-contracts/artifacts'; import { Note } from '@aztec/types'; @@ -16,22 +16,13 @@ import { AcirSimulator } from './simulator.js'; describe('Simulator', () => { let oracle: MockProxy; let simulator: AcirSimulator; - let circuitsWasm: CircuitsWasm; let ownerCompleteAddress: CompleteAddress; let owner: AztecAddress; const ownerPk = GrumpkinScalar.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); - const hashFields = (data: Fr[]) => - Fr.fromBuffer( - pedersenHashInputs( - circuitsWasm, - data.map(f => f.toBuffer()), - ), - ); + const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); - ownerCompleteAddress = await CompleteAddress.fromPrivateKeyAndPartialAddress(ownerPk, Fr.random()); owner = ownerCompleteAddress.address; }); @@ -58,8 +49,8 @@ describe('Simulator', () => { const note = createNote(); const valueNoteHash = hashFields(note.items); const innerNoteHash = hashFields([storageSlot, valueNoteHash]); - const siloedNoteHash = siloCommitment(circuitsWasm, contractAddress, innerNoteHash); - const uniqueSiloedNoteHash = computeUniqueCommitment(circuitsWasm, nonce, siloedNoteHash); + const siloedNoteHash = siloCommitment(contractAddress, innerNoteHash); + const uniqueSiloedNoteHash = computeUniqueCommitment(nonce, siloedNoteHash); const innerNullifier = hashFields([uniqueSiloedNoteHash, ownerPk.low, ownerPk.high]); const result = await simulator.computeNoteHashAndNullifier(contractAddress, nonce, storageSlot, note); diff --git a/yarn-project/acir-simulator/src/client/view_data_oracle.ts b/yarn-project/acir-simulator/src/client/view_data_oracle.ts index 525f4789628..97825133574 100644 --- a/yarn-project/acir-simulator/src/client/view_data_oracle.ts +++ b/yarn-project/acir-simulator/src/client/view_data_oracle.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; +import { HistoricBlockData, PublicKey } from '@aztec/circuits.js'; import { siloNullifier } from '@aztec/circuits.js/abis'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -99,8 +99,7 @@ export class ViewDataOracle extends TypedOracle { * @returns A boolean indicating whether the nullifier exists in the tree or not. */ public async checkNullifierExists(innerNullifier: Fr) { - const wasm = await CircuitsWasm.get(); - const nullifier = siloNullifier(wasm, this.contractAddress, innerNullifier!); + const nullifier = siloNullifier(this.contractAddress, innerNullifier!); const index = await this.db.getNullifierIndex(nullifier); return index !== undefined; } diff --git a/yarn-project/acir-simulator/src/common/packed_args_cache.ts b/yarn-project/acir-simulator/src/common/packed_args_cache.ts index 245c8580ced..fc120f7daf7 100644 --- a/yarn-project/acir-simulator/src/common/packed_args_cache.ts +++ b/yarn-project/acir-simulator/src/common/packed_args_cache.ts @@ -45,11 +45,11 @@ export class PackedArgsCache { * @param args - The arguments to pack. * @returns The hash of the packed arguments. */ - public async pack(args: Fr[]): Promise { + public pack(args: Fr[]) { if (args.length === 0) { return Fr.zero(); } - const packedArguments = await PackedArguments.fromArgs(args, this.wasm); + const packedArguments = PackedArguments.fromArgs(args); this.cache.set(packedArguments.hash.value, packedArguments.args); return packedArguments.hash; } diff --git a/yarn-project/acir-simulator/src/public/execution.ts b/yarn-project/acir-simulator/src/public/execution.ts index e5a8bf43aea..46b1227a6e4 100644 --- a/yarn-project/acir-simulator/src/public/execution.ts +++ b/yarn-project/acir-simulator/src/public/execution.ts @@ -9,7 +9,6 @@ import { PublicDataUpdateRequest, } from '@aztec/circuits.js'; import { computePublicDataTreeIndex, computePublicDataTreeValue } from '@aztec/circuits.js/abis'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { FunctionL2Logs } from '@aztec/types'; /** @@ -71,16 +70,16 @@ export function isPublicExecutionResult( * @param execResult - The topmost execution result. * @returns All public data reads (in execution order). */ -export function collectPublicDataReads(wasm: IWasmModule, execResult: PublicExecutionResult): PublicDataRead[] { +export function collectPublicDataReads(execResult: PublicExecutionResult): PublicDataRead[] { // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed const contractAddress = execResult.execution.contractAddress; const thisExecPublicDataReads = execResult.contractStorageReads.map(read => - contractStorageReadToPublicDataRead(wasm, read, contractAddress), + contractStorageReadToPublicDataRead(read, contractAddress), ); const unsorted = [ ...thisExecPublicDataReads, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(wasm, result)), + ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(result)), ]; return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); } @@ -88,62 +87,51 @@ export function collectPublicDataReads(wasm: IWasmModule, execResult: PublicExec /** * Collect all public storage update requests across all nested executions * and convert them to PublicDataUpdateRequests (to match kernel output). - * @param wasm - A module providing low-level wasm access. * @param execResult - The topmost execution result. * @returns All public data reads (in execution order). */ -export function collectPublicDataUpdateRequests( - wasm: IWasmModule, - execResult: PublicExecutionResult, -): PublicDataUpdateRequest[] { +export function collectPublicDataUpdateRequests(execResult: PublicExecutionResult): PublicDataUpdateRequest[] { // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed const contractAddress = execResult.execution.contractAddress; const thisExecPublicDataUpdateRequests = execResult.contractStorageUpdateRequests.map(update => - contractStorageUpdateRequestToPublicDataUpdateRequest(wasm, update, contractAddress), + contractStorageUpdateRequestToPublicDataUpdateRequest(update, contractAddress), ); const unsorted = [ ...thisExecPublicDataUpdateRequests, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(wasm, result)), + ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(result)), ]; return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); } /** * Convert a Contract Storage Read to a Public Data Read. - * @param wasm - A module providing low-level wasm access. * @param read - the contract storage read to convert * @param contractAddress - the contract address of the read * @returns The public data read. */ -function contractStorageReadToPublicDataRead( - wasm: IWasmModule, - read: ContractStorageRead, - contractAddress: AztecAddress, -): PublicDataRead { +function contractStorageReadToPublicDataRead(read: ContractStorageRead, contractAddress: AztecAddress): PublicDataRead { return new PublicDataRead( - computePublicDataTreeIndex(wasm, contractAddress, read.storageSlot), - computePublicDataTreeValue(wasm, read.currentValue), + computePublicDataTreeIndex(contractAddress, read.storageSlot), + computePublicDataTreeValue(read.currentValue), read.sideEffectCounter!, ); } /** * Convert a Contract Storage Update Request to a Public Data Update Request. - * @param wasm - A module providing low-level wasm access. * @param update - the contract storage update request to convert * @param contractAddress - the contract address of the data update request. * @returns The public data update request. */ function contractStorageUpdateRequestToPublicDataUpdateRequest( - wasm: IWasmModule, update: ContractStorageUpdateRequest, contractAddress: AztecAddress, ): PublicDataUpdateRequest { return new PublicDataUpdateRequest( - computePublicDataTreeIndex(wasm, contractAddress, update.storageSlot), - computePublicDataTreeValue(wasm, update.oldValue), - computePublicDataTreeValue(wasm, update.newValue), + computePublicDataTreeIndex(contractAddress, update.storageSlot), + computePublicDataTreeValue(update.oldValue), + computePublicDataTreeValue(update.newValue), update.sideEffectCounter!, ); } diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 0ac9864e1c2..38ef76b8190 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -1,14 +1,13 @@ import { CallContext, - CircuitsWasm, FunctionData, GlobalVariables, HistoricBlockData, L1_TO_L2_MSG_TREE_HEIGHT, } from '@aztec/circuits.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { @@ -31,17 +30,12 @@ import { PublicExecutor } from './executor.js'; export const createMemDown = () => (memdown as any)() as MemDown; describe('ACIR public execution simulator', () => { - let circuitsWasm: CircuitsWasm; let publicState: MockProxy; let publicContracts: MockProxy; let commitmentsDb: MockProxy; let executor: PublicExecutor; let blockData: HistoricBlockData; - beforeAll(async () => { - circuitsWasm = await CircuitsWasm.get(); - }); - beforeEach(() => { publicState = mock(); publicContracts = mock(); @@ -94,7 +88,7 @@ describe('ACIR public execution simulator', () => { expect(result.returnValues[0]).toEqual(new Fr(1n)); - const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField(), circuitsWasm); + const recipientBalanceStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField()); const totalSupplyStorageSlot = new Fr(4n); const expectedBalance = new Fr(previousBalance.value + mintAmount); @@ -116,7 +110,7 @@ describe('ACIR public execution simulator', () => { ]); const mintersStorageSlot = new Fr(2n); - const isMinterStorageSlot = computeSlotForMapping(mintersStorageSlot, msgSender.toField(), circuitsWasm); + const isMinterStorageSlot = computeSlotForMapping(mintersStorageSlot, msgSender.toField()); // Note: There is only 1 storage read (for the isMinter value) because the other 2 reads get overwritten by // the updates expect(result.contractStorageReads).toEqual([ @@ -157,8 +151,8 @@ describe('ACIR public execution simulator', () => { isStaticCall: false, }); - recipientStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField(), circuitsWasm); - senderStorageSlot = computeSlotForMapping(new Fr(6n), Fr.fromBuffer(sender.toBuffer()), circuitsWasm); + recipientStorageSlot = computeSlotForMapping(new Fr(6n), recipient.toField()); + senderStorageSlot = computeSlotForMapping(new Fr(6n), Fr.fromBuffer(sender.toBuffer())); publicContracts.getBytecode.mockResolvedValue(Buffer.from(transferArtifact.bytecode, 'base64')); @@ -297,14 +291,12 @@ describe('ACIR public execution simulator', () => { let functionData: FunctionData; let amount: Fr; let params: Fr[]; - let wasm: CircuitsWasm; - beforeEach(async () => { + beforeEach(() => { contractAddress = AztecAddress.random(); functionData = new FunctionData(FunctionSelector.empty(), false, false, false); amount = new Fr(1); params = [amount, new Fr(1)]; - wasm = await CircuitsWasm.get(); }); it('Should be able to create a commitment from the public context', async () => { @@ -334,9 +326,9 @@ describe('ACIR public execution simulator', () => { // Assert the commitment was created expect(result.newCommitments.length).toEqual(1); - const expectedNoteHash = pedersenHashInputs(wasm, [amount.toBuffer(), secretHash.toBuffer()]); + const expectedNoteHash = pedersenHash([amount.toBuffer(), secretHash.toBuffer()]); const storageSlot = new Fr(5); // for pending_shields - const expectedInnerNoteHash = pedersenHashInputs(wasm, [storageSlot.toBuffer(), expectedNoteHash]); + const expectedInnerNoteHash = pedersenHash([storageSlot.toBuffer(), expectedNoteHash]); expect(result.newCommitments[0].toBuffer()).toEqual(expectedInnerNoteHash); }); @@ -364,10 +356,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newL2ToL1Messages.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs( - wasm, - params.map(a => a.toBuffer()), - ); + const expectedNewMessageValue = pedersenHash(params.map(a => a.toBuffer())); expect(result.newL2ToL1Messages[0].toBuffer()).toEqual(expectedNewMessageValue); }); @@ -381,7 +370,7 @@ describe('ACIR public execution simulator', () => { const secret = new Fr(1n); const recipient = AztecAddress.random(); - const preimage = await buildL1ToL2Message( + const preimage = buildL1ToL2Message( getFunctionSelector('mint_public(bytes32,uint256,address)').substring(2), [recipient.toField(), new Fr(bridgedAmount), canceller.toField()], contractAddress, @@ -451,10 +440,7 @@ describe('ACIR public execution simulator', () => { // Assert the l2 to l1 message was created expect(result.newNullifiers.length).toEqual(1); - const expectedNewMessageValue = pedersenHashInputs( - wasm, - params.map(a => a.toBuffer()), - ); + const expectedNewMessageValue = pedersenHash(params.map(a => a.toBuffer())); expect(result.newNullifiers[0].toBuffer()).toEqual(expectedNewMessageValue); }); }); diff --git a/yarn-project/acir-simulator/src/public/public_execution_context.ts b/yarn-project/acir-simulator/src/public/public_execution_context.ts index 4097087e19a..12393742c35 100644 --- a/yarn-project/acir-simulator/src/public/public_execution_context.ts +++ b/yarn-project/acir-simulator/src/public/public_execution_context.ts @@ -93,7 +93,7 @@ export class PublicExecutionContext extends TypedOracle { * @param args - Arguments to pack */ public packArguments(args: Fr[]): Promise { - return this.packedArgsCache.pack(args); + return Promise.resolve(this.packedArgsCache.pack(args)); } /** diff --git a/yarn-project/acir-simulator/src/test/utils.ts b/yarn-project/acir-simulator/src/test/utils.ts index acbb2c668d0..8d076822c50 100644 --- a/yarn-project/acir-simulator/src/test/utils.ts +++ b/yarn-project/acir-simulator/src/test/utils.ts @@ -1,4 +1,4 @@ -import { AztecAddress, CircuitsWasm, EthAddress, Fr } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js'; import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; import { ContractArtifact, FunctionSelector, getFunctionDebugMetadata } from '@aztec/foundation/abi'; import { sha256ToField } from '@aztec/foundation/crypto'; @@ -14,21 +14,19 @@ import { FunctionArtifactWithDebugMetadata } from '../index.js'; * @param secret - The secret to unlock the message. * @returns The L1 to L2 message. */ -export const buildL1ToL2Message = async ( +export const buildL1ToL2Message = ( selector: string, contentPreimage: Fr[], targetContract: AztecAddress, secret: Fr, -): Promise => { - const wasm = await CircuitsWasm.get(); - +) => { // Write the selector into a buffer. const selectorBuf = Buffer.from(selector, 'hex'); const contentBuf = Buffer.concat([selectorBuf, ...contentPreimage.map(field => field.toBuffer())]); const content = sha256ToField(contentBuf); - const secretHash = computeSecretMessageHash(wasm, secret); + const secretHash = computeSecretMessageHash(secret); // Eventually the kernel will need to prove the kernel portal pair exists within the contract tree, // EthAddress.random() will need to be replaced when this happens diff --git a/yarn-project/acir-simulator/src/utils.ts b/yarn-project/acir-simulator/src/utils.ts index 45daead148b..bc1ff871737 100644 --- a/yarn-project/acir-simulator/src/utils.ts +++ b/yarn-project/acir-simulator/src/utils.ts @@ -1,5 +1,6 @@ -import { CircuitsWasm, GrumpkinPrivateKey } from '@aztec/circuits.js'; -import { Grumpkin, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { GrumpkinPrivateKey } from '@aztec/circuits.js'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; /** @@ -19,16 +20,11 @@ export type NoirPoint = { * @param bbWasm - Wasm module for computing. * @returns The slot in the contract storage where the value is stored. */ -export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr, bbWasm: CircuitsWasm) { +export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr) { const isFr = (owner: NoirPoint | Fr): owner is Fr => typeof (owner as Fr).value === 'bigint'; const ownerField = isFr(owner) ? owner : new Fr(owner.x); - return Fr.fromBuffer( - pedersenHashInputs( - bbWasm, - [mappingSlot, ownerField].map(f => f.toBuffer()), - ), - ); + return Fr.fromBuffer(pedersenHash([mappingSlot, ownerField].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 5d168d79269..bbf42324341 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -1,7 +1,6 @@ import { Archiver } from '@aztec/archiver'; import { CONTRACT_TREE_HEIGHT, - CircuitsWasm, Fr, GlobalVariables, HistoricBlockData, @@ -107,7 +106,7 @@ export class AztecNodeService implements AztecNode { // now create the merkle trees and the world state syncher const db = await openDb(config); - const merkleTrees = await MerkleTrees.new(db, await CircuitsWasm.get()); + const merkleTrees = await MerkleTrees.new(db); const worldStateConfig: WorldStateConfig = getWorldStateConfig(); const worldStateSynchronizer = await ServerWorldStateSynchronizer.new(db, merkleTrees, archiver, worldStateConfig); @@ -351,7 +350,7 @@ export class AztecNodeService implements AztecNode { */ public async getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise { const committedDb = await this.#getWorldState(); - const leafIndex = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot); + const leafIndex = computePublicDataTreeIndex(contract, slot); const value = await committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex.value); return value ? Fr.fromBuffer(value) : undefined; } @@ -418,7 +417,7 @@ export class AztecNodeService implements AztecNode { // TODO we should be able to remove this after https://github.com/AztecProtocol/aztec-packages/issues/1869 // So simulation of public functions doesn't affect the merkle trees. const merkleTrees = new MerkleTrees(this.merkleTreesDb, this.log); - await merkleTrees.init(await CircuitsWasm.get(), { + await merkleTrees.init({ globalVariables: prevGlobalVariables, }); diff --git a/yarn-project/aztec-sandbox/src/examples/token.ts b/yarn-project/aztec-sandbox/src/examples/token.ts index 2d35a5011b7..14dbcef82e7 100644 --- a/yarn-project/aztec-sandbox/src/examples/token.ts +++ b/yarn-project/aztec-sandbox/src/examples/token.ts @@ -52,7 +52,7 @@ async function main() { // Create a secret and a corresponding hash that will be used to mint funds privately const aliceSecret = Fr.random(); - const aliceSecretHash = await computeMessageSecretHash(aliceSecret); + const aliceSecretHash = computeMessageSecretHash(aliceSecret); const receipt = await tokenAlice.methods.mint_private(ALICE_MINT_BALANCE, aliceSecretHash).send().wait(); // Add the newly created "pending shield" note to PXE diff --git a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts index 974d0fa6bde..edff78a592f 100644 --- a/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/defaults/default_entrypoint.ts @@ -19,10 +19,10 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { ) {} async createTxExecutionRequest(executions: FunctionCall[]): Promise { - const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions); + const { payload, packedArguments: callsPackedArguments } = buildPayload(executions); const abi = this.getEntrypointAbi(); - const packedArgs = await PackedArguments.fromArgs(encodeArguments(abi, [payload])); - const message = Fr.fromBuffer(await hashPayload(payload)); + const packedArgs = PackedArguments.fromArgs(encodeArguments(abi, [payload])); + const message = Fr.fromBuffer(hashPayload(payload)); const authWitness = await this.auth.createAuthWitness(message); const txRequest = TxExecutionRequest.from({ argsHash: packedArgs.hash, 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 3ea1c9190d7..4e2afca4040 100644 --- a/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts +++ b/yarn-project/aztec.js/src/account/defaults/entrypoint_payload.ts @@ -1,6 +1,6 @@ -import { CircuitsWasm, Fr, GeneratorIndex } from '@aztec/circuits.js'; -import { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; +import { Fr, GeneratorIndex } from '@aztec/circuits.js'; import { padArrayEnd } from '@aztec/foundation/collection'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { FunctionCall, PackedArguments, emptyFunctionCall } from '@aztec/types'; // These must match the values defined in yarn-project/aztec-nr/aztec/src/entrypoint.nr @@ -32,18 +32,18 @@ export type EntrypointPayload = { }; /** Assembles an entrypoint payload from a set of private and public function calls */ -export async function buildPayload(calls: FunctionCall[]): Promise<{ +export function buildPayload(calls: FunctionCall[]): { /** The payload for the entrypoint function */ payload: EntrypointPayload; /** The packed arguments of functions called */ packedArguments: PackedArguments[]; -}> { +} { const nonce = Fr.random(); const paddedCalls = padArrayEnd(calls, emptyFunctionCall(), ACCOUNT_MAX_CALLS); const packedArguments: PackedArguments[] = []; for (const call of paddedCalls) { - packedArguments.push(await PackedArguments.fromArgs(call.args)); + packedArguments.push(PackedArguments.fromArgs(call.args)); } const formattedCalls: EntrypointFunctionCall[] = paddedCalls.map((call, index) => ({ @@ -68,9 +68,8 @@ export async function buildPayload(calls: FunctionCall[]): Promise<{ } /** Hashes an entrypoint payload to a 32-byte buffer (useful for signing) */ -export async function hashPayload(payload: EntrypointPayload) { - return pedersenHashWithHashIndex( - await CircuitsWasm.get(), +export function hashPayload(payload: EntrypointPayload) { + return pedersenHash( flattenPayload(payload).map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, ); diff --git a/yarn-project/aztec.js/src/account/utils.ts b/yarn-project/aztec.js/src/account/utils.ts index 0890a3eff46..f6309b90ee7 100644 --- a/yarn-project/aztec.js/src/account/utils.ts +++ b/yarn-project/aztec.js/src/account/utils.ts @@ -19,7 +19,7 @@ export function createAccount(pxe: PXE): Promise { * @returns Complete address of the registered recipient. */ export async function createRecipient(pxe: PXE): Promise { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); return completeAddress; } diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 9b801ddec83..0a848312cbf 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,4 +1,6 @@ -import { FunctionCall, TxExecutionRequest, Wallet } from '../index.js'; +import { FunctionCall, TxExecutionRequest } from '@aztec/types'; + +import { Wallet } from '../wallet/index.js'; import { BaseContractInteraction } from './base_contract_interaction.js'; /** A batch of function calls to be sent as a single transaction through a wallet. */ diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 4852169b3a5..41e3cc5b9b1 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -95,10 +95,10 @@ describe('Contract Class', () => { events: [], }; - beforeEach(async () => { + beforeEach(() => { resolvedExtendedContractData = ExtendedContractData.random(); contractAddress = resolvedExtendedContractData.contractData.contractAddress; - account = await CompleteAddress.random(); + account = CompleteAddress.random(); wallet = mock(); wallet.createTxExecutionRequest.mockResolvedValue(mockTxRequest); diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 47dc389c7eb..5de21db3d77 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,8 +1,9 @@ import { ContractArtifact } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Point } from '@aztec/foundation/fields'; import { PublicKey } from '@aztec/types'; -import { DeployMethod, Point } from '../index.js'; +import { DeployMethod } from '../contract_deployer/deploy_method.js'; import { Wallet } from '../wallet/index.js'; import { ContractBase } from './contract_base.js'; diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts index a97ae9fc6cb..d2ad1a95416 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts @@ -93,7 +93,7 @@ export class DeployMethod extends Bas const args = encodeArguments(this.constructorArtifact, this.args); const functionData = FunctionData.fromAbi(this.constructorArtifact); const execution = { args, functionData, to: completeAddress.address }; - const packedArguments = await PackedArguments.fromArgs(execution.args); + const packedArguments = PackedArguments.fromArgs(execution.args); const txRequest = TxExecutionRequest.from({ origin: execution.to, diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts index 93c16ad56a9..23a2e0bfb06 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_sent_tx.ts @@ -1,8 +1,11 @@ -import { CompleteAddress, FieldsOf } from '@aztec/circuits.js'; +import { AztecAddress, CompleteAddress, FieldsOf } from '@aztec/circuits.js'; import { ContractArtifact } from '@aztec/foundation/abi'; -import { TxHash, TxReceipt } from '@aztec/types'; +import { PXE, TxHash, TxReceipt } from '@aztec/types'; -import { AztecAddress, Contract, ContractBase, PXE, SentTx, WaitOpts, Wallet } from '../index.js'; +import { Contract } from '../contract/contract.js'; +import { ContractBase } from '../contract/contract_base.js'; +import { SentTx, WaitOpts } from '../contract/sent_tx.js'; +import { Wallet } from '../wallet/index.js'; /** Options related to waiting for a deployment tx. */ export type DeployedWaitOpts = WaitOpts & { diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 74f04862c4c..2d4aec8e3a7 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 { pedersenHashWithHashIndex } from '@aztec/circuits.js/barretenberg'; +import { AztecAddress, GeneratorIndex } from '@aztec/circuits.js'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { FunctionCall, PackedArguments } from '@aztec/types'; // docs:start:authwit_computeAuthWitMessageHash @@ -10,15 +10,13 @@ import { FunctionCall, PackedArguments } from '@aztec/types'; * @param request - The request to be made (function call) * @returns The message hash for the witness */ -export const computeAuthWitMessageHash = async (caller: AztecAddress, request: FunctionCall) => { - const wasm = await CircuitsWasm.get(); - return pedersenHashWithHashIndex( - wasm, +export const computeAuthWitMessageHash = (caller: AztecAddress, request: FunctionCall) => { + return pedersenHash( [ caller.toField(), request.to.toField(), request.functionData.selector.toField(), - (await PackedArguments.fromArgs(request.args, wasm)).hash, + PackedArguments.fromArgs(request.args).hash, ].map(fr => fr.toBuffer()), GeneratorIndex.SIGNATURE_PAYLOAD, ); diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index f12c38ea4b7..9833ef02398 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -1,7 +1,6 @@ import { AztecAddress, CircuitsWasm, EthAddress, Fr } from '@aztec/circuits.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer'; -import { keccak } from '@aztec/foundation/crypto'; +import { keccak, pedersenHash } from '@aztec/foundation/crypto'; import { createDebugLogger } from '@aztec/foundation/log'; import { Note, PXE } from '@aztec/types'; @@ -235,12 +234,7 @@ export class AztecCheatCodes { public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr { // Based on `at` function in // aztec3-packages/yarn-project/aztec-nr/aztec/src/state_vars/map.nr - return Fr.fromBuffer( - pedersenHashInputs( - this.wasm, - [new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()), - ), - ); + return Fr.fromBuffer(pedersenHash([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()))); } /** diff --git a/yarn-project/aztec.js/src/utils/secrets.ts b/yarn-project/aztec.js/src/utils/secrets.ts index 758bd6879e4..ac642c15916 100644 --- a/yarn-project/aztec.js/src/utils/secrets.ts +++ b/yarn-project/aztec.js/src/utils/secrets.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr } from '@aztec/circuits.js'; +import { Fr } from '@aztec/circuits.js'; import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; /** @@ -6,7 +6,6 @@ import { computeSecretMessageHash } from '@aztec/circuits.js/abis'; * @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()` * @returns the hash */ -export async function computeMessageSecretHash(secret: Fr): Promise { - const wasm = await CircuitsWasm.get(); - return computeSecretMessageHash(wasm, secret); +export function computeMessageSecretHash(secret: Fr) { + return computeSecretMessageHash(secret); } diff --git a/yarn-project/aztec.js/src/wallet/index.ts b/yarn-project/aztec.js/src/wallet/index.ts index fa43fcb1a97..b0c01e656cd 100644 --- a/yarn-project/aztec.js/src/wallet/index.ts +++ b/yarn-project/aztec.js/src/wallet/index.ts @@ -1,4 +1,6 @@ -import { AccountInterface, PXE } from '../index.js'; +import { PXE } from '@aztec/types'; + +import { AccountInterface } from '../account/index.js'; export * from './base_wallet.js'; export * from './account_wallet.js'; diff --git a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts index 03368dd8611..e9d04584853 100644 --- a/yarn-project/aztec.js/src/wallet/signerless_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/signerless_wallet.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr, TxContext } from '@aztec/circuits.js'; +import { Fr, TxContext } from '@aztec/circuits.js'; import { AuthWitness, FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types'; import { CompleteAddress } from '../index.js'; @@ -13,8 +13,7 @@ export class SignerlessWallet extends BaseWallet { throw new Error(`Unexpected number of executions. Expected 1 but received ${executions.length}).`); } const [execution] = executions; - const wasm = await CircuitsWasm.get(); - const packedArguments = await PackedArguments.fromArgs(execution.args, wasm); + const packedArguments = PackedArguments.fromArgs(execution.args); const { chainId, protocolVersion } = await this.pxe.getNodeInfo(); const txContext = TxContext.empty(chainId, protocolVersion); return Promise.resolve( diff --git a/yarn-project/boxes/token/src/tests/token.contract.test.ts b/yarn-project/boxes/token/src/tests/token.contract.test.ts index 27d8bb5fef8..0ec4dee07cc 100644 --- a/yarn-project/boxes/token/src/tests/token.contract.test.ts +++ b/yarn-project/boxes/token/src/tests/token.contract.test.ts @@ -161,8 +161,8 @@ describe('e2e_token_contract', () => { let secretHash: Fr; let txHash: TxHash; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); describe('Mint flow', () => { @@ -258,7 +258,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // docs:end:authwit_public_transfer_example @@ -319,7 +319,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -342,7 +342,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -364,7 +364,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // Perform the transfer @@ -409,7 +409,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // docs:end:authwit_computeAuthWitMessageHash const witness = await wallets[0].createAuthWitness(messageHash); @@ -460,7 +460,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -484,7 +484,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -501,8 +501,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); @@ -520,8 +520,8 @@ describe('e2e_token_contract', () => { const secret = Fr.random(); let secretHash: Fr; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); it('on behalf of self', async () => { @@ -553,7 +553,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -608,7 +608,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -622,7 +622,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Message not authorized by account'); @@ -664,7 +664,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -716,7 +716,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -737,8 +737,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -774,7 +774,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -825,7 +825,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -839,7 +839,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect( @@ -868,7 +868,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -913,7 +913,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -932,7 +932,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -947,8 +947,8 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index 4895aac0930..52da5e51621 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -1,5 +1,35 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`abis wasm bindings compute globals hash 1`] = ` +Fr { + "value": 19996198784166720428914107076917074510032365849254400404611644441094528984289n, +} +`; + +exports[`abis wasm bindings compute private call stack item hash 1`] = ` +Fr { + "value": 3230879723118793997125108252427471059552102155544558929105689542823769599571n, +} +`; + +exports[`abis wasm bindings compute public call stack item hash 1`] = ` +Fr { + "value": 1369626479296628599511967895314683808250163038382688147156251959177959447826n, +} +`; + +exports[`abis wasm bindings compute secret message hash 1`] = ` +Fr { + "value": 6220068662483113241527007349428551778669520744131373768997518428761948042030n, +} +`; + +exports[`abis wasm bindings compute tx hash 1`] = ` +Fr { + "value": 11028384086470399424960241201065432836500251313078792361310973684322431200173n, +} +`; + exports[`abis wasm bindings computes a complete address 1`] = ` CompleteAddress { "address": AztecAddress { @@ -56,6 +86,48 @@ CompleteAddress { } `; +exports[`abis wasm bindings computes a contract address from partial 1`] = ` +AztecAddress { + "buffer": { + "data": [ + 34, + 41, + 121, + 74, + 138, + 50, + 100, + 6, + 122, + 50, + 114, + 42, + 84, + 48, + 151, + 243, + 88, + 162, + 160, + 249, + 55, + 16, + 237, + 195, + 114, + 27, + 106, + 66, + 228, + 123, + 33, + 231, + ], + "type": "Buffer", + }, +} +`; + exports[`abis wasm bindings computes a function leaf 1`] = ` Fr { "value": 8957681167943973616438847631514238173699549883609341685749385526208761312950n, @@ -74,6 +146,12 @@ exports[`abis wasm bindings computes a function selector 1`] = ` } `; +exports[`abis wasm bindings computes block hash with globals 1`] = ` +Fr { + "value": 7177915431153102916601456081755280584460785548870192083974540199919775120827n, +} +`; + exports[`abis wasm bindings computes commitment nonce 1`] = ` Fr { "value": 7653394882992289714855533169019502055399179742531912347686813547951736946253n, @@ -92,6 +170,18 @@ Fr { } `; +exports[`abis wasm bindings computes public data tree index 1`] = ` +Fr { + "value": 9076808949980998475110411569159266589807853958487763065147292518713994520820n, +} +`; + +exports[`abis wasm bindings computes public data tree value 1`] = ` +Fr { + "value": 3n, +} +`; + exports[`abis wasm bindings computes siloed commitment 1`] = ` Fr { "value": 7262347077404413274044670947879391583109741657896097604752287127491776887739n, @@ -110,6 +200,12 @@ Fr { } `; +exports[`abis wasm bindings computes zero contract leaf 1`] = ` +Fr { + "value": 0n, +} +`; + exports[`abis wasm bindings hashes VK 1`] = ` { "data": [ diff --git a/yarn-project/circuits.js/src/abis/abis.test.ts b/yarn-project/circuits.js/src/abis/abis.test.ts index b630b7b5047..79413a36c10 100644 --- a/yarn-project/circuits.js/src/abis/abis.test.ts +++ b/yarn-project/circuits.js/src/abis/abis.test.ts @@ -1,15 +1,39 @@ import times from 'lodash.times'; -import { AztecAddress, Fr, FunctionData, FunctionLeafPreimage, FunctionSelector, NewContractData } from '../index.js'; -import { makeAztecAddress, makeEthAddress, makePoint, makeTxRequest, makeVerificationKey } from '../tests/factories.js'; +import { + AztecAddress, + Fr, + FunctionData, + FunctionLeafPreimage, + FunctionSelector, + GlobalVariables, + NewContractData, +} from '../index.js'; +import { + makeAztecAddress, + makeEthAddress, + makePoint, + makePrivateCallStackItem, + makePublicCallStackItem, + makeTxRequest, + makeVerificationKey, +} from '../tests/factories.js'; import { CircuitsWasm } from '../wasm/circuits_wasm.js'; import { + computeBlockHashWithGlobals, + computeCallStackItemHash, computeCommitmentNonce, computeCompleteAddress, + computeContractAddressFromPartial, computeContractLeaf, computeFunctionLeaf, computeFunctionSelector, computeFunctionTreeRoot, + computeGlobalsHash, + computePublicDataTreeIndex, + computePublicDataTreeValue, + computeSecretMessageHash, + computeTxHash, computeUniqueCommitment, computeVarArgsHash, hashConstructor, @@ -27,13 +51,13 @@ describe('abis wasm bindings', () => { it('hashes a tx request', () => { const txRequest = makeTxRequest(); - const hash = hashTxRequest(wasm, txRequest); + const hash = hashTxRequest(txRequest); expect(hash).toMatchSnapshot(); }); it('computes a function selector', () => { const funcSig = 'transfer(address,uint256)'; - const res = computeFunctionSelector(wasm, funcSig); + const res = computeFunctionSelector(funcSig); expect(res).toMatchSnapshot(); }); @@ -45,7 +69,7 @@ describe('abis wasm bindings', () => { it('computes a function leaf', () => { const leaf = new FunctionLeafPreimage(new FunctionSelector(7837), false, true, Fr.ZERO, Fr.ZERO); - const res = computeFunctionLeaf(wasm, leaf); + const res = computeFunctionLeaf(leaf); expect(res).toMatchSnapshot(); }); @@ -58,7 +82,7 @@ describe('abis wasm bindings', () => { const functionData = new FunctionData(FunctionSelector.empty(), false, true, true); const argsHash = new Fr(42); const vkHash = Buffer.alloc(32); - const res = hashConstructor(wasm, functionData, argsHash, vkHash); + const res = hashConstructor(functionData, argsHash, vkHash); expect(res).toMatchSnapshot(); }); @@ -67,58 +91,143 @@ describe('abis wasm bindings', () => { const contractAddrSalt = new Fr(2n); const treeRoot = new Fr(3n); const constructorHash = new Fr(4n); - const res = computeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, treeRoot, constructorHash); + const res = computeCompleteAddress(deployerPubKey, contractAddrSalt, treeRoot, constructorHash); + expect(res).toMatchSnapshot(); + }); + + it('computes a contract address from partial', () => { + const deployerPubKey = makePoint(); + const partialAddress = new Fr(2n); + const res = computeContractAddressFromPartial(deployerPubKey, partialAddress); expect(res).toMatchSnapshot(); }); it('computes commitment nonce', () => { const nullifierZero = new Fr(123n); const commitmentIndex = 456; - const res = computeCommitmentNonce(wasm, nullifierZero, commitmentIndex); + const res = computeCommitmentNonce(nullifierZero, commitmentIndex); expect(res).toMatchSnapshot(); }); it('computes unique commitment', () => { const nonce = new Fr(123n); const innerCommitment = new Fr(456); - const res = computeUniqueCommitment(wasm, nonce, innerCommitment); + const res = computeUniqueCommitment(nonce, innerCommitment); expect(res).toMatchSnapshot(); }); it('computes siloed commitment', () => { const contractAddress = new AztecAddress(new Fr(123n).toBuffer()); const uniqueCommitment = new Fr(456); - const res = siloCommitment(wasm, contractAddress, uniqueCommitment); + const res = siloCommitment(contractAddress, uniqueCommitment); expect(res).toMatchSnapshot(); }); it('computes siloed nullifier', () => { const contractAddress = new AztecAddress(new Fr(123n).toBuffer()); const innerNullifier = new Fr(456); - const res = siloNullifier(wasm, contractAddress, innerNullifier); + const res = siloNullifier(contractAddress, innerNullifier); expect(res).toMatchSnapshot(); }); - it('computes contract leaf', () => { - const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n)); - const res = computeContractLeaf(wasm, cd); + it('computes block hash with globals', () => { + const globals = GlobalVariables.from({ + chainId: new Fr(1n), + version: new Fr(2n), + blockNumber: new Fr(3n), + timestamp: new Fr(4n), + }); + const noteHashTreeRoot = new Fr(5n); + const nullifierTreeRoot = new Fr(6n); + const contractTreeRoot = new Fr(7n); + const l1ToL2DataTreeRoot = new Fr(8n); + const publicDataTreeRoot = new Fr(9n); + const res = computeBlockHashWithGlobals( + globals, + noteHashTreeRoot, + nullifierTreeRoot, + contractTreeRoot, + l1ToL2DataTreeRoot, + publicDataTreeRoot, + ); expect(res).toMatchSnapshot(); }); - it('hashes empty function args', async () => { - const res = await computeVarArgsHash(wasm, []); + it('compute globals hash', () => { + const globals = GlobalVariables.from({ + chainId: new Fr(1n), + version: new Fr(2n), + blockNumber: new Fr(3n), + timestamp: new Fr(4n), + }); + const res = computeGlobalsHash(globals); expect(res).toMatchSnapshot(); }); - it('hashes function args', async () => { + it('computes public data tree value', () => { + const value = new Fr(3n); + const res = computePublicDataTreeValue(value); + expect(res).toMatchSnapshot(); + }); + + it('computes public data tree index', () => { + const contractAddress = makeAztecAddress(); + const value = new Fr(3n); + const res = computePublicDataTreeIndex(contractAddress, value); + expect(res).toMatchSnapshot(); + }); + + it('hashes empty function args', () => { + const res = computeVarArgsHash([]); + expect(res).toMatchSnapshot(); + }); + + it('hashes function args', () => { + // const args = Array.from({ length: 8 }).map((_, i) => new Fr(i)); const args = times(8, i => new Fr(i)); - const res = await computeVarArgsHash(wasm, args); + const res = computeVarArgsHash(args); expect(res).toMatchSnapshot(); }); - it('hashes many function args', async () => { + it('hashes many function args', () => { const args = times(200, i => new Fr(i)); - const res = await computeVarArgsHash(wasm, args); + const res = computeVarArgsHash(args); + expect(res).toMatchSnapshot(); + }); + + it('computes contract leaf', () => { + const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n)); + const res = computeContractLeaf(cd); + expect(res).toMatchSnapshot(); + }); + + it('computes zero contract leaf', () => { + const cd = new NewContractData(AztecAddress.ZERO, AztecAddress.ZERO, new Fr(0n)); + const res = computeContractLeaf(cd); expect(res).toMatchSnapshot(); }); + + it('compute tx hash', () => { + const txRequest = makeTxRequest(); + const hash = computeTxHash(txRequest); + expect(hash).toMatchSnapshot(); + }); + + it('compute private call stack item hash', () => { + const item = makePrivateCallStackItem(); + const hash = computeCallStackItemHash(wasm, item); + expect(hash).toMatchSnapshot(); + }); + + it('compute public call stack item hash', () => { + const item = makePublicCallStackItem(); + const hash = computeCallStackItemHash(wasm, item); + expect(hash).toMatchSnapshot(); + }); + + it('compute secret message hash', () => { + const value = new Fr(8n); + const hash = computeSecretMessageHash(value); + expect(hash).toMatchSnapshot(); + }); }); diff --git a/yarn-project/circuits.js/src/abis/abis.ts b/yarn-project/circuits.js/src/abis/abis.ts index f1dfc6d3dc8..88911dd1c67 100644 --- a/yarn-project/circuits.js/src/abis/abis.ts +++ b/yarn-project/circuits.js/src/abis/abis.ts @@ -1,37 +1,29 @@ import { padArrayEnd } from '@aztec/foundation/collection'; +import { keccak, pedersenHash } from '@aztec/foundation/crypto'; +import { numToUInt32BE } from '@aztec/foundation/serialize'; import { IWasmModule } from '@aztec/foundation/wasm'; import { Buffer } from 'buffer'; import chunk from 'lodash.chunk'; -import { - abisComputeBlockHash, - abisComputeBlockHashWithGlobals, - abisComputeCommitmentNonce, - abisComputeCompleteAddress, - abisComputeGlobalsHash, - abisComputePublicDataTreeIndex, - abisComputePublicDataTreeValue, - abisComputeUniqueCommitment, - abisSiloCommitment, - abisSiloNullifier, -} from '../cbind/circuits.gen.js'; import { AztecAddress, CompleteAddress, + ContractDeploymentData, FUNCTION_SELECTOR_NUM_BYTES, Fr, FunctionData, FunctionLeafPreimage, + GeneratorIndex, GlobalVariables, NewContractData, PrivateCallStackItem, PublicCallStackItem, PublicKey, + TxContext, TxRequest, - Vector, } from '../index.js'; -import { serializeBufferArrayToVector } from '../utils/serialize.js'; +import { boolToBuffer, serializeBufferArrayToVector } from '../utils/serialize.js'; /** * Synchronously calls a wasm function. @@ -41,7 +33,7 @@ import { serializeBufferArrayToVector } from '../utils/serialize.js'; * @param expectedOutputLength - The expected length of the output buffer. * @returns The output buffer. */ -export function wasmSyncCall( +function wasmSyncCall( wasm: IWasmModule, fnName: string, input: @@ -65,45 +57,14 @@ export function wasmSyncCall( return buf; } -/** - * Writes input buffers to wasm memory, calls a wasm function, and returns the output buffer. - * @param wasm - A module providing low-level wasm access. - * @param fnName - The name of the function to call. - * @param inputBuffers - Buffers to write to wasm memory. - * @param expectedOutputLength - The expected length of the output buffer. - * @returns The output buffer. - */ -export function inputBuffersToOutputBuffer( - wasm: IWasmModule, - fnName: string, - inputBuffers: Buffer[], - expectedOutputLength: number, -) { - const offsets: number[] = []; - const totalLength = inputBuffers.reduce((total, cur) => { - offsets.push(total); - return total + cur.length; - }, 0); - - const outputBuf = wasm.call('bbmalloc', expectedOutputLength); - const inputBuf = wasm.call('bbmalloc', totalLength); - wasm.writeMemory(inputBuf, Buffer.concat(inputBuffers)); - const args = offsets.map(offset => inputBuf + offset); - wasm.call(fnName, ...args, outputBuf); - const output = Buffer.from(wasm.getMemorySlice(outputBuf, outputBuf + expectedOutputLength)); - wasm.call('bbfree', inputBuf); - wasm.call('bbfree', outputBuf); - return output; -} - /** * Computes a hash of a transaction request. * @param wasm - A module providing low-level wasm access. * @param txRequest - The transaction request. * @returns The hash of the transaction request. */ -export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { - return wasmSyncCall(wasm, 'abis__hash_tx_request', txRequest, 32); +export function hashTxRequest(txRequest: TxRequest): Buffer { + return computeTxHash(txRequest).toBuffer(); } /** @@ -112,15 +73,8 @@ export function hashTxRequest(wasm: IWasmModule, txRequest: TxRequest): Buffer { * @param funcSig - The function signature. * @returns The function selector. */ -export function computeFunctionSelector(wasm: IWasmModule, funcSig: string): Buffer { - return wasmSyncCall( - wasm, - 'abis__compute_function_selector', - // Important - explicit C-string compatibility with a null terminator! - // In the future we want to move away from this fiddly C-string processing. - Buffer.from(funcSig + '\0'), - FUNCTION_SELECTOR_NUM_BYTES, - ); +export function computeFunctionSelector(funcSig: string): Buffer { + return keccak(Buffer.from(funcSig)).subarray(0, FUNCTION_SELECTOR_NUM_BYTES); } /** @@ -139,8 +93,20 @@ export function hashVK(wasm: IWasmModule, vkBuf: Buffer) { * @param fnLeaf - The function leaf preimage. * @returns The function leaf. */ -export function computeFunctionLeaf(wasm: IWasmModule, fnLeaf: FunctionLeafPreimage): Fr { - return Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_function_leaf', fnLeaf, 32)); +export function computeFunctionLeaf(fnLeaf: FunctionLeafPreimage): Fr { + // return Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_function_leaf', fnLeaf, 32)); + return Fr.fromBuffer( + pedersenHash( + [ + numToUInt32BE(fnLeaf.functionSelector.value, 32), + boolToBuffer(fnLeaf.isInternal, 32), + boolToBuffer(fnLeaf.isPrivate, 32), + fnLeaf.vkHash.toBuffer(), + fnLeaf.acirHash.toBuffer(), + ], + GeneratorIndex.FUNCTION_LEAF, + ), + ); } /** @@ -163,19 +129,13 @@ export function computeFunctionTreeRoot(wasm: IWasmModule, fnLeaves: Fr[]) { * @param constructorVKHash - Hash of the constructor's verification key. * @returns The constructor hash. */ -export function hashConstructor( - wasm: IWasmModule, - functionData: FunctionData, - argsHash: Fr, - constructorVKHash: Buffer, -): Fr { - const result = inputBuffersToOutputBuffer( - wasm, - 'abis__hash_constructor', - [functionData.toBuffer(), argsHash.toBuffer(), constructorVKHash], - 32, +export function hashConstructor(functionData: FunctionData, argsHash: Fr, constructorVKHash: Buffer): Fr { + return Fr.fromBuffer( + pedersenHash( + [computeFunctionDataHash(functionData).toBuffer(), argsHash.toBuffer(), constructorVKHash], + GeneratorIndex.CONSTRUCTOR, + ), ); - return Fr.fromBuffer(result); } /** @@ -188,13 +148,35 @@ export function hashConstructor( * @returns The complete address. */ export function computeCompleteAddress( - wasm: IWasmModule, deployerPubKey: PublicKey, contractAddrSalt: Fr, fnTreeRoot: Fr, constructorHash: Fr, ): CompleteAddress { - return abisComputeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, fnTreeRoot, constructorHash); + const partialAddress = computePartialAddress(contractAddrSalt, fnTreeRoot, constructorHash); + return new CompleteAddress( + computeContractAddressFromPartial(deployerPubKey, partialAddress), + deployerPubKey, + partialAddress, + ); +} + +/** + * + */ +function computePartialAddress(contractAddrSalt: Fr, fnTreeRoot: Fr, constructorHash: Fr) { + return Fr.fromBuffer( + pedersenHash( + [ + Fr.ZERO.toBuffer(), + Fr.ZERO.toBuffer(), + contractAddrSalt.toBuffer(), + fnTreeRoot.toBuffer(), + constructorHash.toBuffer(), + ], + GeneratorIndex.PARTIAL_ADDRESS, + ), + ); } /** @@ -205,16 +187,10 @@ export function computeCompleteAddress( * @param constructorHash - The hash of the constructor. * @returns The partially constructed contract address. */ -export function computeContractAddressFromPartial( - wasm: IWasmModule, - pubKey: PublicKey, - partialAddress: Fr, -): AztecAddress { - const result = inputBuffersToOutputBuffer( - wasm, - 'abis__compute_contract_address_from_partial', - [pubKey.toBuffer(), partialAddress.toBuffer()], - 32, +export function computeContractAddressFromPartial(pubKey: PublicKey, partialAddress: Fr): AztecAddress { + const result = pedersenHash( + [pubKey.x.toBuffer(), pubKey.y.toBuffer(), partialAddress.toBuffer()], + GeneratorIndex.CONTRACT_ADDRESS, ); return new AztecAddress(result); } @@ -226,8 +202,10 @@ export function computeContractAddressFromPartial( * @param commitmentIndex - The index of the commitment. * @returns A commitment nonce. */ -export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, commitmentIndex: number): Fr { - return abisComputeCommitmentNonce(wasm, nullifierZero, new Fr(commitmentIndex)); +export function computeCommitmentNonce(nullifierZero: Fr, commitmentIndex: number): Fr { + return Fr.fromBuffer( + pedersenHash([nullifierZero.toBuffer(), numToUInt32BE(commitmentIndex, 32)], GeneratorIndex.COMMITMENT_NONCE), + ); } /** @@ -238,8 +216,10 @@ export function computeCommitmentNonce(wasm: IWasmModule, nullifierZero: Fr, com * @param innerCommitment - The commitment to silo. * @returns A siloed commitment. */ -export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerCommitment: Fr): Fr { - return abisSiloCommitment(wasm, contract, innerCommitment); +export function siloCommitment(contract: AztecAddress, innerCommitment: Fr): Fr { + return Fr.fromBuffer( + pedersenHash([contract.toBuffer(), innerCommitment.toBuffer()], GeneratorIndex.SILOED_COMMITMENT), + ); } /** @@ -249,8 +229,8 @@ export function siloCommitment(wasm: IWasmModule, contract: AztecAddress, innerC * @param siloedCommitment - An siloed commitment. * @returns A unique commitment. */ -export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedCommitment: Fr): Fr { - return abisComputeUniqueCommitment(wasm, nonce, siloedCommitment); +export function computeUniqueCommitment(nonce: Fr, siloedCommitment: Fr): Fr { + return Fr.fromBuffer(pedersenHash([nonce.toBuffer(), siloedCommitment.toBuffer()], GeneratorIndex.UNIQUE_COMMITMENT)); } /** @@ -261,8 +241,8 @@ export function computeUniqueCommitment(wasm: IWasmModule, nonce: Fr, siloedComm * @param innerNullifier - The nullifier to silo. * @returns A siloed nullifier. */ -export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNullifier: Fr): Fr { - return abisSiloNullifier(wasm, contract, innerNullifier); +export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Fr { + return Fr.fromBuffer(pedersenHash([contract.toBuffer(), innerNullifier.toBuffer()], GeneratorIndex.OUTER_NULLIFIER)); } /** @@ -277,7 +257,6 @@ export function siloNullifier(wasm: IWasmModule, contract: AztecAddress, innerNu * @returns The block hash. */ export function computeBlockHashWithGlobals( - wasm: IWasmModule, globals: GlobalVariables, noteHashTreeRoot: Fr, nullifierTreeRoot: Fr, @@ -285,9 +264,8 @@ export function computeBlockHashWithGlobals( l1ToL2DataTreeRoot: Fr, publicDataTreeRoot: Fr, ): Fr { - return abisComputeBlockHashWithGlobals( - wasm, - globals, + return computeBlockHash( + computeGlobalsHash(globals), noteHashTreeRoot, nullifierTreeRoot, contractTreeRoot, @@ -308,7 +286,6 @@ export function computeBlockHashWithGlobals( * @returns The block hash. */ export function computeBlockHash( - wasm: IWasmModule, globalsHash: Fr, noteHashTreeRoot: Fr, nullifierTreeRoot: Fr, @@ -316,14 +293,18 @@ export function computeBlockHash( l1ToL2DataTreeRoot: Fr, publicDataTreeRoot: Fr, ): Fr { - return abisComputeBlockHash( - wasm, - globalsHash, - noteHashTreeRoot, - nullifierTreeRoot, - contractTreeRoot, - l1ToL2DataTreeRoot, - publicDataTreeRoot, + return Fr.fromBuffer( + pedersenHash( + [ + globalsHash.toBuffer(), + noteHashTreeRoot.toBuffer(), + nullifierTreeRoot.toBuffer(), + contractTreeRoot.toBuffer(), + l1ToL2DataTreeRoot.toBuffer(), + publicDataTreeRoot.toBuffer(), + ], + GeneratorIndex.BLOCK_HASH, + ), ); } @@ -333,8 +314,18 @@ export function computeBlockHash( * @param globals - The global variables to put into the block hash. * @returns The globals hash. */ -export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables): Fr { - return abisComputeGlobalsHash(wasm, globals); +export function computeGlobalsHash(globals: GlobalVariables): Fr { + return Fr.fromBuffer( + pedersenHash( + [ + globals.chainId.toBuffer(), + globals.version.toBuffer(), + globals.blockNumber.toBuffer(), + globals.timestamp.toBuffer(), + ], + GeneratorIndex.GLOBAL_VARIABLES, + ), + ); } /** @@ -344,8 +335,8 @@ export function computeGlobalsHash(wasm: IWasmModule, globals: GlobalVariables): * @returns Value hash into a tree-insertion-ready value. */ -export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { - return abisComputePublicDataTreeValue(wasm, value); +export function computePublicDataTreeValue(value: Fr): Fr { + return value; } /** @@ -356,8 +347,10 @@ export function computePublicDataTreeValue(wasm: IWasmModule, value: Fr): Fr { * @returns Public data tree index computed from contract address and storage slot. */ -export function computePublicDataTreeIndex(wasm: IWasmModule, contractAddress: AztecAddress, storageSlot: Fr): Fr { - return abisComputePublicDataTreeIndex(wasm, contractAddress, storageSlot); +export function computePublicDataTreeIndex(contractAddress: AztecAddress, storageSlot: Fr): Fr { + return Fr.fromBuffer( + pedersenHash([contractAddress.toBuffer(), storageSlot.toBuffer()], GeneratorIndex.PUBLIC_LEAF_INDEX), + ); } const ARGS_HASH_CHUNK_SIZE = 32; @@ -369,13 +362,18 @@ const ARGS_HASH_CHUNK_COUNT = 16; * @param args - Arguments to hash. * @returns Pedersen hash of the arguments. */ -export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { - if (args.length === 0) return Promise.resolve(Fr.ZERO); +export function computeVarArgsHash(args: Fr[]) { + if (args.length === 0) return Fr.ZERO; if (args.length > ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT) throw new Error(`Cannot hash more than ${ARGS_HASH_CHUNK_SIZE * ARGS_HASH_CHUNK_COUNT} arguments`); const wasmComputeVarArgs = (args: Fr[]) => - Fr.fromBuffer(wasmSyncCall(wasm, 'abis__compute_var_args_hash', new Vector(args), 32)); + Fr.fromBuffer( + pedersenHash( + args.map(a => a.toBuffer()), + GeneratorIndex.FUNCTION_ARGS, + ), + ); let chunksHashes = chunk(args, ARGS_HASH_CHUNK_SIZE).map(c => { if (c.length < ARGS_HASH_CHUNK_SIZE) { @@ -388,7 +386,7 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { chunksHashes = padArrayEnd(chunksHashes, Fr.ZERO, ARGS_HASH_CHUNK_COUNT); } - return Promise.resolve(wasmComputeVarArgs(chunksHashes)); + return wasmComputeVarArgs(chunksHashes); } /** @@ -397,9 +395,16 @@ export function computeVarArgsHash(wasm: IWasmModule, args: Fr[]): Promise { * @param cd - The contract data of the deployed contract. * @returns The contract leaf. */ -export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr { - const value = wasmSyncCall(wasm, 'abis__compute_contract_leaf', cd, 32); - return Fr.fromBuffer(value); +export function computeContractLeaf(cd: NewContractData): Fr { + if (cd.contractAddress.isZero() && cd.portalContractAddress.isZero() && cd.functionTreeRoot.isZero()) { + return new Fr(0); + } + return Fr.fromBuffer( + pedersenHash( + [cd.contractAddress.toBuffer(), cd.portalContractAddress.toBuffer(), cd.functionTreeRoot.toBuffer()], + GeneratorIndex.CONTRACT_LEAF, + ), + ); } /** @@ -408,9 +413,73 @@ export function computeContractLeaf(wasm: IWasmModule, cd: NewContractData): Fr * @param txRequest - The signed transaction request. * @returns The transaction hash. */ -export function computeTxHash(wasm: IWasmModule, txRequest: TxRequest): Fr { - const value = wasmSyncCall(wasm, 'abis__compute_transaction_hash', txRequest, 32); - return Fr.fromBuffer(value); +export function computeTxHash(txRequest: TxRequest): Fr { + return Fr.fromBuffer( + pedersenHash( + [ + txRequest.origin.toBuffer(), + computeFunctionDataHash(txRequest.functionData).toBuffer(), + txRequest.argsHash.toBuffer(), + computeTxContextHash(txRequest.txContext).toBuffer(), + ], + GeneratorIndex.TX_REQUEST, + ), + ); +} + +/** + * + */ +function computeFunctionDataHash(functionData: FunctionData): Fr { + return Fr.fromBuffer( + pedersenHash( + [ + functionData.selector.toBuffer(32), + new Fr(functionData.isInternal).toBuffer(), + new Fr(functionData.isPrivate).toBuffer(), + new Fr(functionData.isConstructor).toBuffer(), + ], + GeneratorIndex.FUNCTION_DATA, + ), + ); +} + +/** + * + */ +function computeTxContextHash(txContext: TxContext): Fr { + return Fr.fromBuffer( + pedersenHash( + [ + new Fr(txContext.isFeePaymentTx).toBuffer(), + new Fr(txContext.isRebatePaymentTx).toBuffer(), + new Fr(txContext.isContractDeploymentTx).toBuffer(), + computeContractDeploymentDataHash(txContext.contractDeploymentData).toBuffer(), + txContext.chainId.toBuffer(), + txContext.version.toBuffer(), + ], + GeneratorIndex.TX_CONTEXT, + ), + ); +} + +/** + * + */ +function computeContractDeploymentDataHash(data: ContractDeploymentData): Fr { + return Fr.fromBuffer( + pedersenHash( + [ + data.deployerPublicKey.x.toBuffer(), + data.deployerPublicKey.y.toBuffer(), + data.constructorVkHash.toBuffer(), + data.functionTreeRoot.toBuffer(), + data.contractAddressSalt.toBuffer(), + data.portalContractAddress.toBuffer(), + ], + GeneratorIndex.CONTRACT_DEPLOYMENT_DATA, + ), + ); } /** @@ -441,6 +510,16 @@ export function computeCallStackItemHash( export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem: PrivateCallStackItem): Fr { const value = wasmSyncCall(wasm, 'abis__compute_private_call_stack_item_hash', callStackItem, 32); return Fr.fromBuffer(value); + // return Fr.fromBuffer( + // pedersenHashWithHashIndex( + // [ + // callStackItem.contractAddress.toBuffer(), + // computeFunctionDataHash(callStackItem.functionData).toBuffer(), + // computePublicInputsHash(callStackItem.publicInputs).toBuffer(), + // ], + // GeneratorIndex.CALL_STACK_ITEM, + // ), + // ); } /** @@ -452,6 +531,16 @@ export function computePrivateCallStackItemHash(wasm: IWasmModule, callStackItem export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: PublicCallStackItem): Fr { const value = wasmSyncCall(wasm, 'abis__compute_public_call_stack_item_hash', callStackItem, 32); return Fr.fromBuffer(value); + // return Fr.fromBuffer( + // pedersenHashWithHashIndex( + // [ + // callStackItem.contractAddress.toBuffer(), + // callStackItem.functionData.toBuffer(), + // callStackItem.publicInputs.toBuffer(), + // ], + // GeneratorIndex.CALL_STACK_ITEM, + // ), + // ); } /** @@ -459,7 +548,6 @@ export function computePublicCallStackItemHash(wasm: IWasmModule, callStackItem: * @param secretMessage - The secret message. * @returns */ -export function computeSecretMessageHash(wasm: IWasmModule, secretMessage: Fr) { - const value = wasmSyncCall(wasm, 'abis__compute_message_secret_hash', secretMessage, 32); - return Fr.fromBuffer(value); +export function computeSecretMessageHash(secretMessage: Fr) { + return Fr.fromBuffer(pedersenHash([secretMessage.toBuffer()], GeneratorIndex.L1_TO_L2_MESSAGE_SECRET)); } diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts index 82c73556355..35a0cb068e5 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/grumpkin/index.ts @@ -3,6 +3,8 @@ import { IWasmModule } from '@aztec/foundation/wasm'; import { CircuitsWasm, GrumpkinScalar } from '../../../index.js'; +// TODO: Establish if these needs high performance and consider refactoring and using the grumpkin curve in pedersen ts. + /** * Grumpkin elliptic curve operations. */ diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/index.ts index 4157db3d632..e9c594c032d 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/index.ts @@ -1,6 +1,5 @@ export * from './aes128/index.js'; export * from './grumpkin/index.js'; -export * from './pedersen/index.js'; export * from './ecdsa/index.js'; export * from './secp256k1/index.js'; export * from './schnorr/index.js'; diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts b/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts deleted file mode 100644 index 5ec6c0cde01..00000000000 --- a/yarn-project/circuits.js/src/barretenberg/crypto/pedersen/pedersen.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { IWasmModule } from '@aztec/foundation/wasm'; - -import { Buffer } from 'buffer'; - -import { serializeBufferArrayToVector } from '../../serialize.js'; - -/** - * Hashes two arrays. - * @param wasm - The barretenberg module. - * @param lhs - The first array. - * @param rhs - The second array. - * @returns The new 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenHash(wasm: IWasmModule, lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHashWithHashIndex(wasm, [Buffer.from(lhs), Buffer.from(rhs)], 0); -} - -/** - * Computes the hash of an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to hash. - * @returns The new 32-byte hash. - * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific - * purposes. - */ -export function pedersenHashInputs(wasm: IWasmModule, inputs: Buffer[]): Buffer { - return pedersenHashWithHashIndex(wasm, inputs, 0); -} - -/** - * Hashes an array of buffers. - * @param wasm - The barretenberg module. - * @param inputs - The array of buffers to hash. - * @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 pedersenHashWithHashIndex(wasm: IWasmModule, inputs: Buffer[], hashIndex: number): Buffer { - const data = serializeBufferArrayToVector(inputs); - - // WASM gives us 1024 bytes of scratch space which we can use without - // needing to allocate/free it ourselves. This can be useful for when we need to pass in several small variables - // when calling functions on the wasm, however it's important to not overrun this scratch space as otherwise - // the written data will begin to corrupt the stack. - // - // Using this scratch space isn't particularly safe if we have multiple threads interacting with the wasm however, - // each thread could write to the same pointer address simultaneously. - const SCRATCH_SPACE_SIZE = 1024; - - // For pedersen hashing, the case of hashing two inputs is the most common. - // so ideally we want to optimize for that. This will use 64 bytes of memory and - // can thus be optimized by checking if the input buffer is smaller than the scratch space. - let inputPtr = 0; - if (inputs.length >= SCRATCH_SPACE_SIZE) { - inputPtr = wasm.call('bbmalloc', data.length); - } - wasm.writeMemory(inputPtr, data); - - // Since the output is 32 bytes, instead of allocating memory - // we can reuse the scratch space to store the result. - const outputPtr = 0; - - wasm.call('pedersen__hash_with_hash_index', inputPtr, hashIndex, outputPtr); - const hashOutput = wasm.getMemorySlice(0, 32); - - wasm.call('bbfree', inputPtr); - - return Buffer.from(hashOutput); -} diff --git a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts index df1d8efade5..5914d6c840b 100644 --- a/yarn-project/circuits.js/src/contract/contract_deployment_info.ts +++ b/yarn-project/circuits.js/src/contract/contract_deployment_info.ts @@ -38,20 +38,14 @@ export async function getContractDeploymentInfo( ...f, selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters), })); - const leaves = generateFunctionLeaves(functions, wasm); + const leaves = generateFunctionLeaves(functions); const functionTreeRoot = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const flatArgs = encodeArguments(constructorArtifact, args); - const argsHash = await computeVarArgsHash(wasm, flatArgs); - const constructorHash = hashConstructor(wasm, functionData, argsHash, constructorVkHash.toBuffer()); + const argsHash = computeVarArgsHash(flatArgs); + const constructorHash = hashConstructor(functionData, argsHash, constructorVkHash.toBuffer()); - const completeAddress = computeCompleteAddress( - wasm, - publicKey, - contractAddressSalt, - functionTreeRoot, - constructorHash, - ); + const completeAddress = computeCompleteAddress(publicKey, contractAddressSalt, functionTreeRoot, constructorHash); return { completeAddress, diff --git a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts index fe3325d11aa..b74a372849b 100644 --- a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts +++ b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts @@ -64,7 +64,7 @@ export function isConstrained({ * @param wasm - CircuitsWasm instance used for hashing and computations. * @returns An array of Fr instances representing the generated function leaves. */ -export function generateFunctionLeaves(functions: ContractFunctionDao[], wasm: CircuitsWasm) { +export function generateFunctionLeaves(functions: ContractFunctionDao[]) { const targetFunctions = functions.filter(isConstrained); const result: Fr[] = []; for (let i = 0; i < targetFunctions.length; i++) { @@ -88,7 +88,7 @@ export function generateFunctionLeaves(functions: ContractFunctionDao[], wasm: C Fr.fromBuffer(vkHash), Fr.fromBuffer(acirHash), ); - const fnLeaf = computeFunctionLeaf(wasm, fnLeafPreimage); + const fnLeaf = computeFunctionLeaf(fnLeafPreimage); result.push(fnLeaf); } return result; diff --git a/yarn-project/circuits.js/src/structs/complete_address.test.ts b/yarn-project/circuits.js/src/structs/complete_address.test.ts index 52953661b54..c3047a267cb 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.test.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.test.ts @@ -4,26 +4,26 @@ import { Fr, Point } from '@aztec/foundation/fields'; import { CompleteAddress } from './complete_address.js'; describe('CompleteAddress', () => { - it('refuses to add an account with incorrect address for given partial address and pubkey', async () => { - await expect(CompleteAddress.create(AztecAddress.random(), Point.random(), Fr.random())).rejects.toThrowError( + it('refuses to add an account with incorrect address for given partial address and pubkey', () => { + expect(() => CompleteAddress.create(AztecAddress.random(), Point.random(), Fr.random())).toThrowError( /cannot be derived/, ); }); - it('equals returns true when 2 instances are equal', async () => { - const address1 = await CompleteAddress.random(); - const address2 = await CompleteAddress.create(address1.address, address1.publicKey, address1.partialAddress); + it('equals returns true when 2 instances are equal', () => { + const address1 = CompleteAddress.random(); + const address2 = CompleteAddress.create(address1.address, address1.publicKey, address1.partialAddress); expect(address1.equals(address2)).toBe(true); }); - it('equals returns true when 2 instances are not equal', async () => { - const address1 = await CompleteAddress.random(); - const address2 = await CompleteAddress.random(); + it('equals returns true when 2 instances are not equal', () => { + const address1 = CompleteAddress.random(); + const address2 = CompleteAddress.random(); expect(address1.equals(address2)).toBe(false); }); - it('serializes / deserializes correctly', async () => { - const expectedAddress = await CompleteAddress.random(); + it('serializes / deserializes correctly', () => { + const expectedAddress = CompleteAddress.random(); const address = CompleteAddress.fromBuffer(expectedAddress.toBuffer()); expect(address.equals(expectedAddress)).toBe(true); }); diff --git a/yarn-project/circuits.js/src/structs/complete_address.ts b/yarn-project/circuits.js/src/structs/complete_address.ts index e35c98d252c..e0f86e1419d 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.ts @@ -30,13 +30,8 @@ export class CompleteAddress { /** Size in bytes of an instance */ static readonly SIZE_IN_BYTES = 32 * 4; - static async create( - address: AztecAddress, - publicKey: PublicKey, - partialAddress: PartialAddress, - ): Promise { - const wasm = await CircuitsWasm.get(); - const expectedAddress = computeContractAddressFromPartial(wasm, publicKey, partialAddress); + static create(address: AztecAddress, publicKey: PublicKey, partialAddress: PartialAddress) { + const expectedAddress = computeContractAddressFromPartial(publicKey, partialAddress); if (!expectedAddress.equals(address)) { throw new Error( `Address cannot be derived from pubkey and partial address (received ${address.toString()}, derived ${expectedAddress.toString()})`, @@ -45,11 +40,10 @@ export class CompleteAddress { return new CompleteAddress(address, publicKey, partialAddress); } - static async random(): Promise { + static random() { const partialAddress = Fr.random(); const pubKey = Point.random(); - const wasm = await CircuitsWasm.get(); - const address = computeContractAddressFromPartial(wasm, pubKey, partialAddress); + const address = computeContractAddressFromPartial(pubKey, partialAddress); return new CompleteAddress(address, pubKey, partialAddress); } @@ -60,7 +54,7 @@ export class CompleteAddress { const wasm = await CircuitsWasm.get(); const grumpkin = new Grumpkin(wasm); const pubKey = grumpkin.mul(Grumpkin.generator, privateKey); - const address = computeContractAddressFromPartial(wasm, pubKey, partialAddress); + const address = computeContractAddressFromPartial(pubKey, partialAddress); return new CompleteAddress(address, pubKey, partialAddress); } diff --git a/yarn-project/circuits.js/src/structs/public_call_request.ts b/yarn-project/circuits.js/src/structs/public_call_request.ts index e32e045fc9c..6c62b190f4a 100644 --- a/yarn-project/circuits.js/src/structs/public_call_request.ts +++ b/yarn-project/circuits.js/src/structs/public_call_request.ts @@ -1,7 +1,7 @@ import { BufferReader } from '@aztec/foundation/serialize'; import { computeVarArgsHash } from '../abis/abis.js'; -import { CircuitsWasm, FieldsOf } from '../index.js'; +import { FieldsOf } from '../index.js'; import { serializeToBuffer } from '../utils/serialize.js'; import { AztecAddress, @@ -92,10 +92,10 @@ export class PublicCallRequest { * Creates a new PublicCallStackItem by populating with zeroes all fields related to result in the public circuit output. * @returns A PublicCallStackItem instance with the same contract address, function data, call context, and args. */ - async toPublicCallStackItem(): Promise { + toPublicCallStackItem() { const publicInputs = PublicCircuitPublicInputs.empty(); publicInputs.callContext = this.callContext; - publicInputs.argsHash = await this.getArgsHash(); + publicInputs.argsHash = this.getArgsHash(); return new PublicCallStackItem(this.contractAddress, this.functionData, publicInputs, true); } @@ -103,7 +103,7 @@ export class PublicCallRequest { * Returns the hash of the arguments for this request. * @returns Hash of the arguments for this request. */ - async getArgsHash() { - return computeVarArgsHash(await CircuitsWasm.get(), this.args); + getArgsHash() { + return computeVarArgsHash(this.args); } } diff --git a/yarn-project/circuits.js/src/utils/serialize.ts b/yarn-project/circuits.js/src/utils/serialize.ts index c1c79ba0d30..fd75c700d37 100644 --- a/yarn-project/circuits.js/src/utils/serialize.ts +++ b/yarn-project/circuits.js/src/utils/serialize.ts @@ -101,8 +101,10 @@ export function uint8ArrayToNum(array: Uint8Array): number { * @param value - Value to serialize. * @returns The serialized boolean. */ -export function boolToBuffer(value: boolean): Buffer { - return Buffer.from([value ? 1 : 0]); +export function boolToBuffer(value: boolean, bufferSize = 1): Buffer { + const buf = Buffer.alloc(bufferSize); + buf.writeUInt8(value ? 1 : 0, bufferSize - 1); + return buf; } /** diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 778f2b88031..a33f13ae89c 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -443,7 +443,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .addOption(pxeOption) .action(async ({ address, publicKey, partialAddress, rpcUrl }) => { const client = await createCompatibleClient(rpcUrl, debugLogger); - await client.registerRecipient(await CompleteAddress.create(address, publicKey, partialAddress)); + await client.registerRecipient(CompleteAddress.create(address, publicKey, partialAddress)); log(`\nRegistered details for account with address: ${address}\n`); }); diff --git a/yarn-project/cli/src/test/utils.test.ts b/yarn-project/cli/src/test/utils.test.ts index aea7a8bbfc6..28dac48c874 100644 --- a/yarn-project/cli/src/test/utils.test.ts +++ b/yarn-project/cli/src/test/utils.test.ts @@ -33,7 +33,7 @@ describe('CLI Utils', () => { expect(result).toEqual(aztecAddress); // returns an address found in the aztec client - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); client.getRegisteredAccounts.mockResolvedValueOnce([completeAddress]); const resultWithoutString = await getTxSender(client); expect(client.getRegisteredAccounts).toHaveBeenCalled(); diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 58960a8f48d..3c6adc367f0 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -9,7 +9,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000 --forceExit", + "test": "DEBUG='aztec:*' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000 --forceExit", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json" }, diff --git a/yarn-project/end-to-end/scripts/docker-compose-browser.yml b/yarn-project/end-to-end/scripts/docker-compose-browser.yml index ddb5838000b..d3abd8fb74d 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-browser.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-browser.yml @@ -16,6 +16,7 @@ services: image: aztecprotocol/aztec-sandbox:latest environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 @@ -32,6 +33,7 @@ services: environment: BENCHMARK: 'true' DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 PXE_URL: http://sandbox:8080 diff --git a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml index 76d045ebc4b..e810a57db3d 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-no-sandbox.yml @@ -17,6 +17,7 @@ services: environment: BENCHMARK: 'true' DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 diff --git a/yarn-project/end-to-end/scripts/docker-compose-p2p.yml b/yarn-project/end-to-end/scripts/docker-compose-p2p.yml index 9fa069b1ca9..c030caaef20 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-p2p.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-p2p.yml @@ -13,6 +13,7 @@ services: command: 'start' environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 P2P_TCP_LISTEN_PORT: 40400 P2P_TCP_LISTEN_IP: '0.0.0.0' P2P_ANNOUNCE_HOSTNAME: 'p2p-bootstrap' @@ -23,6 +24,7 @@ services: environment: BENCHMARK: true DEBUG: ${DEBUG:-'aztec:*'} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL: 500 diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 81b15fcbd52..9b675470f35 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -16,6 +16,7 @@ services: image: aztecprotocol/aztec-sandbox:latest environment: DEBUG: 'aztec:*' + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 ARCHIVER_POLLING_INTERVAL_MS: 50 @@ -31,8 +32,8 @@ services: image: aztecprotocol/end-to-end:latest environment: BENCHMARK: 'true' - LOG_LEVL: 'debug' DEBUG: ${DEBUG:-aztec:*} + DEBUG_COLORS: 1 ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 PXE_URL: http://sandbox:8080 diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 660d89292b6..ad21409a9de 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -102,7 +102,7 @@ describe('e2e_2_pxes', () => { const mintTokens = async (contract: TokenContract, recipient: AztecAddress, balance: bigint, pxe: PXE) => { const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await contract.methods.mint_private(balance, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index 1a2b49aa10c..d6eccd46936 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -1,6 +1,5 @@ import { BatchCall, - CircuitsWasm, ContractDeployer, ContractFunctionInteraction, DebugLogger, @@ -10,7 +9,7 @@ import { Wallet, isContractDeployed, } from '@aztec/aztec.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { TestContractArtifact } from '@aztec/noir-contracts/artifacts'; import { TestContract, TokenContract } from '@aztec/noir-contracts/types'; @@ -136,10 +135,7 @@ describe('e2e_block_building', () => { it('drops tx with private nullifier already emitted from public on the same block', async () => { const secret = Fr.random(); // See yarn-project/acir-simulator/src/public/index.test.ts 'Should be able to create a nullifier from the public context' - const emittedPublicNullifier = pedersenHashInputs( - await CircuitsWasm.get(), - [new Fr(140), secret].map(a => a.toBuffer()), - ); + const emittedPublicNullifier = pedersenHash([new Fr(140), secret].map(a => a.toBuffer())); const calls = [ contract.methods.create_nullifier_public(140n, secret), diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 39dcc9477d1..d14102622f4 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -207,7 +207,7 @@ describe('e2e_cheat_codes', () => { // docs:start:load_private_cheatcode const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const note = new Note([new Fr(mintAmount), secretHash]); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 457ff3a7431..d3269892776 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -59,9 +59,9 @@ describe('e2e_cross_chain_messaging', () => { const bridgeAmount = 100n; const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const [secretForRedeemingMintedNotes, secretHashForRedeemingMintedNotes] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); // 1. Mint tokens on L1 await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); @@ -99,7 +99,7 @@ describe('e2e_cross_chain_messaging', () => { // 4. Give approval to bridge to burn owner's funds: const withdrawAmount = 9n; const nonce = Fr.random(); - const burnMessageHash = await computeAuthWitMessageHash( + const burnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn(ownerAddress, withdrawAmount, nonce).request(), ); @@ -124,9 +124,9 @@ describe('e2e_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const [secretForRedeemingMintedNotes, secretHashForRedeemingMintedNotes] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( @@ -190,7 +190,7 @@ describe('e2e_cross_chain_messaging', () => { const withdrawAmount = 9n; const nonce = Fr.random(); - const expectedBurnMessageHash = await computeAuthWitMessageHash( + const expectedBurnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn(user1Wallet.getAddress(), withdrawAmount, nonce).request(), ); @@ -210,7 +210,7 @@ describe('e2e_cross_chain_messaging', () => { // 2. Deposit tokens to the TokenPortal privately const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] = - await crossChainTestHarness.generateClaimSecret(); + crossChainTestHarness.generateClaimSecret(); const messageKey = await crossChainTestHarness.sendTokensToPortalPrivate( Fr.random(), diff --git a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts index aac0dae8adc..97a1fb488de 100644 --- a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts @@ -68,7 +68,7 @@ describe('e2e_escrow_contract', () => { const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); @@ -115,7 +115,7 @@ describe('e2e_escrow_contract', () => { logger(`Minting funds in token contract to ${owner}`); const mintAmount = 50n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index 7cb444bc2d3..7c3f0ee627a 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -115,7 +115,7 @@ describe('e2e_lending_contract', () => { const mintAmount = 10000n; for (const asset of assets) { const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const a = asset.methods.mint_public(lendingAccount.address, mintAmount).send(); const b = asset.methods.mint_private(mintAmount, secretHash).send(); @@ -152,7 +152,7 @@ describe('e2e_lending_contract', () => { it('Depositing 🥸 : 💰 -> 🏦', async () => { const depositAmount = 420n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .unshield(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -161,7 +161,7 @@ describe('e2e_lending_contract', () => { await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); await lendingSim.progressTime(TIME_JUMP); - lendingSim.depositPrivate(lendingAccount.address, await lendingAccount.key(), depositAmount); + lendingSim.depositPrivate(lendingAccount.address, lendingAccount.key(), depositAmount); // Make a private deposit of funds into own account. // This should: @@ -186,7 +186,7 @@ describe('e2e_lending_contract', () => { it('Depositing 🥸 on behalf of recipient: 💰 -> 🏦', async () => { const depositAmount = 421n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .unshield(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -220,7 +220,7 @@ describe('e2e_lending_contract', () => { const depositAmount = 211n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, collateralAsset.methods .transfer_public(lendingAccount.address, lendingContract.address, depositAmount, nonce) @@ -264,7 +264,7 @@ describe('e2e_lending_contract', () => { it('Borrow 🥸 : 🏦 -> 🍌', async () => { const borrowAmount = 69n; await lendingSim.progressTime(TIME_JUMP); - lendingSim.borrow(await lendingAccount.key(), lendingAccount.address, borrowAmount); + lendingSim.borrow(lendingAccount.key(), lendingAccount.address, borrowAmount); // Make a private borrow using the private account // This should: @@ -298,14 +298,14 @@ describe('e2e_lending_contract', () => { it('Repay 🥸 : 🍌 -> 🏦', async () => { const repayAmount = 20n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); await lendingSim.progressTime(TIME_JUMP); - lendingSim.repayPrivate(lendingAccount.address, await lendingAccount.key(), repayAmount); + lendingSim.repayPrivate(lendingAccount.address, lendingAccount.key(), repayAmount); // Make a private repay of the debt in the private account // This should: @@ -324,7 +324,7 @@ describe('e2e_lending_contract', () => { it('Repay 🥸 on behalf of public: 🍌 -> 🏦', async () => { const repayAmount = 21n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); @@ -351,7 +351,7 @@ describe('e2e_lending_contract', () => { const repayAmount = 20n; const nonce = Fr.random(); - const messageHash = await computeAuthWitMessageHash( + const messageHash = computeAuthWitMessageHash( lendingContract.address, stableCoin.methods.burn_public(lendingAccount.address, repayAmount, nonce).request(), ); @@ -394,7 +394,7 @@ describe('e2e_lending_contract', () => { it('Withdraw 🥸 : 🏦 -> 💰', async () => { const withdrawAmount = 42n; await lendingSim.progressTime(TIME_JUMP); - lendingSim.withdraw(await lendingAccount.key(), lendingAccount.address, withdrawAmount); + lendingSim.withdraw(lendingAccount.key(), lendingAccount.address, withdrawAmount); // Withdraw funds from the private account // This should: diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index c33691c42a2..9cb2bd8b16d 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -74,7 +74,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => { logger(`Token deployed at ${tokenAddress}`); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); expect(receipt.status).toEqual(TxStatus.MINED); diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 3844c39aac5..64e987fba80 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -1,6 +1,5 @@ import { AztecNode, - CircuitsWasm, DebugLogger, ExtendedNote, Fr, @@ -47,7 +46,7 @@ describe('e2e_non_contract_account', () => { expect(receipt.status).toBe(TxStatus.MINED); const tx = await aztecNode!.getTx(receipt.txHash); - const expectedSiloedNullifier = siloNullifier(await CircuitsWasm.get(), contract.address, nullifier); + const expectedSiloedNullifier = siloNullifier(contract.address, nullifier); const siloedNullifier = tx!.newNullifiers[1]; expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy(); diff --git a/yarn-project/end-to-end/src/e2e_ordering.test.ts b/yarn-project/end-to-end/src/e2e_ordering.test.ts index 51f10670598..b8f704a9a06 100644 --- a/yarn-project/end-to-end/src/e2e_ordering.test.ts +++ b/yarn-project/end-to-end/src/e2e_ordering.test.ts @@ -65,7 +65,7 @@ describe('e2e_ordering', () => { expect(enqueuedPublicCalls.length).toEqual(2); // The call stack hashes in the output of the kernel proof match the tx enqueuedPublicFunctionCalls - const hashes = await Promise.all(enqueuedPublicCalls.map(c => c.toPublicCallStackItem().then(i => i.hash()))); + const hashes = await Promise.all(enqueuedPublicCalls.map(c => c.toPublicCallStackItem().hash())); expect(tx.data.end.publicCallStack.slice(0, 2)).toEqual(hashes); // The enqueued public calls are in the expected order based on the argument they set (stack is reversed!) diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 3c906d017fc..d38a705e891 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -59,7 +59,7 @@ describe('e2e_public_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); // 1. Mint tokens on L1 await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); @@ -88,7 +88,7 @@ describe('e2e_public_cross_chain_messaging', () => { // 4. Give approval to bridge to burn owner's funds: const withdrawAmount = 9n; const nonce = Fr.random(); - const burnMessageHash = await computeAuthWitMessageHash( + const burnMessageHash = computeAuthWitMessageHash( l2Bridge.address, l2Token.methods.burn_public(ownerAddress, withdrawAmount, nonce).request(), ); @@ -115,7 +115,7 @@ describe('e2e_public_cross_chain_messaging', () => { const l1TokenBalance = 1000000n; const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); @@ -167,7 +167,7 @@ describe('e2e_public_cross_chain_messaging', () => { it("can't claim funds privately which were intended for public deposit from the token portal", async () => { const bridgeAmount = 100n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(bridgeAmount); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); diff --git a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts index 5fed92844e4..e07a5cf57d4 100644 --- a/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts @@ -44,7 +44,7 @@ describe('e2e_public_to_private_messaging', () => { const bridgeAmount = 100n; const shieldAmount = 50n; - const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); + const [secret, secretHash] = crossChainTestHarness.generateClaimSecret(); await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const messageKey = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount, secretHash); diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 782e17a4619..814feb26b49 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -69,7 +69,7 @@ describe('e2e_sandbox_example', () => { // Create a secret and a corresponding hash that will be used to mint funds privately const aliceSecret = Fr.random(); - const aliceSecretHash = await computeMessageSecretHash(aliceSecret); + const aliceSecretHash = computeMessageSecretHash(aliceSecret); logger(`Minting tokens to Alice...`); // Mint the initial supply privately "to secret hash" @@ -136,7 +136,7 @@ describe('e2e_sandbox_example', () => { await tokenContractAlice.methods.set_minter(bob, true).send().wait(); const bobSecret = Fr.random(); - const bobSecretHash = await computeMessageSecretHash(bobSecret); + const bobSecretHash = computeMessageSecretHash(bobSecret); // Bob now has a secret 🥷 const mintQuantity = 10_000n; diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index 009e276095d..5acdf39a0de 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -156,8 +156,8 @@ describe('e2e_token_contract', () => { let secretHash: Fr; let txHash: TxHash; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); describe('Mint flow', () => { @@ -257,7 +257,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // docs:end:authwit_public_transfer_example @@ -318,7 +318,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -341,7 +341,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); @@ -363,7 +363,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); // Perform the transfer @@ -415,7 +415,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // docs:end:authwit_computeAuthWitMessageHash const witness = await wallets[0].createAuthWitness(messageHash); @@ -466,7 +466,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -497,7 +497,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -514,8 +514,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); @@ -533,8 +533,8 @@ describe('e2e_token_contract', () => { const secret = Fr.random(); let secretHash: Fr; - beforeAll(async () => { - secretHash = await computeMessageSecretHash(secret); + beforeAll(() => { + secretHash = computeMessageSecretHash(secret); }); it('on behalf of self', async () => { @@ -566,7 +566,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -621,7 +621,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -635,7 +635,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Message not authorized by account'); @@ -677,7 +677,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -729,7 +729,7 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[1]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -750,8 +750,8 @@ describe('e2e_token_contract', () => { const action = asset .withWallet(wallets[2]) .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -787,7 +787,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); const tx = action.send(); @@ -838,7 +838,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect(action.simulate()).rejects.toThrowError('Assertion failed: Underflow'); @@ -852,7 +852,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[0].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[0].address, action.request()); await wallets[0].setPublicAuth(messageHash, true).send().wait(); await expect( @@ -881,7 +881,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -926,7 +926,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); @@ -945,7 +945,7 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, @@ -960,8 +960,8 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); - const messageHash = await computeAuthWitMessageHash(accounts[1].address, action.request()); - const expectedMessageHash = await computeAuthWitMessageHash(accounts[2].address, action.request()); + const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); + const expectedMessageHash = computeAuthWitMessageHash(accounts[2].address, action.request()); const witness = await wallets[0].createAuthWitness(messageHash); await wallets[2].addAuthWitness(witness); diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 4f688f38ed6..ee03c984ba6 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -43,7 +43,7 @@ describe('guides/dapp/testing', () => { const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); // The storage slot of `pending_shields` is 5. @@ -76,7 +76,7 @@ describe('guides/dapp/testing', () => { const recipientAddress = recipient.getAddress(); const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); @@ -130,7 +130,7 @@ describe('guides/dapp/testing', () => { const ownerAddress = owner.getAddress(); const mintAmount = 100n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(100n, secretHash).send().wait(); const storageSlot = new Fr(5); @@ -252,7 +252,7 @@ describe('guides/dapp/testing', () => { const mintAmount = 20n; const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); const storageSlot = new Fr(5); diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index 890936886fa..867c1f998d2 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -67,7 +67,7 @@ describe('guides/writing_an_account_contract', () => { logger(`Deployed token contract at ${token.address}`); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const mintAmount = 50n; const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index 648db721679..83746e71497 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -78,7 +78,7 @@ describe('archiver integration with l1 to l2 messages', () => { // Generate a claim secret using pedersen logger("Generating a claim secret using pedersen's hash function"); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`; logger('Generated claim secret: ' + secretString); diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index 95ded0f40c5..050c5f4f814 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -72,6 +72,10 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL pageLogger.error(err.toString()); }); await page.goto(`http://localhost:${PORT}/index.html`); + while (!(await page.evaluate(() => !!window.AztecJs))) { + pageLogger('Waiting for window.AztecJs...'); + await AztecJs.sleep(1000); + } }, 120_000); afterAll(async () => { @@ -199,7 +203,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL const token = await Contract.at(receipt.contractAddress!, TokenContractArtifact, owner); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); const mintPrivateReceipt = await token.methods.mint_private(initialBalance, secretHash).send().wait(); const storageSlot = new Fr(5); diff --git a/yarn-project/end-to-end/src/shared/cli.ts b/yarn-project/end-to-end/src/shared/cli.ts index bcc500edc9f..59de7abe3b5 100644 --- a/yarn-project/end-to-end/src/shared/cli.ts +++ b/yarn-project/end-to-end/src/shared/cli.ts @@ -131,7 +131,7 @@ export const cliTestSuite = ( expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); debug('Mint initial tokens.'); await run( diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index 952190af5b0..b3b8374be45 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -202,10 +202,10 @@ export class CrossChainTestHarness { public ownerAddress: AztecAddress, ) {} - async generateClaimSecret(): Promise<[Fr, Fr]> { + generateClaimSecret(): [Fr, Fr] { this.logger("Generating a claim secret using pedersen's hash function"); const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); + const secretHash = computeMessageSecretHash(secret); this.logger('Generated claim secret: ' + secretHash.toString(true)); return [secret, secretHash]; } diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 44a7584523f..3825ed735a7 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -156,8 +156,8 @@ export const uniswapL1L2TestSuite = ( const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress); // 1. Approve and deposit weth to the portal and move to L2 - const [secretForMintingWeth, secretHashForMintingWeth] = await wethCrossChainHarness.generateClaimSecret(); - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); const messageKey = await wethCrossChainHarness.sendTokensToPortalPrivate( secretHashForRedeemingWeth, @@ -200,7 +200,7 @@ export const uniswapL1L2TestSuite = ( // 3. Owner gives uniswap approval to unshield funds to self on its behalf logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(1n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -211,8 +211,8 @@ export const uniswapL1L2TestSuite = ( // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. logger('Withdrawing weth to L1 and sending message to swap to dai'); const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = - await daiCrossChainHarness.generateClaimSecret(); - const [secretForRedeemingDai, secretHashForRedeemingDai] = await daiCrossChainHarness.generateClaimSecret(); + daiCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingDai, secretHashForRedeemingDai] = daiCrossChainHarness.generateClaimSecret(); const withdrawReceipt = await uniswapL2Contract.methods .swap_private( @@ -304,7 +304,7 @@ export const uniswapL1L2TestSuite = ( const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress); // 1. Approve and deposit weth to the portal and move to L2 - const [secretForMintingWeth, secretHashForMintingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret(); const messageKey = await wethCrossChainHarness.sendTokensToPortalPublic( wethAmountToBridge, @@ -339,7 +339,7 @@ export const uniswapL1L2TestSuite = ( // 3. Owner gives uniswap approval to transfer funds on its behalf const nonceForWETHTransferApproval = new Fr(1n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -353,7 +353,7 @@ export const uniswapL1L2TestSuite = ( // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = - await daiCrossChainHarness.generateClaimSecret(); + daiCrossChainHarness.generateClaimSecret(); // 4.1 Owner approves user to swap on their behalf: const nonceForSwap = new Fr(3n); @@ -374,7 +374,7 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, nonceForSwap, ); - const swapMessageHash = await computeAuthWitMessageHash(sponsorAddress, action.request()); + const swapMessageHash = computeAuthWitMessageHash(sponsorAddress, action.request()); await ownerWallet.setPublicAuth(swapMessageHash, true).send().wait(); // 4.2 Call swap_public from user2 on behalf of owner @@ -451,7 +451,7 @@ export const uniswapL1L2TestSuite = ( // swap should fail since no withdraw approval to uniswap: const nonceForWETHUnshieldApproval = new Fr(2n); - const expectedMessageHash = await computeAuthWitMessageHash( + const expectedMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -480,7 +480,7 @@ export const uniswapL1L2TestSuite = ( it("can't swap if user passes a token different to what the bridge tracks", async () => { // 1. give user private funds on L2: - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); await wethCrossChainHarness.mintTokensPrivateOnL2(wethAmountToBridge, secretHashForRedeemingWeth); await wethCrossChainHarness.redeemShieldPrivatelyOnL2(wethAmountToBridge, secretForRedeemingWeth); await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethAmountToBridge); @@ -488,7 +488,7 @@ export const uniswapL1L2TestSuite = ( // 2. owner gives uniswap approval to unshield funds: logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(3n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -526,7 +526,7 @@ export const uniswapL1L2TestSuite = ( // 2. Give approval to uniswap to transfer funds to itself const nonceForWETHTransferApproval = new Fr(2n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -535,7 +535,7 @@ export const uniswapL1L2TestSuite = ( await ownerWallet.setPublicAuth(transferMessageHash, true).send().wait(); // No approval to call `swap` but should work even without it: - const [_, secretHashForDepositingSwappedDai] = await daiCrossChainHarness.generateClaimSecret(); + const [_, secretHashForDepositingSwappedDai] = daiCrossChainHarness.generateClaimSecret(); const withdrawReceipt = await uniswapL2Contract.methods .swap_public( @@ -584,7 +584,7 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, nonceForSwap, ); - const swapMessageHash = await computeAuthWitMessageHash(approvedUser, action.request()); + const swapMessageHash = computeAuthWitMessageHash(approvedUser, action.request()); await ownerWallet.setPublicAuth(swapMessageHash, true).send().wait(); // Swap! @@ -597,7 +597,7 @@ export const uniswapL1L2TestSuite = ( // swap should fail since no transfer approval to uniswap: const nonceForWETHTransferApproval = new Fr(4n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) @@ -629,7 +629,7 @@ export const uniswapL1L2TestSuite = ( // tests when trying to mix private and public flows: it("can't call swap_public on L1 if called swap_private on L2", async () => { // get tokens on L2: - const [secretForRedeemingWeth, secretHashForRedeemingWeth] = await wethCrossChainHarness.generateClaimSecret(); + const [secretForRedeemingWeth, secretHashForRedeemingWeth] = wethCrossChainHarness.generateClaimSecret(); logger('minting weth on L2'); await wethCrossChainHarness.mintTokensPrivateOnL2(wethAmountToBridge, secretHashForRedeemingWeth); await wethCrossChainHarness.redeemShieldPrivatelyOnL2(wethAmountToBridge, secretForRedeemingWeth); @@ -638,7 +638,7 @@ export const uniswapL1L2TestSuite = ( logger('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(4n); - const unshieldToUniswapMessageHash = await computeAuthWitMessageHash( + const unshieldToUniswapMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) @@ -699,7 +699,7 @@ export const uniswapL1L2TestSuite = ( // Owner gives uniswap approval to transfer funds on its behalf const nonceForWETHTransferApproval = new Fr(5n); - const transferMessageHash = await computeAuthWitMessageHash( + const transferMessageHash = computeAuthWitMessageHash( uniswapL2Contract.address, wethCrossChainHarness.l2Token.methods .transfer_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval) diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index 159a606628f..c5d6bdcf706 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -1,6 +1,6 @@ // Convenience struct to hold an account's address and secret that can easily be passed around. -import { AztecAddress, CheatCodes, CircuitsWasm, Fr } from '@aztec/aztec.js'; -import { pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { AztecAddress, CheatCodes, Fr } from '@aztec/aztec.js'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { LendingContract } from '@aztec/noir-contracts/types'; import { TokenSimulator } from './token_simulator.js'; @@ -23,13 +23,8 @@ export class LendingAccount { * Computes the key for the private holdings of this account. * @returns Key in public space */ - public async key(): Promise { - return Fr.fromBuffer( - pedersenHashInputs( - await CircuitsWasm.get(), - [this.address, this.secret].map(f => f.toBuffer()), - ), - ); + public key() { + return Fr.fromBuffer(pedersenHash([this.address, this.secret].map(f => f.toBuffer()))); } } @@ -174,7 +169,7 @@ export class LendingSimulator { expect(asset['interest_accumulator']).toEqual(this.accumulator); expect(asset['last_updated_ts']).toEqual(BigInt(this.time)); - for (const key of [this.account.address, await this.account.key()]) { + for (const key of [this.account.address, this.account.key()]) { const privatePos = await this.lendingContract.methods.get_position(key).view(); expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO); expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO); diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index ef597d2b308..d71d41889d5 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -42,6 +42,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", + "test:light": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" }, "inherits": [ @@ -56,10 +57,13 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/bb.js": "portal:../../barretenberg/ts", "@koa/cors": "^4.0.0", "@noble/curves": "^1.2.0", + "bn.js": "^5.2.1", "debug": "^4.3.4", "detect-node": "^2.1.0", + "elliptic": "^6.5.4", "hash.js": "^1.1.7", "koa": "^2.14.2", "koa-bodyparser": "^4.4.0", @@ -76,8 +80,10 @@ "devDependencies": { "@jest/globals": "^29.5.0", "@rushstack/eslint-patch": "^1.1.4", + "@types/bn.js": "^5.1.3", "@types/debug": "^4.1.7", "@types/detect-node": "^2.0.0", + "@types/elliptic": "^6.4.16", "@types/jest": "^29.5.0", "@types/koa": "^2.13.5", "@types/koa-bodyparser": "^4.3.10", diff --git a/yarn-project/foundation/src/abi/function_selector.ts b/yarn-project/foundation/src/abi/function_selector.ts index fbfc56f79b6..ac20bcb3620 100644 --- a/yarn-project/foundation/src/abi/function_selector.ts +++ b/yarn-project/foundation/src/abi/function_selector.ts @@ -29,10 +29,11 @@ export class FunctionSelector { /** * Serialize as a buffer. + * @param bufferSize - The buffer size. * @returns The buffer. */ - toBuffer(): Buffer { - return toBufferBE(BigInt(this.value), FunctionSelector.SIZE); + toBuffer(bufferSize = FunctionSelector.SIZE): Buffer { + return toBufferBE(BigInt(this.value), bufferSize); } /** diff --git a/yarn-project/foundation/src/async-map/async_map.test.ts b/yarn-project/foundation/src/async-map/async_map.test.ts index 2ec4c370153..e64256c4ca6 100644 --- a/yarn-project/foundation/src/async-map/async_map.test.ts +++ b/yarn-project/foundation/src/async-map/async_map.test.ts @@ -1,7 +1,7 @@ import { asyncMap } from './index.js'; describe('asyncMap', () => { - test('execute list item sequentially', async () => { + it('execute list item sequentially', async () => { const sleepAndLog = (ms: number, idx: number) => new Promise(resolve => setTimeout(() => resolve(idx), ms)); const result = await asyncMap([100, 0, 30, 1], (ms, i) => sleepAndLog(ms, i)); expect(result).toEqual([0, 1, 2, 3]); diff --git a/yarn-project/foundation/src/crypto/index.ts b/yarn-project/foundation/src/crypto/index.ts index de07953e43b..98abed1dacd 100644 --- a/yarn-project/foundation/src/crypto/index.ts +++ b/yarn-project/foundation/src/crypto/index.ts @@ -1,3 +1,4 @@ export * from './keccak/index.js'; export * from './random/index.js'; export * from './sha256/index.js'; +export * from './pedersen/index.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/index.test.ts b/yarn-project/foundation/src/crypto/pedersen/index.test.ts index 385dadfc8ec..0640c13d0b1 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.test.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.test.ts @@ -1,5 +1,5 @@ import { toBufferBE } from '../../bigint-buffer/index.js'; -import { pedersenCommit, pedersenHashWithHashIndex } from './index.js'; +import { pedersenCommit, pedersenHash } from './index.js'; describe('pedersen', () => { it('pedersen commit', () => { @@ -10,13 +10,21 @@ describe('pedersen', () => { ]); }); + it('pedersen commit with zero', () => { + const r = pedersenCommit([toBufferBE(0n, 32), toBufferBE(1n, 32)]); + expect(r).toEqual([ + Buffer.from('054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402', 'hex'), + Buffer.from('209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126', 'hex'), + ]); + }); + it('pedersen hash', () => { - const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)]); + const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)]); expect(r).toEqual(Buffer.from('07ebfbf4df29888c6cd6dca13d4bb9d1a923013ddbbcbdc3378ab8845463297b', 'hex')); }); it('pedersen hash with index', () => { - const r = pedersenHashWithHashIndex([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5); + const r = pedersenHash([toBufferBE(1n, 32), toBufferBE(1n, 32)], 5); expect(r).toEqual(Buffer.from('1c446df60816b897cda124524e6b03f36df0cec333fad87617aab70d7861daa6', 'hex')); }); }); diff --git a/yarn-project/foundation/src/crypto/pedersen/index.ts b/yarn-project/foundation/src/crypto/pedersen/index.ts index fe63fbaf757..c85dafd4ca4 100644 --- a/yarn-project/foundation/src/crypto/pedersen/index.ts +++ b/yarn-project/foundation/src/crypto/pedersen/index.ts @@ -1,309 +1 @@ -/* cSpell:disable */ -import { Field } from '@noble/curves/abstract/modular'; -import { weierstrassPoints } from '@noble/curves/abstract/weierstrass'; - -import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js'; - -const grumpkin = weierstrassPoints({ - a: 0n, - b: 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0n, - Fp: Field(0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n), - n: 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n, - h: 1n, - Gx: 1n, - Gy: 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272cn, -}); - -const defaultGenerators = [ - [ - 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, - 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, - ], - [ - 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, - 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, - ], - [ - 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, - 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, - ], - [ - 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, - 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, - ], - [ - 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, - 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, - ], - [ - 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, - 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, - ], - [ - 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, - 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, - ], - [ - 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, - 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, - ], - [ - 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, - 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, - ], - [ - 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, - 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, - ], - [ - 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, - 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, - ], - [ - 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, - 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, - ], - [ - 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, - 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, - ], - [ - 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, - 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, - ], - [ - 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, - 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, - ], - [ - 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, - 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, - ], - [ - 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, - 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, - ], - [ - 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, - 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, - ], - [ - 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, - 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, - ], - [ - 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, - 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, - ], - [ - 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, - 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, - ], - [ - 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, - 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, - ], - [ - 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, - 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, - ], - [ - 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, - 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, - ], - [ - 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, - 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, - ], - [ - 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, - 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, - ], - [ - 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, - 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, - ], - [ - 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, - 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, - ], - [ - 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, - 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, - ], - [ - 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, - 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, - ], - [ - 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, - 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, - ], - [ - 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, - 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, - ], - [ - 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, - 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, - ], - [ - 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, - 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, - ], - [ - 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, - 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, - ], - [ - 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, - 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, - ], - [ - 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, - 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, - ], - [ - 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, - 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, - ], - [ - 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, - 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, - ], - [ - 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, - 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, - ], - [ - 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, - 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, - ], - [ - 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, - 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, - ], - [ - 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, - 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, - ], - [ - 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, - 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, - ], - [ - 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, - 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, - ], - [ - 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, - 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, - ], - [ - 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, - 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, - ], - [ - 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, - 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, - ], - [ - 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, - 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, - ], - [ - 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, - 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, - ], - [ - 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, - 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, - ], - [ - 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, - 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, - ], - [ - 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, - 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, - ], - [ - 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, - 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, - ], - [ - 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, - 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, - ], - [ - 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, - 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, - ], - [ - 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, - 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, - ], - [ - 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, - 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, - ], - [ - 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, - 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, - ], - [ - 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, - 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, - ], - [ - 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, - 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, - ], - [ - 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, - 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, - ], - [ - 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, - 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, - ], - [ - 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, - 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, - ], -].map(([x, y]) => new grumpkin.ProjectivePoint(x, y, 1n)); - -const lengthGenerator = new grumpkin.ProjectivePoint( - 0x2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcdn, - 0x2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083n, - 1n, -); - -const pointAtInfinity = lengthGenerator.subtract(lengthGenerator); - -/** - * Create a pedersen commitment (point) from an array of input fields. - */ -function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { - if (generatorOffset + input.length > defaultGenerators.length) { - throw new Error('Pedersen commit overflowed default generators.'); - } - const generators = defaultGenerators.slice(generatorOffset, generatorOffset + input.length); - return generators.reduce((a, g, i) => a.add(g.multiply(toBigIntBE(input[i]))), pointAtInfinity); -} - -/** - * Create a pedersen commitment (point) from an array of input fields. - */ -export function pedersenCommit(input: Buffer[], generatorOffset = 0) { - const result = pedersenCommitInternal(input, generatorOffset); - return [toBufferBE(result.x, 32), toBufferBE(result.y, 32)]; -} - -/** - * Create a pedersen hash (field) from an array of input fields. - */ -export function pedersenHashWithHashIndex(input: Buffer[], index = 0) { - const result = lengthGenerator.multiply(BigInt(input.length)); - return toBufferBE(result.add(pedersenCommitInternal(input, index)).x, 32); -} +export * from './pedersen.wasm.js'; diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts new file mode 100644 index 00000000000..0ff91b5abe6 --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.elliptic.ts @@ -0,0 +1,584 @@ +/** + * This is about 10x slower than WASM pedersen. + * But note that if run within jest it's like, 100x slower. + * I banged my head against a wall for a weekend trying to understand why, profiling and everything. + * Ultimately I discovered that using jest-runner-light resolved that, and still it's a mystery to me. + * Given it's 10x slower anyway, this might be fine for small hash calculations, but not for merkle trees. + */ +import BN from 'bn.js'; +// eslint-disable-next-line +import EC from 'elliptic'; + +// eslint-disable-next-line +const grumpkin = new EC.curve.short({ + a: '0', + b: new BN('30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0', 16), + p: new BN('30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001', 16), + n: new BN('30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47', 16), + g: ['1', new BN('0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c', 16)], +} as any); + +const defaultGenerators = [ + [ + 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, + 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, + ], + [ + 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, + 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, + ], + [ + 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, + 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, + ], + [ + 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, + 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, + ], + [ + 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, + 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, + ], + [ + 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, + 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, + ], + [ + 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, + 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, + ], + [ + 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, + 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, + ], + [ + 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, + 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, + ], + [ + 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, + 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, + ], + [ + 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, + 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, + ], + [ + 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, + 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, + ], + [ + 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, + 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, + ], + [ + 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, + 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, + ], + [ + 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, + 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, + ], + [ + 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, + 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, + ], + [ + 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, + 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, + ], + [ + 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, + 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, + ], + [ + 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, + 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, + ], + [ + 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, + 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, + ], + [ + 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, + 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, + ], + [ + 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, + 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, + ], + [ + 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, + 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, + ], + [ + 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, + 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, + ], + [ + 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, + 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, + ], + [ + 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, + 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, + ], + [ + 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, + 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, + ], + [ + 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, + 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, + ], + [ + 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, + 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, + ], + [ + 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, + 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, + ], + [ + 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, + 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, + ], + [ + 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, + 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, + ], + [ + 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, + 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, + ], + [ + 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, + 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, + ], + [ + 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, + 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, + ], + [ + 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, + 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, + ], + [ + 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, + 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, + ], + [ + 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, + 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, + ], + [ + 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, + 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, + ], + [ + 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, + 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, + ], + [ + 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, + 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, + ], + [ + 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, + 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, + ], + [ + 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, + 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, + ], + [ + 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, + 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, + ], + [ + 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, + 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, + ], + [ + 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, + 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, + ], + [ + 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, + 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, + ], + [ + 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, + 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, + ], + [ + 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, + 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, + ], + [ + 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, + 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, + ], + [ + 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, + 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, + ], + [ + 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, + 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, + ], + [ + 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, + 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, + ], + [ + 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, + 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, + ], + [ + 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, + 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, + ], + [ + 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, + 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, + ], + [ + 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, + 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, + ], + [ + 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, + 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, + ], + [ + 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, + 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, + ], + [ + 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, + 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, + ], + [ + 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, + 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, + ], + [ + 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, + 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, + ], + [ + 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, + 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, + ], + [ + 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, + 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, + ], + [ + 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, + 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, + ], + [ + 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, + 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, + ], + [ + 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, + 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, + ], + [ + 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, + 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, + ], + [ + 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, + 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, + ], + [ + 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, + 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, + ], + [ + 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, + 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, + ], + [ + 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, + 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, + ], + [ + 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, + 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, + ], + [ + 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, + 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, + ], + [ + 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, + 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, + ], + [ + 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, + 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, + ], + [ + 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, + 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, + ], + [ + 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, + 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, + ], + [ + 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, + 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, + ], + [ + 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, + 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, + ], + [ + 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, + 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, + ], + [ + 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, + 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, + ], + [ + 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, + 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, + ], + [ + 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, + 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, + ], + [ + 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, + 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, + ], + [ + 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, + 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, + ], + [ + 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, + 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, + ], + [ + 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, + 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, + ], + [ + 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, + 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, + ], + [ + 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, + 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, + ], + [ + 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, + 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, + ], + [ + 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, + 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, + ], + [ + 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, + 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, + ], + [ + 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, + 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, + ], + [ + 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, + 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, + ], + [ + 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, + 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, + ], + [ + 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, + 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, + ], + [ + 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, + 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, + ], + [ + 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, + 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, + ], + [ + 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, + 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, + ], + [ + 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, + 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, + ], + [ + 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, + 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, + ], + [ + 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, + 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, + ], + [ + 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, + 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, + ], + [ + 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, + 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, + ], + [ + 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, + 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, + ], + [ + 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, + 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, + ], + [ + 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, + 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, + ], + [ + 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, + 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, + ], + [ + 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, + 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, + ], + [ + 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, + 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, + ], + [ + 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, + 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, + ], + [ + 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, + 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, + ], + [ + 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, + 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, + ], + [ + 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, + 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, + ], + [ + 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, + 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, + ], + [ + 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, + 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, + ], + [ + 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, + 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, + ], + [ + 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, + 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, + ], + [ + 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, + 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, + ], + [ + 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, + 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, + ], + [ + 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, + 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, + ], + [ + 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, + 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, + ], + [ + 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, + 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, + ], + [ + 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, + 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, + ], + [ + 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, + 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, + ], + [ + 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, + 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, + ], + [ + 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, + 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, + ], +].map(([x, y]) => grumpkin.point(new BN(x.toString(16), 16), new BN(y.toString(16), 16))); + +const lengthGenerator = grumpkin.point( + new BN('2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcd', 16), + new BN('2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083', 16), +); + +const pointAtInfinity = grumpkin.g.add(grumpkin.g.neg()); + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { + if (generatorOffset + input.length > defaultGenerators.length) { + throw new Error('Pedersen commit overflowed default generators.'); + } + let result = pointAtInfinity; + for (let i = 0; i < input.length; ++i) { + // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. + // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? + const ie = new BN(input[i]).mod(grumpkin.p); + result = ie ? result.add(defaultGenerators[generatorOffset + i].mul(ie)) : result; + } + return result; +} + +/** + * Create a pedersen commitment (point) from an array of input fields. + * Left pads any inputs less than 32 bytes. + */ +export function pedersenCommit(input: Buffer[], generatorOffset = 0) { + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); + const result = pedersenCommitInternal(input, generatorOffset); + return [result.getX().toBuffer(), result.getY().toBuffer()]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + * Left pads any inputs less than 32 bytes. + */ +export function pedersenHash(input: Buffer[], index = 0) { + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); + const result = lengthGenerator.mul(new BN(input.length)); + return result.add(pedersenCommitInternal(input, index)).getX().toBuffer(); +} diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts new file mode 100644 index 00000000000..d9ae4080114 --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.noble.ts @@ -0,0 +1,573 @@ +/* cSpell:disable */ +import { Field } from '@noble/curves/abstract/modular'; +import { weierstrassPoints } from '@noble/curves/abstract/weierstrass'; + +import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js'; + +const grumpkin = weierstrassPoints({ + a: 0n, + b: 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effffff0n, + Fp: Field(0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n), + n: 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n, + h: 1n, + Gx: 1n, + Gy: 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272cn, +}); + +const defaultGenerators = [ + [ + 0x083e7911d835097629f0067531fc15cafd79a89beecb39903f69572c636f4a5an, + 0x1a7f5efaad7f315c25a918f30cc8d7333fccab7ad7c90f14de81bcc528f9935dn, + ], + [ + 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402n, + 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126n, + ], + [ + 0x1c44f2a5207c81c28a8321a5815ce8b1311024bbed131819bbdaf5a2ada84748n, + 0x03aaee36e6422a1d0191632ac6599ae9eba5ac2c17a8c920aa3caf8b89c5f8a8n, + ], + [ + 0x26d8b1160c6821a30c65f6cb47124afe01c29f4338f44d4a12c9fccf22fb6fb2n, + 0x05c70c3b9c0d25a4c100e3a27bf3cc375f8af8cdd9498ec4089a823d7464caffn, + ], + [ + 0x20ed9c6a1d27271c4498bfce0578d59db1adbeaa8734f7facc097b9b994fcf6en, + 0x29cd7d370938b358c62c4a00f73a0d10aba7e5aaa04704a0713f891ebeb92371n, + ], + [ + 0x0224a8abc6c8b8d50373d64cd2a1ab1567bf372b3b1f7b861d7f01257052d383n, + 0x2358629b90eafb299d6650a311e79914b0215eb0a790810b26da5a826726d711n, + ], + [ + 0x0f106f6d46bc904a5290542490b2f238775ff3c445b2f8f704c466655f460a2an, + 0x29ab84d472f1d33f42fe09c47b8f7710f01920d6155250126731e486877bcf27n, + ], + [ + 0x0298f2e42249f0519c8a8abd91567ebe016e480f219b8c19461d6a595cc33696n, + 0x035bec4b8520a4ece27bd5aafabee3dfe1390d7439c419a8c55aceb207aac83bn, + ], + [ + 0x2c9628479de4181ea77e7b0913ccf41d2a74155b1d9c82eaa220c218781f6f3bn, + 0x278f86b8fd95520b5da23bee1a5e354dc5dcb0cb43d6b76e628ddbffb101d776n, + ], + [ + 0x0be1916f382e3532aa53a766fe74b1a983784caab90290aea7bf616bc371fb41n, + 0x0f65545005e896f14249956344faf9addd762b7573a487b58f805a361d920a20n, + ], + [ + 0x29ff8437ae5bec89981441b23036a22b7fd5bee9eff0e83c0dd5b87bfb5bd60en, + 0x1fd247352b77e2676b22db23cf7cd482474f543e3480b5a39c42f839a306be10n, + ], + [ + 0x2f3bd4e98f8c8458cd58888749f0f5e582a43565767398e08e50e94b9b19a4d9n, + 0x1f534906d1aa8b4ba74ad9e3f85ae3f8295e51eaafd15b5d116801b96360205bn, + ], + [ + 0x27759098f425b76447c2c52728576803a1ac5de37bba875ac47cdcff539ab931n, + 0x0aa47ee64d12d856cfb81b595c1d60ceecb693f0fdae644746ff333e39f61db7n, + ], + [ + 0x015ca8d68616fde86c9108e3db04f588e0f308e60d367e963b7d460fe9a65e6cn, + 0x2cf918009dda942ac9d59903cd2d0294d8738f938b1394170d892a027d0f347bn, + ], + [ + 0x0d1783d5b256765515f3c9988df9f1ba7e6f5fb0248c8971fbc503ffd5187714n, + 0x2ebb434ff4857fc3621f3bc3c6b8002b17d02d9c204e75f19b8f0b99ea68402cn, + ], + [ + 0x300f20942e37abb19520f931f7bf7c6bbac93e4461a7789677f986e344d1f5e5n, + 0x1172a6b674c66bb037109fbb4d93d4ca8054bb9dda08839a6189eb578511116dn, + ], + [ + 0x13a6b381a663aa8a757dd386a3a8947d456874a356f52f8af1a3d84ba1067eaan, + 0x224854000fa9c70e873fb14ad7c0d01dcf6df5f30261333d6b63c78a7da5a348n, + ], + [ + 0x2b37dc5eb4c3f8cba62f0085ec131053eae6181a3e73a82e7d79764a023394ccn, + 0x27c817c1376228a3a9f5ac6caed57857a3baa580a0c1b70a17f75a6ab7e2377cn, + ], + [ + 0x26ae1cc453dab3f2cf4810cc3fb8f71257383333aa4f3ace8eb69c8ba4fa5da1n, + 0x28bfbf80541bde37e9db113ae1eb049cf163ff4ea9654d61f42a95bc2e0b17bdn, + ], + [ + 0x0e29626ab6be74417d08b28c8f8ebf02fd701e28d1d47b1961e716e735e02d12n, + 0x119f55d6bffb6bba81779eaf98f310c5661d85397b094ffbddbb41fb264b0876n, + ], + [ + 0x055cda53e781f3eedd760ba2c48c6d36d2a061544c3d33e76100bd4c65e89748n, + 0x28391e899d6407e40294faa5e5561ab472e43ea5d54c15343b9a47cb7a80ed09n, + ], + [ + 0x203c402369e8b2bc2c3827bc82a278d32c51dc9ab95e55ce1566e8b625b7bce7n, + 0x2bf25525d4a62f1252355559dd496b68ba4d6ea65f4b669bb3da73c42455f0a3n, + ], + [ + 0x2468739cedeabea49dbc46c2356bd5cf341aa4574272ba53a40d8049e5ee949fn, + 0x0e8b73bcac6b2ccffaa2e50fce992db11a0b46dcdb8ad4b8325393f903a2543an, + ], + [ + 0x242d8ad05dc6e2a8a6fd636f48eec881e05ee8d2a58e2653173f4954ec867654n, + 0x0afe0d7aa588a3dcf791f11fcdf54c1d07cfc805c5ae0b02101faafab9cb55f0n, + ], + [ + 0x05c378d0596af9f9a2471be52b7ad0112d48ef355c372088eb0db86e42887e14n, + 0x1ba1f1adb66e67bc88c1b3eafe95b202812803a8b71ca62de9ed06c8b9f3cff3n, + ], + [ + 0x04e5c213eebfffcdb42b6c371e52f0d598646cf0ca2a353b4b99889074c5a2bcn, + 0x0ae6442bc73b0f2b2d45829fd8fa321ab6b5eecdd3988a39f0c5850544de5082n, + ], + [ + 0x2c96765650bd7c3bee01114b9097b036e20d5c774afe2ba7d5d6099f498f47fdn, + 0x0879c9cc5e7eea97f1f9193e1fd08b8d0390320197dee299af1eb67f92c506a3n, + ], + [ + 0x2113980404df880af7d25a27aec16e61c770619912435b618914da7fa1a88385n, + 0x106827183994d8da15037851748b05392620516277bf0000f8b38e97f5db602an, + ], + [ + 0x13b4c5f15cc69af871b91e862db8b0044834c5e8da5a287d0794342bb97ffca6n, + 0x17941f13343835b572e18d37ab3897f80e0461f9b72ab61da61927fc980a6bd2n, + ], + [ + 0x085c0f69b19e05986883dcc9d53334bb6799968688935d938cebd4b4455f9187n, + 0x242b8a5ab074d09e26427b1b6633a79a82ba41d64c4d658017f3186d6926721bn, + ], + [ + 0x1bb111daaf71e632a4c9244a362bdde16a5efc5e7c7dda42b20f3290c2776d2cn, + 0x2b4506bf741b2dc59f71f7036716cac04b6f808b4ca1469eb2fd7bccff5882c0n, + ], + [ + 0x1a76ba8ca6b8e2c65915521b175da98137dfcaf0b5faff1019f37afce77c99ean, + 0x1894c8c79e69e52a495bf6fe467aa4f5bdbe606490d6803df325a075c5b0079an, + ], + [ + 0x2fea40a9bfb252ba7e192be641a4051381982719b77d567caee2657f36b701abn, + 0x1e80d5ea79b50a722e65ce274b8ba2a133de94b757ef71b452183ee958c620e1n, + ], + [ + 0x217c100e6cd64b68e91fe26e90eda02eaa505859201253bd5e550e0bb8f0f29an, + 0x12a5c4fc942353f962bc5b97f36b9a326d5dbb6c505266d2a016415d8da0be65n, + ], + [ + 0x2f50fc293e4529108595329b6e7b0110c0db563927bd57a169e81884535660f9n, + 0x03547f619f9c30a761963381fe31f031ecd5b393d2281455a66e01aff0896338n, + ], + [ + 0x06e0f1aab04c530ed9e9584b7c06cb40d6dbd1752313b1bf8498accb8227e743n, + 0x2b47e83f03e635a9c20eb0d6412955dec1578a197c7d51f648550623ac5b3baen, + ], + [ + 0x1dee7c6f5d7527d26da506eec28cc3b71acf9a8e694567749dc5e6b073748632n, + 0x235955a911e3744859c1db3996aa1f0f64424f67c2ef1c8fcc8c767af5749068n, + ], + [ + 0x1e5aa70095a858d1c4153691e91c19f01a883f422efc19ec766c86bc416ceb2an, + 0x0f1e06c820067d8d0af14cf87633c1bd761d65bc5b3889a17bae7d70d2b19f5dn, + ], + [ + 0x2f4d8f60344443350f226f19c4b01e2198f6b475b0291dd2e0c3981e3797a5e0n, + 0x1aaab92caf692c5fb89e6eab983f26ebe009463c1ddece0a650508994cb84a82n, + ], + [ + 0x06e0aba4044a552343f7ba02f234dafe4ccca7fd552342a8493ce544758df012n, + 0x243269273e7c7ee7a50288f282cb6a7169ec2aac03d2ff7b40463638ad5722d5n, + ], + [ + 0x1aecf2ef53262227e12a9ca29ae7f14be031c03488a7604a03cdc77115f26136n, + 0x0753180b7d445c215d55dbfd6ebfb1c6aabd690ac92fd76cea5144ef3c9a8b3fn, + ], + [ + 0x207d50d783c727a979303bc8f50538ad75e5f856180d4f3dc2c7ee186916cef8n, + 0x20155253cd087a980aad326564240cca45a72c888e69395e4d8f5ca3d2b96e0an, + ], + [ + 0x21db09b3c2c299f1b0be7a8f3031fd283cd5f1efca0a468b7ea9a0f170e81fc7n, + 0x21b50f8107353afc7a1656040c9888ee393608420d88c2a07f34293fb609a26dn, + ], + [ + 0x02190016f4cc44935d100bc7b7dae46cea5922261e9889112cc815fafd5c45ccn, + 0x01dfaacfa00ddb9133042d9833d1201172f69a456f0c9483d0b58e5f01b571fdn, + ], + [ + 0x04e67573df0c1591ec51d2f60b74f1964abeef3e201084425a55cd71ffe0b4f8n, + 0x1f0285b2ede69aff961919827312afad0753c112cab001cb28ff6c2c27f277c6n, + ], + [ + 0x092450548d189dfe4e852370c17343aeef92ac3a8fbdeb8fdd244f87d3af03cdn, + 0x23e3c53d9265d6debfdb40988a908e64673b2f87b1fe2a08b56c6a3fcf84f5d1n, + ], + [ + 0x2935be388ee1365bf6a9cc6fd25d130607835dbf7926c5cafed690b9072cd316n, + 0x059edfbc50a9699e29b975a2fc3bfe7855997e708ce82fa30ed19cc91850f6ccn, + ], + [ + 0x21cc891713fb8570152149a9fbb23410d7c42dece266bc6093650e46111a465cn, + 0x248f486105ee09f447e7e0ff522b5ff1db5f64522f2bbbb28e7a07595cff3e79n, + ], + [ + 0x147f06fa12cbb8d1c98f9c06d57899e20d9651bb8da104ad5168c9be10d4419fn, + 0x2766f677196fb611814f5d7af22aa8555c3c65b572151576b116df5b9f05857dn, + ], + [ + 0x0143beefa7f0b8fb72262a3c3d1502a36d8b4cb35befbb37dba3a70ffe2571c7n, + 0x1808ba6988bbb8585b77765760fb2afccdfe4946702043a46b8d461c7d211b11n, + ], + [ + 0x1ac3c1edb1eddd9c5011f88769fac4050aa8820de1f84fcda7e400f87028ba3an, + 0x050cbb4da87ecd3f0c84d6252e76e19b3678b955c603f35abdcee3b988a57fa4n, + ], + [ + 0x05a7092c674d8f44add477edf7369dc7bcb9da4d1b903fd58dd8bd4d166de73en, + 0x182545ce8ba6fa781823673d50fc62c7d1bb5f3515da6e5c2bdfd7248f311e1bn, + ], + [ + 0x0154a12dbf3fd3ae8957fe154f378630c12306eb55425d9732e0ae2b56ca0306n, + 0x140688ffb0de33c9625e323a13e9df6fb37c841b34c4b18b7e19d51792d393ccn, + ], + [ + 0x2fcdf4e4b421286df484fdd08725ffe53728759508f74f0d87e65bd932af28d4n, + 0x25f57213413f9f0982573c4a6640efe32b612c6c8f0b027425260c4629d38b21n, + ], + [ + 0x203ed9a7ff1ef21910003e658dbff87a3e10da7782de00af71995c233587961dn, + 0x0c7ae4445018e5d451f197d7881b1b95fb66574c26ff6967a37c1eab5f907a08n, + ], + [ + 0x131abdc8d6c6319aeee7e8b186ace3c07d140eb4037b21285b2260cd7bf310f7n, + 0x2371e4c2b73ce0af013b30ee9f434584742cdd7e91f1d842c1a6a95bd12d915dn, + ], + [ + 0x124029864085263e79448fdeef91ee2ea5a4952637646b02f132c1ac917edbdan, + 0x29d11c62ccfca5d8328e5171466137e6cfd19d56bdc3bbc4633a0aed34a90e69n, + ], + [ + 0x1ded46fcf96cba70ac0cb4ca58348c90041b257232e476acd236b45271413fben, + 0x26d04c6660ab9693743bf5c5fcf13047860dfeed3dd903e6ff6fe917fddf73fbn, + ], + [ + 0x2b31b48b7313f6a5c3f1f59fe9ad3d4b8900d873056af1691d143208eb5c8790n, + 0x27cec87606fe5f9562a3d0b1fef90da3e8d17721c668c342b681468a501deff3n, + ], + [ + 0x22080b093f3b3c98f9afc52b80594dcf51a714e77c40c3a08513897d73a70806n, + 0x1cbcacedf498eaebd03b602c4908c165c50ba184230c7c52244c9a5d0e9759ebn, + ], + [ + 0x0560b3857af53bc7262482310593e316543551ee57417583161bfce9d12a4d40n, + 0x2c91b186a9740d4b9f49c8889878381833cc5b5fe29e6e83affa2916e2008988n, + ], + [ + 0x2cf006347b380b6e0eb766ebdd1d24dc1eed9a43c206ee58e9457303d509c308n, + 0x03d11688f54726466399ddce8523148453cd1b6cad3cd414ee6e2af66a6b6addn, + ], + [ + 0x2e5c7e4d9a6069892bac121490fee89df1c238c7738c9f3ab599d6b4cc2ff491n, + 0x0f3c26f5de9ad898d4a4b1a08d1e87fd5cf4362f9796fb8715c60d431902cd54n, + ], + [ + 0x15298a52895eb8c9399509dc1f0ef68a90afc29084d3a0cec6956c8420819b5cn, + 0x2dc0ccd80f1bbbdf364f5b912a961332d9f5db54763745b64e0d85e33faf87c7n, + ], + [ + 0x132026c02d21e2ccabf1338f0d93f4223ecca5f0f2a96208561c9d5a5ef79c88n, + 0x09224bf821c64b105233fb98964f9ee0d3365f59e054c4693492ac07956d5c87n, + ], + [ + 0x2d6c6f3d040ad0c71760e8139ed3aef03c01d86e03f4ff0919f97899649d4bden, + 0x1a186b79fdcea1c8bb184097418bc68279fc5f682c48f5f21809bd2087944935n, + ], + [ + 0x1d69440baeb72617846c275fd817a4dbf9a8d39ddd38ca87b6a9e54ec6cc2adcn, + 0x239c44e43c9a91c9d126e745b949bf87844de4f2775aad804f81b8dcd3c232c7n, + ], + [ + 0x1e80e18c68865cf7bfcc6964613ba1aa1ae749a2d6154288d9572f022b2a4dd5n, + 0x1fa00a74773c3214ed7dfd125c82192d4c24ce557f720c98827aeec194dc9a30n, + ], + [ + 0x01b1362ee72c3e3ef5d63f67b54a6c5f547db48126b640fc8356e4cc19382dd3n, + 0x13e340c7dea9488aa6f9fe7443d7d1aa4b937800dd213c8bb4b301ba4a1a583cn, + ], + [ + 0x21f121f9754a315b922f8464a6cbe5a9fe191f30cbd2218cc4997c3d028fa52dn, + 0x2b8e094f90ea155bd675e389c69c3b021095801905efcfbcfeced8d7e25d6e96n, + ], + [ + 0x0d03c9e026afecdaf0f1b68679faf85830f2e16edf65c80c04b032441935e7b1n, + 0x18a285be0228b819cdd475d2f08192c02a998c85802b10d0ab3256fe367d9cf3n, + ], + [ + 0x12db390e5305fd19780de901727bb248778b6077f75ee6f8ae9c2b8629a8c037n, + 0x16952c652e2719fd93571b55357e6533410e2cb115cb970676c5d08a39d1be87n, + ], + [ + 0x04598dbf51d48775d7acafd239192aa850b72785472238e79f65a89292ac238bn, + 0x06872dca2aac431fbcb2fc3196b516bb791afb6136cc457b3aeeb85d1b02e4ecn, + ], + [ + 0x015ae13d6981f433340a44f9d33ebfda3b7108fbed96fabbbdd96e95b9f2cf23n, + 0x269b90e34244790294b66b9699510444a01ef16661fa80a2a41d368c6371af4bn, + ], + [ + 0x0a3d1c57e4d12a2041a41cc6483b63d8616af9b11a272535e3c88a4bb0f293a7n, + 0x092cf2eec8c9c1cefcaac51028875fb2f9abc46d111c852466d479edb244d852n, + ], + [ + 0x054e837ebc7a6b5142d527fd0e0b052aca6b91dd6dc4827e0196acea8bd04af5n, + 0x294164cfdfc4ddde270ccef912a1ac370f1aced76d933f702937db9ae0f6ab13n, + ], + [ + 0x1d175a456220eaa15ac082acf8a910da24751810edad87b1d558e229064c8da4n, + 0x1c0db158fb28522527eeffec568c97f8b7bc7a3927d1ba93ffcdab8de75e7ecbn, + ], + [ + 0x254c3c07450ac82ed0479ce88ace7cc5223b7cdc07557c234620d006df28fb09n, + 0x09e22217e07537054ab2c6c3947690ec12620ab0f0e7d03b023f51160c1df68dn, + ], + [ + 0x1cf4eece13e6e8b9bfd4644614cb0df16b38f76e70b11b4e72c283bc47439ffcn, + 0x18fcd0501cc6d30faf81f21b62ab175d5b5fff6b16a80b23700c9094ee3f779an, + ], + [ + 0x2ca6acd35e2ff4527399a13876563461726f08e629bd5897dfbf9a576f4d6641n, + 0x303c6102e21ec7518cc4181436345be6af5916b8f604bb1054c02d5ee1362c6en, + ], + [ + 0x037612d11f47ede28098ea80adef547f4912031fd236c9a7e5d5cdf00ba4911fn, + 0x0d547e26bf94386d4ba5a69caa4baac73aaff2bf4abdfadaaa42b892cfa033d8n, + ], + [ + 0x2494d804f242aa8a8a7e5eaf09829b04b4c7690c810a5ab01d3fbe2dae54a1f3n, + 0x093b3e5ca5fdfdb2e58ba6649e9c13f97b79d8e7f4cf65e3255b98a14689c94an, + ], + [ + 0x020c10d95e90a551134c8ad77cfb5f11465c23efd81c7713efe22ad54c048403n, + 0x03eea8fd0ad7fc2ea2eae6a082bb199959a6a361f7e8865d251d6ff547c15207n, + ], + [ + 0x0e274ceca67b5c0ff0b8774e5c8adb780b62e3e4a1065b190c2c28da6c808f50n, + 0x21c6675fbe4ae752919ab3f92f412394c138807af9adc3a5dd81400a83db3bc5n, + ], + [ + 0x0158f7157c016635f6f878fb58e1b59f2741a2315939fea4536e056bb7f35ce7n, + 0x20b454ec327caab24f39f8eb5caf9eda33a9274a8f4bab8f03de09a3c176e7d4n, + ], + [ + 0x1fee261ad59b9bb95733b499820beb21ed40156dc89dea7f02739661eafd81a5n, + 0x003e98b3f725336c5a13aeddb2e2c1e894860365915d06733d847f3a01dced7fn, + ], + [ + 0x237e59a6bfc3ff0e1f5fada642d1d1a5c349502bed14f64a6c5b03caf3975008n, + 0x2362bf67d5eff33ec19af5ef915557363bd3aa313f3610bd6b1a93cf6bd8b045n, + ], + [ + 0x0204a6de6d1e5243dabb6485d5eb0231aa1487f417f7677fb56f398269b07fefn, + 0x01b9bbb78a97b65bd9854d56e5bd50be8ca60f18b73f012ef28775ef3fc0901bn, + ], + [ + 0x18ad002f659998c9bd8543361f97a2a454e5b87aa62893406298f3e37f2720ben, + 0x227bd053f0ba47f463cee2caa96c4d00516f579a1646ec4a2a70dc1700b06a50n, + ], + [ + 0x03a74f956daea99179061720902ed0f3206c92f215fe1dc2b1a10545803a99e9n, + 0x2a279b91188c2bd770f5b23f0cc724ec9eab26971db684d4d8a1623e150d0e4cn, + ], + [ + 0x26b3364b6285c48a552b5f1a977d9be8728a8493855bf5acc49d5815af84dd2cn, + 0x1898136f0513c863a49ba1b27f7de7452f004ebe7409dfae1f28966f918e6ba4n, + ], + [ + 0x2ead9bee2969459504a0fa26e953a7caafe76dee6da60ca921e9f78743378589n, + 0x0934d50a9d9007be2e47f077044775b50d33438443853dc1e81ba011816faccen, + ], + [ + 0x03b638cfae5057787fc620d2a8fa257b7126603402dade0789093853eca1b6a1n, + 0x1e57da2d7d7c7087e58b74ae04e3be194424a64e21ee94feb20859dc1f65438bn, + ], + [ + 0x1253e8cce9c54cc1f0c2f38eb583f48f7421b516ff629c9764bc187f768cb0d3n, + 0x1164460615286ea5972631b0e2d96f68cdbf17c327cd1a0399666e34950375a3n, + ], + [ + 0x0de7b3c645363ac23ff2c8af302e995251419b52ea1936cf58805b589485ed08n, + 0x29ac530d28441b612678ff86c9f48cbee512260e21aacb7ae1a6abc05d0df10fn, + ], + [ + 0x11ee0a33439f8e1da5fbaec6ad6368a2c1ecd2590ebe06bb0269a2c28bd389a5n, + 0x0d37b9e16c881409be41d42601fdaecfc7b67bca0f088eb0bef1c4e4c428a1f1n, + ], + [ + 0x00ef4d130e14eb610f533b395d18db4708b4154a689cd4acddac1f1b43ed6854n, + 0x2c485355a6a340b718e1a20206ec5c55da5dacc9045d3454b2947b759a1401ban, + ], + [ + 0x0b2500eddb982dc3ef2728e010260a5e33aa06e6960ac8d3926e3e4b441c978an, + 0x023919ab917efd33a4e07c3da64b5c0af384c7487e23333c43c4b62a315014cbn, + ], + [ + 0x2e9eb27d5d8f60d282cf0866e4f0fb92d045388f1d227852f85c1518dddc503an, + 0x1f0edc2cc1602d4f66b658f676446a7ebd3bab1a08cfe60184390600c2b0044dn, + ], + [ + 0x05c545ab45ef4d781e551674ce7027668b384667c7e3e04be02a921410223713n, + 0x0e8988769b7f561fd70e9a761c198ab9d5807fbe6ecd327241a8f10815ac4d76n, + ], + [ + 0x252896bd06ea09d5260c6053b96a3c9f0fe2bf520debabc1422b298e1b823ff0n, + 0x0beba0fe2d2ed0e028356ae129ba2a444a871a7aad25d5e90fc022b963e0c5e3n, + ], + [ + 0x17c2b8543fe3ba1042342557072eb30e941f8b93c879512e590a761454458694n, + 0x2de5011cc9b603ba43cfcc082671de63da3de9b9f0021879e7f482058f9fae0fn, + ], + [ + 0x0792855505a783cb49f954bccca6120e8990a7092b4ab0bd08168203932c7bacn, + 0x09e95a4c731b378b80991239ff87b90ba00b9439c287dbf01aaac56f05aa550dn, + ], + [ + 0x0d4beeb972497603c3a1d7d7ad79c45615f12844a530580ca2de18ef8fa1b1efn, + 0x004998039050599d55e744c51f8846dbc7db25a8318abcaf217ae68bff075d77n, + ], + [ + 0x12c6d0a3726a805bc04506282ce0218ce5de5386b1eb4aaa893722fe80983688n, + 0x2394def51425f2cee78f4ac1f0c04e25b60d1fdc9e84bacad67500f7ebcfca34n, + ], + [ + 0x1a19096c5c3522d45e2827449adef54d91287ede96b3d39818da08a0b93e9dc3n, + 0x27a0dde36f91156a87d746a58477553ec138d108fb471f157175e22a75a495dbn, + ], + [ + 0x0b7748b109ba5798a8d2803be7fd015f2ca5af9eaad8ddddde16d50a07a7bc10n, + 0x12214803947f2969d86455b1a47213f04a9309620d9692ec91114237acb84eebn, + ], + [ + 0x0c02dbea3ecb6bacc7390d53b6fe23feb49a58c571d95d01fabac5a42489a7can, + 0x0d73b846a5cf707f3e5abf9ba2b4f5602a55b5fbad7fbd7bd9b9ab48977c1005n, + ], + [ + 0x169623c619bc3ac95ec3315d5e01afecebafb1931826551b86c007070001fe90n, + 0x00cb91b18d7097d4fa2d7600ae1bf31a3b4df9479e39f1bf23f231773258ea3cn, + ], + [ + 0x0fd5b9f9d183b6da8ba0f99503e851450b3efb33c6a7807a6239e0707b5af271n, + 0x2a4153eb0395955d7d7ee71519d1d600bc32dd39b6283224fbc92d23b860eb54n, + ], + [ + 0x1209e1604a9b10afde568fcfe0ea9f1e09cdf13fe17747abeff0a1454dcf947bn, + 0x0e1d63b8ab7b9a4a7ef8d3d17207dcbbc22e9c21da661ddfdc1ac961e0032b57n, + ], + [ + 0x2982c7c825f0e86293b7a0c9eefea7f5383e222a054ffa4c5d4e5908c543c2a6n, + 0x151b990dec385eab48210cd7766d2de58eba95ff76faeee4eb64e6f3dbd3c139n, + ], + [ + 0x124faaed649b6df79325991151fb88952c9acfd57a6b3cb20b18f2fe63529818n, + 0x229dfd4712f46fe904c28adccd1165786e96baaa2c74a0a7744dbb4ab4300d41n, + ], + [ + 0x0963070c9042bbbbe66468d9e75a719123b52b76ee9797f4b039b5de1b5c9651n, + 0x06aa3729a947ec02394d82a46a0c2c2f8e2013e15f46cc97b96944937da731d0n, + ], + [ + 0x279040e3e8f1e0effaf0450099574e134c3eef819f04cadff27851de962da0d3n, + 0x1ee7f53a1b21c4fbd2ef56895bc274e520140858ba51eff6968eae9d0a03a2f8n, + ], + [ + 0x0502d68753a132e8b268e02362166d6c0e43494aef2a5173eff138aadfe05ad0n, + 0x21629dc5334c80a75f79a4b75169c40bb6eb665796a8c4d1024231cbc4604f1en, + ], + [ + 0x13edf560ae7a1c78296f4609233337cd8fbb009b22d89a27d2e5c94983095fe9n, + 0x039c043f9ac7c68faf473565cdcb51785597c90d8ba14dd8e577bf14d70c53e5n, + ], + [ + 0x075a3019dc700efd12e8b91be0029407d59c3dfeeeced4d8f8d35fed14900d79n, + 0x073d003f8998a46ba32780d2e50c2a287b6902ecb2b82672a817980666c406c1n, + ], + [ + 0x1e8509ab9d961e5dea389e1498be69790390a5f77c7dc68cc55858207ece11c5n, + 0x19979a1f1a22dc051a45427d70f66fc27c064fd451b64b6b609d74f0a6439b2cn, + ], + [ + 0x0dc528103070ee030c96bdfe9004693f52a22042abad186aba5616918c701f56n, + 0x05f194973a699889fecfedf291c50be0526c35c22faba00aec84b967e1a0f278n, + ], + [ + 0x1f795886933d543108a9cb86291f04ba487cd95fb6ff9a062d8e6ac9f267d3fan, + 0x127fe0e1209741e32c0a093bada5517cbab952de68241df774b6ddeabc2a6397n, + ], + [ + 0x156c18df6da11a7f9657751e43b50abea544017d347f27406cf4751e51a81e42n, + 0x28e38ee1433b9eefac4b22ba5d88f1d7979d1fce9920d20213b1c01fb204f725n, + ], + [ + 0x2341ce02c131e47cec7777567cc7996ac3b6fd6255ba880ba819ae4982465becn, + 0x0913340a3a212e4e0adb678d500a70e99e24f7a8370cab3b92df8cb6ec2766f3n, + ], + [ + 0x2ee690cd26ee66b12bfe6a7d4fe3077a8c2a41ce96216a964c1a94227b0cb8f9n, + 0x1e207e2e40816da78ca89b8d98f0ada6208f014beef4efec812f629d42e5e304n, + ], + [ + 0x086d9eebd9fbb9b6394cb155b8ee9e3558857f65053abb4a04c6d956d1fdfe95n, + 0x08deaf603a5fee68ccbf892f95f787dd437283b46362a9071ee1e73ec4e03edcn, + ], + [ + 0x0f63792ebcefa16d26dbfeb58db005dced755740bd047de3fde3013575b57022n, + 0x1cbd79e5b8ac132920b495e66d47f2969df49423452a34336796d152ac7de76bn, + ], + [ + 0x05f6732fe8526a3340e547d2a19a97a5c4538a94ce607eb0909db67c8880bdedn, + 0x1e0bbf2a4e501a83460c96e919bec020187f51ce94c328b3b38b07f34dea2cb2n, + ], + [ + 0x1f1df03870f616146c84545722f1e8064bc9db8180caf35061367af95445bb3fn, + 0x077004e054257d7389065f3f11be644084b357c1b9214a9869d5b6761ccee13cn, + ], +].map(([x, y]) => new grumpkin.ProjectivePoint(x, y, 1n)); + +const lengthGenerator = new grumpkin.ProjectivePoint( + 0x2df8b940e5890e4e1377e05373fae69a1d754f6935e6a780b666947431f2cdcdn, + 0x2ecd88d15967bc53b885912e0d16866154acb6aac2d3f85e27ca7eefb2c19083n, + 1n, +); + +const pointAtInfinity = new grumpkin.ProjectivePoint(0n, 1n, 0n); + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +function pedersenCommitInternal(input: Buffer[], generatorOffset = 0) { + if (generatorOffset + input.length > defaultGenerators.length) { + throw new Error( + `Pedersen commit overflowed default generators. offset: ${generatorOffset} length: ${input.length}`, + ); + } + let result = pointAtInfinity; + for (let i = 0; i < input.length; ++i) { + // TODO: WARNING! Merkle tree tests fail if we don't reduce modulo p as they feed in 256 bits. + // Is it right that we accept 256 bit buffers here and reduce mod p? Is the right thing to only accept fields? + const ie = toBigIntBE(input[i]) % grumpkin.CURVE.Fp.ORDER; + result = ie ? result.add(defaultGenerators[generatorOffset + i].multiply(ie)) : result; + } + return result; +} + +/** + * Create a pedersen commitment (point) from an array of input fields. + */ +export function pedersenCommitNoble(input: Buffer[], generatorOffset = 0) { + const result = pedersenCommitInternal(input, generatorOffset); + return [toBufferBE(result.x, 32), toBufferBE(result.y, 32)]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + */ +export function pedersenHashWithHashIndexNoble(input: Buffer[], index = 0) { + const result = lengthGenerator.multiply(BigInt(input.length)); + return toBufferBE(result.add(pedersenCommitInternal(input, index)).x, 32); +} diff --git a/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts new file mode 100644 index 00000000000..86fd96e882d --- /dev/null +++ b/yarn-project/foundation/src/crypto/pedersen/pedersen.wasm.ts @@ -0,0 +1,28 @@ +import { Pedersen } from '@aztec/bb.js'; + +const pedersen = await Pedersen.new(); + +/** + * Create a pedersen commitment (point) from an array of input fields. + * Left pads any inputs less than 32 bytes. + */ +export function pedersenCommit(input: Buffer[]) { + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); + const [x, y] = pedersen.pedersenCommit(input); + return [Buffer.from(x), Buffer.from(y)]; +} + +/** + * Create a pedersen hash (field) from an array of input fields. + * Left pads any inputs less than 32 bytes. + */ +export function pedersenHash(input: Buffer[], index = 0) { + if (!input.every(i => i.length <= 32)) { + throw new Error('All input buffers must be <= 32 bytes.'); + } + input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i)); + return Buffer.from(pedersen.pedersenHash(input, index)); +} diff --git a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts index b07c2f300ab..7b720a6e123 100644 --- a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts +++ b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts @@ -4,7 +4,7 @@ import { TestNote, TestState } from '../fixtures/test_state.js'; import { JsonRpcServer } from '../server/index.js'; import { createJsonRpcClient } from './json_rpc_client.js'; -test('test an RPC function over client', async () => { +it('test an RPC function over client', async () => { const mockFetch = async (host: string, method: string, body: any) => { const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const result = await request(server.getApp().callback()).post(`/${method}`).send(body); diff --git a/yarn-project/foundation/src/json-rpc/convert.test.ts b/yarn-project/foundation/src/json-rpc/convert.test.ts index ddad7fa09bd..ba5eeaa9f98 100644 --- a/yarn-project/foundation/src/json-rpc/convert.test.ts +++ b/yarn-project/foundation/src/json-rpc/convert.test.ts @@ -7,7 +7,7 @@ import { ToStringClass as ToStringClassB } from './fixtures/class_b.js'; import { TestNote } from './fixtures/test_state.js'; const TEST_BASE64 = 'YmFzZTY0IGRlY29kZXI='; -test('test an RPC function over client', () => { +it('test an RPC function over client', () => { const cc = new ClassConverter({ TestNote }); const buffer = Buffer.from(TEST_BASE64, 'base64'); expect(convertFromJsonObj(cc, convertToJsonObj(cc, buffer)).toString('base64')).toBe(TEST_BASE64); @@ -16,18 +16,18 @@ test('test an RPC function over client', () => { expect(convertFromJsonObj(cc, convertToJsonObj(cc, note)).toString()).toBe('1'); }); -test('converts a bigint', () => { +it('converts a bigint', () => { expect(convertBigintsInObj(10n)).toEqual({ type: 'bigint', data: '10' }); expect(convertBigintsInObj({ value: 10n })).toEqual({ value: { type: 'bigint', data: '10' } }); expect(convertBigintsInObj([10n])).toEqual([{ type: 'bigint', data: '10' }]); }); -test('does not convert a string', () => { +it('does not convert a string', () => { expect(convertBigintsInObj('hello')).toEqual('hello'); expect(convertBigintsInObj({ msg: 'hello' })).toEqual({ msg: 'hello' }); }); -test('converts a registered class', () => { +it('converts a registered class', () => { const cc = new ClassConverter({ ToStringClass: ToStringClassA }); const obj = { content: new ToStringClassA('a', 'b') }; const serialized = convertToJsonObj(cc, obj); @@ -37,7 +37,7 @@ test('converts a registered class', () => { expect(deserialized.content.y).toEqual('b'); }); -test('converts a class by name in the event of duplicate modules being loaded', () => { +it('converts a class by name in the event of duplicate modules being loaded', () => { expect(ToStringClassA.prototype.constructor.name).toEqual('ToStringClass'); expect(ToStringClassB.prototype.constructor.name).toEqual('ToStringClass'); const cc = new ClassConverter({ ToStringClass: ToStringClassA }); @@ -49,7 +49,7 @@ test('converts a class by name in the event of duplicate modules being loaded', expect(deserialized.content.y).toEqual('b'); }); -test('converts a class by constructor instead of name in the event of minified bundle', () => { +it('converts a class by constructor instead of name in the event of minified bundle', () => { const cc = new ClassConverter({ NotMinifiedToStringClassName: ToStringClassA }); const obj = { content: new ToStringClassA('a', 'b') }; const serialized = convertToJsonObj(cc, obj); @@ -59,18 +59,18 @@ test('converts a class by constructor instead of name in the event of minified b expect(deserialized.content.y).toEqual('b'); }); -test('converts a plain object', () => { +it('converts a plain object', () => { const obj = { a: 10, b: [20, 30], c: 'foo' }; const cc = new ClassConverter(); expect(convertFromJsonObj(cc, convertToJsonObj(cc, obj))).toEqual(obj); }); -test('refuses to convert to json an unknown class', () => { +it('refuses to convert to json an unknown class', () => { const cc = new ClassConverter(); expect(() => convertToJsonObj(cc, { content: new ToStringClassA('a', 'b') })).toThrowError(/not registered/); }); -test('refuses to convert from json an unknown class', () => { +it('refuses to convert from json an unknown class', () => { const cc = new ClassConverter({ ToStringClass: ToStringClassA }); const serialized = convertToJsonObj(cc, { content: new ToStringClassA('a', 'b') }); expect(() => convertFromJsonObj(new ClassConverter(), serialized)).toThrowError(/not registered/); diff --git a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts index 7c2d2c856cf..c5272c2b74c 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts @@ -3,7 +3,7 @@ import request from 'supertest'; import { TestNote, TestState } from '../fixtures/test_state.js'; import { JsonRpcServer } from './json_rpc_server.js'; -test('test an RPC function with a primitive parameter', async () => { +it('test an RPC function with a primitive parameter', async () => { const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/getNote') @@ -12,7 +12,7 @@ test('test an RPC function with a primitive parameter', async () => { expect(response.text).toBe(JSON.stringify({ result: { type: 'TestNote', data: 'a' } })); }); -test('test an RPC function with an array of classes', async () => { +it('test an RPC function with an array of classes', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/addNotes') @@ -23,7 +23,7 @@ test('test an RPC function with an array of classes', async () => { expect(response.text).toBe(JSON.stringify({ result: [{ data: 'a' }, { data: 'b' }, { data: 'c' }] })); }); -test('test invalid JSON', async () => { +it('test invalid JSON', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, false); const response = await request(server.getApp().callback()).post('/').send('{'); expect(response.status).toBe(400); @@ -34,7 +34,7 @@ test('test invalid JSON', async () => { }); }); -test('invalid method', async () => { +it('invalid method', async () => { const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, false); const response = await request(server.getApp().callback()).post('/').send({ jsonrpc: '2.0', diff --git a/yarn-project/foundation/src/timer/timer.ts b/yarn-project/foundation/src/timer/timer.ts index b74be9819ea..ee96cbc94a7 100644 --- a/yarn-project/foundation/src/timer/timer.ts +++ b/yarn-project/foundation/src/timer/timer.ts @@ -14,7 +14,14 @@ export class Timer { private start: number; constructor() { - this.start = new Date().getTime(); + this.start = performance.now(); + } + + /** + * Return microseconds. + */ + public us() { + return this.ms() * 1000; } /** @@ -25,7 +32,7 @@ export class Timer { * @returns The elapsed time in milliseconds. */ public ms() { - return new Date().getTime() - this.start; + return performance.now() - this.start; } /** @@ -36,6 +43,6 @@ export class Timer { * @returns The elapsed time in seconds. */ public s() { - return (new Date().getTime() - this.start) / 1000; + return this.ms() / 1000; } } diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index ae6c5e74e5b..0d1681c5077 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -1,5 +1,4 @@ -import { pedersenHash, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; -import { IWasmModule } from '@aztec/foundation/wasm'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Hasher } from '@aztec/types'; /** @@ -8,14 +7,12 @@ import { Hasher } from '@aztec/types'; * purposes. */ export class Pedersen implements Hasher { - constructor(private wasm: IWasmModule) {} - /* * @deprecated Don't call pedersen directly in production code. Instead, create suitably-named functions for specific * purposes. */ public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHash(this.wasm, lhs, rhs); + return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]); } /* @@ -23,6 +20,6 @@ export class Pedersen implements Hasher { * purposes. */ public hashInputs(inputs: Buffer[]): Buffer { - return pedersenHashInputs(this.wasm, inputs); + return pedersenHash(inputs); } } diff --git a/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts b/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts index d5ed72d5e58..bd4f1e6bd0b 100644 --- a/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts +++ b/yarn-project/merkle-tree/src/sparse_tree/sparse_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { randomBytes } from 'crypto'; @@ -36,12 +34,10 @@ treeTestSuite('SparseTree', createDb, createFromName); standardBasedTreeTestSuite('SparseTree', createDb); describe('SparseTreeSpecific', () => { - let wasm: IWasmModule; let pedersen: Pedersen; - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('throws when index is bigger than (2^DEPTH - 1) ', async () => { diff --git a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts index d2f2c187609..2f6db0b1ac1 100644 --- a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts +++ b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -38,12 +36,10 @@ const TEST_TREE_DEPTH = 3; treeTestSuite('StandardIndexedTree', createDb, createFromName); describe('StandardIndexedTreeSpecific', () => { - let wasm: IWasmModule; let pedersen: Pedersen; - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('produces the correct roots and sibling paths', async () => { diff --git a/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts b/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts index 6cae5035466..ee3191f42ff 100644 --- a/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts +++ b/yarn-project/merkle-tree/src/standard_tree/standard_tree.test.ts @@ -1,6 +1,4 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; import { randomBytes } from '@aztec/foundation/crypto'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -26,12 +24,10 @@ treeTestSuite('StandardTree', createDb, createFromName); standardBasedTreeTestSuite('StandardTree', createDb); describe('StandardTree_batchAppend', () => { - let wasm: IWasmModule; let pedersen: PedersenWithCounter; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new PedersenWithCounter(wasm); + beforeAll(() => { + pedersen = new PedersenWithCounter(); }); afterEach(() => { diff --git a/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts b/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts index a5ed2f48099..3ccbd7ff6d1 100644 --- a/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts +++ b/yarn-project/merkle-tree/src/test/standard_based_test_suite.ts @@ -1,5 +1,3 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { randomBytes } from 'crypto'; @@ -23,13 +21,11 @@ export const standardBasedTreeTestSuite = ( ) => Promise, ) => { describe(testName, () => { - let wasm: IWasmModule; let pedersen: Pedersen; const values: Buffer[] = []; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeAll(() => { + pedersen = new Pedersen(); for (let i = 0; i < 4; ++i) { const v = Buffer.alloc(32, i + 1); diff --git a/yarn-project/merkle-tree/src/test/test_suite.ts b/yarn-project/merkle-tree/src/test/test_suite.ts index 9192e399fd1..1940f32ce91 100644 --- a/yarn-project/merkle-tree/src/test/test_suite.ts +++ b/yarn-project/merkle-tree/src/test/test_suite.ts @@ -1,5 +1,3 @@ -import { CircuitsWasm } from '@aztec/circuits.js'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { Hasher, SiblingPath } from '@aztec/types'; import { default as levelup } from 'levelup'; @@ -38,7 +36,6 @@ export const treeTestSuite = ( ) => { describe(testName, () => { const values: Buffer[] = []; - let wasm: IWasmModule; let pedersen: Pedersen; beforeAll(() => { @@ -49,9 +46,8 @@ export const treeTestSuite = ( } }); - beforeEach(async () => { - wasm = await CircuitsWasm.get(); - pedersen = new Pedersen(wasm); + beforeEach(() => { + pedersen = new Pedersen(); }); it('should revert changes on rollback', async () => { diff --git a/yarn-project/noir-protocol-circuits/src/index.test.ts b/yarn-project/noir-protocol-circuits/src/index.test.ts index 7fbc73c6ccb..893dcafc338 100644 --- a/yarn-project/noir-protocol-circuits/src/index.test.ts +++ b/yarn-project/noir-protocol-circuits/src/index.test.ts @@ -3,7 +3,6 @@ import { AztecAddress, CONTRACT_TREE_HEIGHT, CallContext, - CircuitsWasm, CombinedAccumulatedData, CombinedConstantData, ContractDeploymentData, @@ -405,24 +404,21 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { logger = createDebugLogger('noir-private-kernel-compatibility'); }); - it('Complete Address matches Noir', async () => { + it('Complete Address matches Noir', () => { logger('Initialized Noir instance with private kernel init circuit'); - const wasm = await CircuitsWasm.get(); const deployerPubKey = new Point(new Fr(1n), new Fr(2n)); const contractAddrSalt = new Fr(3n); const treeRoot = new Fr(4n); const constructorHash = new Fr(5n); - const res = computeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, treeRoot, constructorHash); + const res = computeCompleteAddress(deployerPubKey, contractAddrSalt, treeRoot, constructorHash); expect(res.address.toString()).toMatchSnapshot(); expect(res.publicKey).toMatchSnapshot(); expect(res.partialAddress.toString()).toMatchSnapshot(); }); - it('TxRequest Hash matches Noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('TxRequest Hash matches Noir', () => { const deploymentData = new ContractDeploymentData( new Point(new Fr(1), new Fr(2)), new Fr(1), @@ -436,14 +432,12 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { argsHash: new Fr(3), txContext: new TxContext(false, false, true, deploymentData, Fr.ZERO, Fr.ZERO), }); - const hash = computeTxHash(wasm, txRequest); + const hash = computeTxHash(txRequest); expect(hash.toString()).toMatchSnapshot(); }); - it('ComputeContractAddressFromPartial matches Noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('ComputeContractAddressFromPartial matches Noir', () => { const deploymentData = new ContractDeploymentData( new Point(new Fr(1), new Fr(2)), new Fr(1), @@ -457,16 +451,14 @@ describe('Noir compatibility tests (interop_testing.nr)', () => { argsHash: new Fr(3), txContext: new TxContext(false, false, true, deploymentData, Fr.ZERO, Fr.ZERO), }); - const hash = computeTxHash(wasm, txRequest); + const hash = computeTxHash(txRequest); expect(hash.toString()).toMatchSnapshot(); }); - it('Function leaf matches noir', async () => { - const wasm = await CircuitsWasm.get(); - + it('Function leaf matches noir', () => { const fnLeafPreimage = new FunctionLeafPreimage(new FunctionSelector(27), false, true, new Fr(1), new Fr(2)); - const fnLeaf = computeFunctionLeaf(wasm, fnLeafPreimage); + const fnLeaf = computeFunctionLeaf(fnLeafPreimage); expect(fnLeaf.toString()).toMatchSnapshot(); }); }); diff --git a/yarn-project/noir-protocol-circuits/src/noir_test_gen.test.ts b/yarn-project/noir-protocol-circuits/src/noir_test_gen.test.ts index c1ede73ca32..602a8b32ad5 100644 --- a/yarn-project/noir-protocol-circuits/src/noir_test_gen.test.ts +++ b/yarn-project/noir-protocol-circuits/src/noir_test_gen.test.ts @@ -37,7 +37,7 @@ describe('Data generation for noir tests', () => { it('Computes function leaf', () => { const functionLeafPreimage = new FunctionLeafPreimage(selector, false, true, vkHash, acirHash); - functionLeaf = computeFunctionLeaf(wasm, functionLeafPreimage); + functionLeaf = computeFunctionLeaf(functionLeafPreimage); expect(functionLeaf.toString()).toMatchSnapshot(); }); @@ -57,14 +57,13 @@ describe('Data generation for noir tests', () => { it('Computes the contract tree root', async () => { const contractLeaf = computeContractLeaf( - wasm, new NewContractData(contractAddress, portalContractAddress, functionTreeRoot), ); const db = levelup((memdown as any)()); const tree = new StandardTree( db, - new Pedersen(wasm), + new Pedersen(), `${MerkleTreeId[MerkleTreeId.CONTRACT_TREE]}`, CONTRACT_TREE_HEIGHT, ); @@ -86,7 +85,7 @@ describe('Data generation for noir tests', () => { const noteHashTree = new StandardTree( db, - new Pedersen(wasm), + new Pedersen(), `${MerkleTreeId[MerkleTreeId.NOTE_HASH_TREE]}`, NOTE_HASH_TREE_HEIGHT, ); diff --git a/yarn-project/package.json b/yarn-project/package.json index 33c83a466c5..3e85099f718 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -56,6 +56,7 @@ "eslint": "^8.21.0", "eslint-import-resolver-typescript": "^3.5.5", "eslint-plugin-import": "^2.27.5", + "madge": "^6.1.0", "prettier": "^2.8.8", "typedoc": "^0.24.8", "typescript": "^5.0.4" diff --git a/yarn-project/pxe/src/contract_tree/index.ts b/yarn-project/pxe/src/contract_tree/index.ts index c0fe69e7226..81546f39baf 100644 --- a/yarn-project/pxe/src/contract_tree/index.ts +++ b/yarn-project/pxe/src/contract_tree/index.ts @@ -87,14 +87,14 @@ export class ContractTree { ...f, selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters), })); - const leaves = generateFunctionLeaves(functions, wasm); + const leaves = generateFunctionLeaves(functions); const root = computeFunctionTreeRoot(wasm, leaves); const functionData = FunctionData.fromAbi(constructorArtifact); const vkHash = hashVKStr(constructorArtifact.verificationKey, wasm); - const argsHash = await computeVarArgsHash(wasm, args); - const constructorHash = hashConstructor(wasm, functionData, argsHash, vkHash); + const argsHash = computeVarArgsHash(args); + const constructorHash = hashConstructor(functionData, argsHash, vkHash); - const completeAddress = computeCompleteAddress(wasm, from, contractAddressSalt, root, constructorHash); + const completeAddress = computeCompleteAddress(from, contractAddressSalt, root, constructorHash); const contractDao: ContractDao = { ...artifact, @@ -218,7 +218,7 @@ export class ContractTree { */ private getFunctionLeaves() { if (!this.functionLeaves) { - this.functionLeaves = generateFunctionLeaves(this.contract.functions, this.wasm); + this.functionLeaves = generateFunctionLeaves(this.contract.functions); } return this.functionLeaves; } @@ -228,7 +228,7 @@ export class ContractTree { const { completeAddress, portalContract } = this.contract; const root = await this.getFunctionTreeRoot(); const newContractData = new NewContractData(completeAddress.address, portalContract, root); - const commitment = computeContractLeaf(this.wasm, newContractData); + const commitment = computeContractLeaf(newContractData); this.contractIndex = await this.stateInfoProvider.findLeafIndex(MerkleTreeId.CONTRACT_TREE, commitment); if (this.contractIndex === undefined) { throw new Error( diff --git a/yarn-project/pxe/src/kernel_prover/proof_creator.ts b/yarn-project/pxe/src/kernel_prover/proof_creator.ts index 84be723b22f..afd1e586224 100644 --- a/yarn-project/pxe/src/kernel_prover/proof_creator.ts +++ b/yarn-project/pxe/src/kernel_prover/proof_creator.ts @@ -1,5 +1,4 @@ import { - CircuitsWasm, KernelCircuitPublicInputs, KernelCircuitPublicInputsFinal, PrivateCircuitPublicInputs, @@ -98,11 +97,10 @@ export interface ProofCreator { export class KernelProofCreator implements ProofCreator { constructor(private log = createDebugLogger('aztec:kernel_proof_creator')) {} - public async getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { - const wasm = await CircuitsWasm.get(); + public getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) { const contractAddress = publicInputs.callContext.storageContractAddress; - return publicInputs.newCommitments.map(commitment => siloCommitment(wasm, contractAddress, commitment)); + return Promise.resolve(publicInputs.newCommitments.map(commitment => siloCommitment(contractAddress, commitment))); } public async createProofInit(privateInputs: PrivateKernelInputsInit): Promise { diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index ea13498b4f0..207850ee757 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -1,6 +1,7 @@ import { AcirSimulator } from '@aztec/acir-simulator'; import { CircuitsWasm, Fr, MAX_NEW_COMMITMENTS_PER_TX } from '@aztec/circuits.js'; -import { Grumpkin, pedersenHashInputs } from '@aztec/circuits.js/barretenberg'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Point } from '@aztec/foundation/fields'; import { ConstantKeyPair } from '@aztec/key-store'; import { @@ -40,13 +41,7 @@ describe('Note Processor', () => { const numCommitmentsPerBlock = TXS_PER_BLOCK * MAX_NEW_COMMITMENTS_PER_TX; const firstBlockDataStartIndex = (firstBlockNum - 1) * numCommitmentsPerBlock; - const computeMockNoteHash = (note: Note) => - Fr.fromBuffer( - pedersenHashInputs( - wasm, - note.items.map(i => i.toBuffer()), - ), - ); + const computeMockNoteHash = (note: Note) => Fr.fromBuffer(pedersenHash(note.items.map(i => i.toBuffer()))); // ownedData: [tx1, tx2, ...], the numbers in each tx represents the indices of the note hashes the account owns. const createEncryptedLogsAndOwnedL1NotePayloads = (ownedData: number[][], ownedNotes: L1NotePayload[]) => { diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index db9246e4cd9..385b4ee0c0d 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js'; +import { MAX_NEW_COMMITMENTS_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, PublicKey } from '@aztec/circuits.js'; import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { Fr } from '@aztec/foundation/fields'; @@ -196,7 +196,6 @@ export class NoteProcessor { { contractAddress, storageSlot, note }: L1NotePayload, excludedIndices: Set, ) { - const wasm = await CircuitsWasm.get(); let commitmentIndex = 0; let nonce: Fr | undefined; let innerNoteHash: Fr | undefined; @@ -209,7 +208,7 @@ export class NoteProcessor { const commitment = commitments[commitmentIndex]; if (commitment.equals(Fr.ZERO)) break; - const expectedNonce = computeCommitmentNonce(wasm, firstNullifier, commitmentIndex); + const expectedNonce = computeCommitmentNonce(firstNullifier, commitmentIndex); ({ innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier } = await this.simulator.computeNoteHashAndNullifier(contractAddress, expectedNonce, storageSlot, note)); if (commitment.equals(uniqueSiloedNoteHash)) { @@ -244,7 +243,7 @@ https://github.com/AztecProtocol/aztec-packages/issues/1641`; commitmentIndex, nonce, innerNoteHash: innerNoteHash!, - siloedNullifier: siloNullifier(wasm, contractAddress, innerNullifier!), + siloedNullifier: siloNullifier(contractAddress, innerNullifier!), }; } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index e6771d40018..26aec37b47a 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -8,7 +8,6 @@ import { } from '@aztec/acir-simulator'; import { AztecAddress, - CircuitsWasm, CompleteAddress, FunctionData, GrumpkinPrivateKey, @@ -238,8 +237,7 @@ export class PXEService implements PXE { throw new Error('Note does not exist.'); } - const wasm = await CircuitsWasm.get(); - const siloedNullifier = siloNullifier(wasm, note.contractAddress, innerNullifier!); + const siloedNullifier = siloNullifier(note.contractAddress, innerNullifier!); const nullifierIndex = await this.node.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier); if (nullifierIndex !== undefined) { throw new Error('The note has been destroyed.'); @@ -273,8 +271,6 @@ export class PXEService implements PXE { throw new Error(`Unknown tx: ${note.txHash}`); } - const wasm = await CircuitsWasm.get(); - const nonces: Fr[] = []; const firstNullifier = tx.newNullifiers[0]; const commitments = tx.newCommitments; @@ -282,7 +278,7 @@ export class PXEService implements PXE { const commitment = commitments[i]; if (commitment.equals(Fr.ZERO)) break; - const nonce = computeCommitmentNonce(wasm, firstNullifier, i); + const nonce = computeCommitmentNonce(firstNullifier, i); const { siloedNoteHash, uniqueSiloedNoteHash } = await this.simulator.computeNoteHashAndNullifier( note.contractAddress, nonce, @@ -626,7 +622,7 @@ export class PXEService implements PXE { publicInputs: KernelCircuitPublicInputsFinal, enqueuedPublicCalls: PublicCallRequest[], ) { - const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().then(item => item.hash()); + const callToHash = (call: PublicCallRequest) => call.toPublicCallStackItem().hash(); const enqueuedPublicCallsHashes = await Promise.all(enqueuedPublicCalls.map(callToHash)); const { publicCallStack } = publicInputs.end; diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index cbb772b36fa..fdc21c69941 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -34,7 +34,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('registers a recipient and returns it as a recipient only and not as an account', async () => { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); @@ -63,7 +63,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('cannot register a recipient with the same aztec address but different pub key or partial address', async () => { - const recipient1 = await CompleteAddress.random(); + const recipient1 = CompleteAddress.random(); const recipient2 = new CompleteAddress(recipient1.address, Point.random(), Fr.random()); await pxe.registerRecipient(recipient1); @@ -73,14 +73,14 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => }); it('does not throw when registering the same recipient twice (just ignores the second attempt)', async () => { - const completeAddress = await CompleteAddress.random(); + const completeAddress = CompleteAddress.random(); await pxe.registerRecipient(completeAddress); await pxe.registerRecipient(completeAddress); }); it('successfully adds a contract', async () => { - const contracts: DeployedContract[] = [await randomDeployedContract(), await randomDeployedContract()]; + const contracts: DeployedContract[] = [randomDeployedContract(), randomDeployedContract()]; await pxe.addContracts(contracts); const expectedContractAddresses = contracts.map(contract => contract.completeAddress.address); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index bc3ad8c03d6..fec240b9ef1 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -1,4 +1,4 @@ -import { AztecAddress, CircuitsWasm, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; +import { AztecAddress, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js'; import { computeGlobalsHash } from '@aztec/circuits.js/abis'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { InterruptibleSleep } from '@aztec/foundation/sleep'; @@ -199,8 +199,7 @@ export class Synchronizer { const { block } = latestBlock; if (block.number < this.initialSyncBlockNumber) return; - const wasm = await CircuitsWasm.get(); - const globalsHash = computeGlobalsHash(wasm, latestBlock.block.globalVariables); + const globalsHash = computeGlobalsHash(latestBlock.block.globalVariables); const blockData = new HistoricBlockData( block.endNoteHashTreeSnapshot.root, block.endNullifierTreeSnapshot.root, diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index e5c828cb5c8..f5ddccffe60 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -1,7 +1,6 @@ import { AppendOnlyTreeSnapshot, BaseOrMergeRollupPublicInputs, - CircuitsWasm, Fr, GlobalVariables, KernelCircuitPublicInputs, @@ -80,8 +79,6 @@ describe('sequencer/solo_block_builder', () => { let rootRollupOutput: RootRollupPublicInputs; let mockL1ToL2Messages: Fr[]; - let wasm: CircuitsWasm; - let globalVariables: GlobalVariables; const emptyProof = new Proof(Buffer.alloc(32, 0)); @@ -89,10 +86,6 @@ describe('sequencer/solo_block_builder', () => { const chainId = Fr.ZERO; const version = Fr.ZERO; - beforeAll(async () => { - wasm = await CircuitsWasm.get(); - }); - beforeEach(async () => { blockNumber = 3; globalVariables = new GlobalVariables(chainId, version, new Fr(blockNumber), Fr.ZERO); @@ -128,7 +121,7 @@ describe('sequencer/solo_block_builder', () => { // Updates the expectedDb trees based on the new commitments, contracts, and nullifiers from these txs const updateExpectedTreesFromTxs = async (txs: ProcessedTx[]) => { - const newContracts = flatMap(txs, tx => tx.data.end.newContracts.map(n => computeContractLeaf(wasm, n))); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts.map(n => computeContractLeaf(n))); for (const [tree, leaves] of [ [MerkleTreeId.NOTE_HASH_TREE, flatMap(txs, tx => tx.data.end.newCommitments.map(l => l.toBuffer()))], [MerkleTreeId.CONTRACT_TREE, newContracts.map(x => x.toBuffer())], @@ -152,7 +145,6 @@ describe('sequencer/solo_block_builder', () => { const updateHistoricBlocksTree = async () => { const blockHash = computeBlockHashWithGlobals( - wasm, globalVariables, rootRollupOutput.endNoteHashTreeSnapshot.root, rootRollupOutput.endNullifierTreeSnapshot.root, @@ -219,7 +211,7 @@ describe('sequencer/solo_block_builder', () => { const newNullifiers = flatMap(txs, tx => tx.data.end.newNullifiers); const newCommitments = flatMap(txs, tx => tx.data.end.newCommitments); - const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(wasm, cd)); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(cd)); const newContractData = flatMap(txs, tx => tx.data.end.newContracts).map( n => new ContractData(n.contractAddress, n.portalContractAddress), ); diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index eabf7066040..b02c12ebb1c 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -4,7 +4,6 @@ import { BaseRollupInputs, CONTRACT_SUBTREE_HEIGHT, CONTRACT_SUBTREE_SIBLING_PATH_LENGTH, - CircuitsWasm, ConstantRollupData, GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, @@ -132,10 +131,9 @@ export class SoloBlockBuilder implements BlockBuilder { } = circuitsOutput; // Collect all new nullifiers, commitments, and contracts from all txs in this block - const wasm = await CircuitsWasm.get(); const newNullifiers = flatMap(txs, tx => tx.data.end.newNullifiers); const newCommitments = flatMap(txs, tx => tx.data.end.newCommitments); - const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(wasm, cd)); + const newContracts = flatMap(txs, tx => tx.data.end.newContracts).map(cd => computeContractLeaf(cd)); const newContractData = flatMap(txs, tx => tx.data.end.newContracts).map( n => new ContractData(n.contractAddress, n.portalContractAddress), ); @@ -313,7 +311,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Update the root trees with the latest data and contract tree roots, // and validate them against the output of the root circuit simulation this.debug(`Updating and validating root trees`); - const globalVariablesHash = computeGlobalsHash(await CircuitsWasm.get(), left[0].constants.globalVariables); + const globalVariablesHash = computeGlobalsHash(left[0].constants.globalVariables); await this.db.updateLatestGlobalVariablesHash(globalVariablesHash); await this.db.updateHistoricBlocksTree(globalVariablesHash); @@ -341,9 +339,7 @@ export class SoloBlockBuilder implements BlockBuilder { ) ).map(r => r.root); - const wasm = await CircuitsWasm.get(); const blockHash = computeBlockHashWithGlobals( - wasm, globals, noteHashTreeRoot, nullifierTreeRoot, @@ -541,14 +537,11 @@ export class SoloBlockBuilder implements BlockBuilder { return new MembershipWitness(height, index, assertLength(path.toFieldArray(), height)); } - protected async getHistoricTreesMembershipWitnessFor(tx: ProcessedTx) { - const wasm = await CircuitsWasm.get(); - + protected getHistoricTreesMembershipWitnessFor(tx: ProcessedTx) { const blockData = tx.data.constants.blockData; const { noteHashTreeRoot, nullifierTreeRoot, contractTreeRoot, l1ToL2MessagesTreeRoot, publicDataTreeRoot } = blockData; const blockHash = computeBlockHash( - wasm, blockData.globalVariablesHash, noteHashTreeRoot, nullifierTreeRoot, @@ -648,8 +641,6 @@ export class SoloBlockBuilder implements BlockBuilder { // Builds the base rollup inputs, updating the contract, nullifier, and data trees in the process protected async buildBaseRollupInput(left: ProcessedTx, right: ProcessedTx, globalVariables: GlobalVariables) { - const wasm = await CircuitsWasm.get(); - // Get trees info before any changes hit const constants = await this.getConstantRollupData(globalVariables); const startNullifierTreeSnapshot = await this.getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE); @@ -679,9 +670,7 @@ export class SoloBlockBuilder implements BlockBuilder { // Update the contract and note hash trees with the new items being inserted to get the new roots // that will be used by the next iteration of the base rollup circuit, skipping the empty ones - const newContracts = flatMap([left, right], tx => - tx.data.end.newContracts.map(cd => computeContractLeaf(wasm, cd)), - ); + const newContracts = flatMap([left, right], tx => tx.data.end.newContracts.map(cd => computeContractLeaf(cd))); const newCommitments = flatMap([left, right], tx => tx.data.end.newCommitments.map(x => x.toBuffer())); await this.db.appendLeaves( MerkleTreeId.CONTRACT_TREE, diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts index e0761465d09..64a36de4d09 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.test.ts @@ -175,7 +175,7 @@ describe('public_processor', () => { it('runs a tx with an enqueued public call with nested execution', async function () { const callRequest: PublicCallRequest = makePublicCallRequest(0x100); - const callStackItem = await callRequest.toPublicCallStackItem(); + const callStackItem = callRequest.toPublicCallStackItem(); const callStackHash = computeCallStackItemHash(wasm, callStackItem); const kernelOutput = makePrivateKernelPublicInputsFinal(0x10); diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 1f63c6f4b82..501cd78ca4b 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -201,7 +201,7 @@ export class PublicProcessor { } // HACK(#1622): Manually patches the ordering of public state actions // TODO(#757): Enforce proper ordering of public state actions - await this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!); + this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!); } return [kernelOutput, kernelProof, newUnencryptedFunctionLogs]; @@ -262,7 +262,7 @@ export class PublicProcessor { return PublicCircuitPublicInputs.from({ callContext: result.execution.callContext, proverAddress: AztecAddress.ZERO, - argsHash: await computeVarArgsHash(wasm, result.execution.args), + argsHash: computeVarArgsHash(result.execution.args), newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL), newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL), newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_CALL), @@ -345,14 +345,10 @@ export class PublicProcessor { * @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point * @param execResult - result of the top/first execution for this enqueued public call */ - private async patchPublicStorageActionOrdering( - publicInputs: KernelCircuitPublicInputs, - execResult: PublicExecutionResult, - ) { + private patchPublicStorageActionOrdering(publicInputs: KernelCircuitPublicInputs, execResult: PublicExecutionResult) { // Convert ContractStorage* objects to PublicData* objects and sort them in execution order - const wasm = await CircuitsWasm.get(); - const simPublicDataReads = collectPublicDataReads(wasm, execResult); - const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(wasm, execResult); + const simPublicDataReads = collectPublicDataReads(execResult); + const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult); const { publicDataReads, publicDataUpdateRequests } = publicInputs.end; // from kernel diff --git a/yarn-project/sequencer-client/src/sequencer/utils.ts b/yarn-project/sequencer-client/src/sequencer/utils.ts index d49536ba060..b43747fc644 100644 --- a/yarn-project/sequencer-client/src/sequencer/utils.ts +++ b/yarn-project/sequencer-client/src/sequencer/utils.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js'; +import { Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js'; import { computeGlobalsHash } from '@aztec/circuits.js/abis'; import { MerkleTreeOperations } from '@aztec/world-state'; @@ -9,8 +9,7 @@ export async function getHistoricBlockData( db: MerkleTreeOperations, prevBlockGlobalVariables: GlobalVariables = GlobalVariables.empty(), ) { - const wasm = await CircuitsWasm.get(); - const prevGlobalsHash = computeGlobalsHash(wasm, prevBlockGlobalVariables); + const prevGlobalsHash = computeGlobalsHash(prevBlockGlobalVariables); const roots = await db.getTreeRoots(); return new HistoricBlockData( diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index affb9e1ccb6..d0e6b024f3f 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -5,7 +5,7 @@ import { PublicExecutor, PublicStateDB, } from '@aztec/acir-simulator'; -import { AztecAddress, CircuitsWasm, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, Fr, FunctionSelector, HistoricBlockData } from '@aztec/circuits.js'; import { computePublicDataTreeIndex } from '@aztec/circuits.js/abis'; import { ContractDataSource, ExtendedContractData, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types'; import { MerkleTreeOperations } from '@aztec/world-state'; @@ -107,7 +107,7 @@ class WorldStatePublicDB implements PublicStateDB { * @returns The current value in the storage slot. */ public async storageRead(contract: AztecAddress, slot: Fr): Promise { - const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value; + const index = computePublicDataTreeIndex(contract, slot).value; const cached = this.writeCache.get(index); if (cached !== undefined) return cached; const value = await this.db.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, index); @@ -120,9 +120,10 @@ class WorldStatePublicDB implements PublicStateDB { * @param slot - Slot to read in the contract storage. * @param newValue - The new value to store. */ - public async storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise { - const index = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot).value; + public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise { + const index = computePublicDataTreeIndex(contract, slot).value; this.writeCache.set(index, newValue); + return Promise.resolve(); } } diff --git a/yarn-project/types/src/mocks.ts b/yarn-project/types/src/mocks.ts index 459c436afff..5752c8789f8 100644 --- a/yarn-project/types/src/mocks.ts +++ b/yarn-project/types/src/mocks.ts @@ -47,9 +47,9 @@ export const randomContractArtifact = (): ContractArtifact => ({ events: [], }); -export const randomDeployedContract = async (): Promise => ({ +export const randomDeployedContract = (): DeployedContract => ({ artifact: randomContractArtifact(), - completeAddress: await CompleteAddress.random(), + completeAddress: CompleteAddress.random(), portalContract: EthAddress.random(), }); diff --git a/yarn-project/types/src/packed_arguments.ts b/yarn-project/types/src/packed_arguments.ts index 538afec05f6..8b59ede60ba 100644 --- a/yarn-project/types/src/packed_arguments.ts +++ b/yarn-project/types/src/packed_arguments.ts @@ -1,4 +1,4 @@ -import { CircuitsWasm, FieldsOf, Fr, Vector } from '@aztec/circuits.js'; +import { FieldsOf, Fr, Vector } from '@aztec/circuits.js'; import { computeVarArgsHash } from '@aztec/circuits.js/abis'; import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils'; @@ -25,8 +25,8 @@ export class PackedArguments { return new PackedArguments(...PackedArguments.getFields(fields)); } - static async fromArgs(args: Fr[], wasm?: CircuitsWasm) { - return new PackedArguments(args, await computeVarArgsHash(wasm ?? (await CircuitsWasm.get()), args)); + static fromArgs(args: Fr[]) { + return new PackedArguments(args, computeVarArgsHash(args)); } toBuffer() { diff --git a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts index 5dc3ec4bb1d..4fe162c12b0 100644 --- a/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts +++ b/yarn-project/world-state/src/synchronizer/server_world_state_synchronizer.test.ts @@ -1,6 +1,5 @@ import { AppendOnlyTreeSnapshot, - CircuitsWasm, Fr, GlobalVariables, MAX_NEW_COMMITMENTS_PER_TX, @@ -125,10 +124,9 @@ describe('server_world_state_synchronizer', () => { getTreeInfo: jest.fn(() => Promise.resolve({ depth: 8, treeId: MerkleTreeId.CONTRACT_TREE, root: Buffer.alloc(32, 0), size: 0n }), ), - getSiblingPath: jest.fn(async () => { - const wasm = await CircuitsWasm.get(); - const pedersen: Pedersen = new Pedersen(wasm); - return SiblingPath.ZERO(32, INITIAL_LEAF, pedersen) as SiblingPath; + getSiblingPath: jest.fn(() => { + const pedersen: Pedersen = new Pedersen(); + return Promise.resolve(SiblingPath.ZERO(32, INITIAL_LEAF, pedersen) as SiblingPath); }), handleL2Block: jest.fn(() => Promise.resolve({ isBlockOurs: false })), }); diff --git a/yarn-project/world-state/src/world-state-db/index.ts b/yarn-project/world-state/src/world-state-db/index.ts index 053e5db849c..8c0a92a77dd 100644 --- a/yarn-project/world-state/src/world-state-db/index.ts +++ b/yarn-project/world-state/src/world-state-db/index.ts @@ -1,245 +1,3 @@ -import { MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; -import { Fr } from '@aztec/foundation/fields'; -import { createDebugLogger } from '@aztec/foundation/log'; -import { LeafData, LowLeafWitnessData } from '@aztec/merkle-tree'; -import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types'; - export * from './merkle_trees.js'; +export * from './merkle_tree_db.js'; export { LeafData } from '@aztec/merkle-tree'; - -/** - * Type alias for the nullifier tree ID. - */ -export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE; - -/** - * Type alias for the public data tree ID. - */ -export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE; - -/** - * - * @remarks Short explanation: - * The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion. - * Padding with some values solves this issue. - * - * @remarks Thorough explanation: - * There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can - * prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of - * leaves that are added by one block" so that the first 'proper' block can insert a full subtree. - * - * Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g. - * 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023 - * more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047. - */ -export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX; - -/** - * Defines tree information. - */ -export interface TreeInfo { - /** - * The tree ID. - */ - treeId: MerkleTreeId; - /** - * The tree root. - */ - root: Buffer; - /** - * The number of leaves in the tree. - */ - size: bigint; - - /** - * The depth of the tree. - */ - depth: number; -} - -/** - * Adds a last boolean flag in each function on the type. - */ -type WithIncludeUncommitted = F extends (...args: [...infer Rest]) => infer Return - ? (...args: [...Rest, boolean]) => Return - : F; - -/** - * The current roots of the commitment trees - */ -export type CurrentTreeRoots = { - /** Note Hash Tree root. */ - noteHashTreeRoot: Buffer; - /** Contract data tree root. */ - contractDataTreeRoot: Buffer; - /** L1 to L2 Messages data tree root. */ - l1Tol2MessagesTreeRoot: Buffer; - /** Nullifier data tree root. */ - nullifierTreeRoot: Buffer; - /** Blocks tree root. */ - blocksTreeRoot: Buffer; - /** Public data tree root */ - publicDataTreeRoot: Buffer; -}; - -/** - * Defines the names of the setters on Merkle Trees. - */ -type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert'; - -/** - * Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data. - */ -export type MerkleTreeDb = { - [Property in keyof MerkleTreeOperations as Exclude]: WithIncludeUncommitted< - MerkleTreeOperations[Property] - >; -} & Pick; - -/** - * Defines the interface for operations on a set of Merkle Trees. - */ -export interface MerkleTreeOperations { - /** - * Appends leaves to a given tree. - * @param treeId - The tree to be updated. - * @param leaves - The set of leaves to be appended. - */ - appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise; - - /** - * Returns information about the given tree. - * @param treeId - The tree to be queried. - */ - getTreeInfo(treeId: MerkleTreeId): Promise; - - /** - * Gets the current roots of the commitment trees. - */ - getTreeRoots(): Promise; - - /** - * Gets sibling path for a leaf. - * @param treeId - The tree to be queried for a sibling path. - * @param index - The index of the leaf for which a sibling path should be returned. - */ - getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise>; - - /** - * Returns the previous index for a given value in an indexed tree. - * @param treeId - The tree for which the previous value index is required. - * @param value - The value to be queried. - */ - getPreviousValueIndex( - treeId: IndexedTreeId, - value: bigint, - ): Promise<{ - /** - * The index of the found leaf. - */ - index: number; - /** - * A flag indicating if the corresponding leaf's value is equal to `newValue`. - */ - alreadyPresent: boolean; - }>; - - /** - * Returns the data at a specific leaf. - * @param treeId - The tree for which leaf data should be returned. - * @param index - The index of the leaf required. - */ - getLeafData(treeId: IndexedTreeId, index: number): Promise; - - /** - * Update the leaf data at the given index. - * @param treeId - The tree for which leaf data should be edited. - * @param leaf - The updated leaf value. - * @param index - The index of the leaf to be updated. - */ - updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise; - - /** - * Returns the index containing a leaf value. - * @param treeId - The tree for which the index should be returned. - * @param value - The value to search for in the tree. - */ - findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise; - - /** - * Gets the value for a leaf in the tree. - * @param treeId - The tree for which the index should be returned. - * @param index - The index of the leaf. - */ - getLeafValue(treeId: MerkleTreeId, index: bigint): Promise; - - /** - * Inserts the new block hash into the new block hashes tree. - * This includes all of the current roots of all of the data trees and the current blocks global vars. - * @param globalVariablesHash - The global variables hash to insert into the block hash. - */ - updateHistoricBlocksTree(globalVariablesHash: Fr): Promise; - - /** - * Updates the latest global variables hash - * @param globalVariablesHash - The latest global variables hash - */ - updateLatestGlobalVariablesHash(globalVariablesHash: Fr): Promise; - - /** - * Gets the global variables hash from the previous block - */ - getLatestGlobalVariablesHash(): Promise; - - /** - * Batch insert multiple leaves into the tree. - * @param leaves - Leaves to insert into the tree. - * @param treeId - The tree on which to insert. - * @param subtreeHeight - Height of the subtree. - * @returns The witness data for the leaves to be updated when inserting the new ones. - */ - batchInsert( - treeId: MerkleTreeId, - leaves: Buffer[], - subtreeHeight: number, - ): Promise<[LowLeafWitnessData[], SiblingPath] | [undefined, SiblingPath]>; - - /** - * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree). - * @param block - The L2 block to handle. - */ - handleL2Block(block: L2Block): Promise; - - /** - * Commits pending changes to the underlying store. - */ - commit(): Promise; - - /** - * Rolls back pending changes. - */ - rollback(): Promise; -} - -/** Return type for handleL2Block */ -export type HandleL2BlockResult = { - /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean; -}; - -/** - * Outputs a tree leaves using for debugging purposes. - */ -export async function inspectTree( - db: MerkleTreeOperations, - treeId: MerkleTreeId, - log = createDebugLogger('aztec:inspect-tree'), -) { - const info = await db.getTreeInfo(treeId); - const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`]; - for (let i = 0; i < info.size; i++) { - output.push( - ` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`, - ); - } - log(output.join('\n')); -} diff --git a/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts b/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts new file mode 100644 index 00000000000..0f23abaa257 --- /dev/null +++ b/yarn-project/world-state/src/world-state-db/merkle_tree_db.ts @@ -0,0 +1,242 @@ +import { MAX_NEW_NULLIFIERS_PER_TX } from '@aztec/circuits.js'; +import { Fr } from '@aztec/foundation/fields'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { LeafData, LowLeafWitnessData } from '@aztec/merkle-tree'; +import { L2Block, MerkleTreeId, SiblingPath } from '@aztec/types'; + +/** + * Type alias for the nullifier tree ID. + */ +export type IndexedTreeId = MerkleTreeId.NULLIFIER_TREE; + +/** + * Type alias for the public data tree ID. + */ +export type PublicTreeId = MerkleTreeId.PUBLIC_DATA_TREE; + +/** + * + * @remarks Short explanation: + * The nullifier tree must be initially padded as the pre-populated 0 index prevents efficient subtree insertion. + * Padding with some values solves this issue. + * + * @remarks Thorough explanation: + * There needs to be an initial (0,0,0) leaf in the tree, so that when we insert the first 'proper' leaf, we can + * prove that any value greater than 0 doesn't exist in the tree yet. We prefill/pad the tree with "the number of + * leaves that are added by one block" so that the first 'proper' block can insert a full subtree. + * + * Without this padding, there would be a leaf (0,0,0) at leaf index 0, making it really difficult to insert e.g. + * 1024 leaves for the first block, because there's only neat space for 1023 leaves after 0. By padding with 1023 + * more leaves, we can then insert the first block of 1024 leaves into indices 1024:2047. + */ +export const INITIAL_NULLIFIER_TREE_SIZE = 2 * MAX_NEW_NULLIFIERS_PER_TX; + +/** + * Defines tree information. + */ +export interface TreeInfo { + /** + * The tree ID. + */ + treeId: MerkleTreeId; + /** + * The tree root. + */ + root: Buffer; + /** + * The number of leaves in the tree. + */ + size: bigint; + + /** + * The depth of the tree. + */ + depth: number; +} + +/** + * Adds a last boolean flag in each function on the type. + */ +type WithIncludeUncommitted = F extends (...args: [...infer Rest]) => infer Return + ? (...args: [...Rest, boolean]) => Return + : F; + +/** + * The current roots of the commitment trees + */ +export type CurrentTreeRoots = { + /** Note Hash Tree root. */ + noteHashTreeRoot: Buffer; + /** Contract data tree root. */ + contractDataTreeRoot: Buffer; + /** L1 to L2 Messages data tree root. */ + l1Tol2MessagesTreeRoot: Buffer; + /** Nullifier data tree root. */ + nullifierTreeRoot: Buffer; + /** Blocks tree root. */ + blocksTreeRoot: Buffer; + /** Public data tree root */ + publicDataTreeRoot: Buffer; +}; + +/** + * Defines the names of the setters on Merkle Trees. + */ +type MerkleTreeSetters = 'appendLeaves' | 'updateLeaf' | 'commit' | 'rollback' | 'handleL2Block' | 'batchInsert'; + +/** + * Defines the interface for operations on a set of Merkle Trees configuring whether to return committed or uncommitted data. + */ +export type MerkleTreeDb = { + [Property in keyof MerkleTreeOperations as Exclude]: WithIncludeUncommitted< + MerkleTreeOperations[Property] + >; +} & Pick; + +/** + * Defines the interface for operations on a set of Merkle Trees. + */ +export interface MerkleTreeOperations { + /** + * Appends leaves to a given tree. + * @param treeId - The tree to be updated. + * @param leaves - The set of leaves to be appended. + */ + appendLeaves(treeId: MerkleTreeId, leaves: Buffer[]): Promise; + + /** + * Returns information about the given tree. + * @param treeId - The tree to be queried. + */ + getTreeInfo(treeId: MerkleTreeId): Promise; + + /** + * Gets the current roots of the commitment trees. + */ + getTreeRoots(): Promise; + + /** + * Gets sibling path for a leaf. + * @param treeId - The tree to be queried for a sibling path. + * @param index - The index of the leaf for which a sibling path should be returned. + */ + getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise>; + + /** + * Returns the previous index for a given value in an indexed tree. + * @param treeId - The tree for which the previous value index is required. + * @param value - The value to be queried. + */ + getPreviousValueIndex( + treeId: IndexedTreeId, + value: bigint, + ): Promise<{ + /** + * The index of the found leaf. + */ + index: number; + /** + * A flag indicating if the corresponding leaf's value is equal to `newValue`. + */ + alreadyPresent: boolean; + }>; + + /** + * Returns the data at a specific leaf. + * @param treeId - The tree for which leaf data should be returned. + * @param index - The index of the leaf required. + */ + getLeafData(treeId: IndexedTreeId, index: number): Promise; + + /** + * Update the leaf data at the given index. + * @param treeId - The tree for which leaf data should be edited. + * @param leaf - The updated leaf value. + * @param index - The index of the leaf to be updated. + */ + updateLeaf(treeId: IndexedTreeId | PublicTreeId, leaf: LeafData | Buffer, index: bigint): Promise; + + /** + * Returns the index containing a leaf value. + * @param treeId - The tree for which the index should be returned. + * @param value - The value to search for in the tree. + */ + findLeafIndex(treeId: MerkleTreeId, value: Buffer): Promise; + + /** + * Gets the value for a leaf in the tree. + * @param treeId - The tree for which the index should be returned. + * @param index - The index of the leaf. + */ + getLeafValue(treeId: MerkleTreeId, index: bigint): Promise; + + /** + * Inserts the new block hash into the new block hashes tree. + * This includes all of the current roots of all of the data trees and the current blocks global vars. + * @param globalVariablesHash - The global variables hash to insert into the block hash. + */ + updateHistoricBlocksTree(globalVariablesHash: Fr): Promise; + + /** + * Updates the latest global variables hash + * @param globalVariablesHash - The latest global variables hash + */ + updateLatestGlobalVariablesHash(globalVariablesHash: Fr): Promise; + + /** + * Gets the global variables hash from the previous block + */ + getLatestGlobalVariablesHash(): Promise; + + /** + * Batch insert multiple leaves into the tree. + * @param leaves - Leaves to insert into the tree. + * @param treeId - The tree on which to insert. + * @param subtreeHeight - Height of the subtree. + * @returns The witness data for the leaves to be updated when inserting the new ones. + */ + batchInsert( + treeId: MerkleTreeId, + leaves: Buffer[], + subtreeHeight: number, + ): Promise<[LowLeafWitnessData[], SiblingPath] | [undefined, SiblingPath]>; + + /** + * Handles a single L2 block (i.e. Inserts the new commitments into the merkle tree). + * @param block - The L2 block to handle. + */ + handleL2Block(block: L2Block): Promise; + + /** + * Commits pending changes to the underlying store. + */ + commit(): Promise; + + /** + * Rolls back pending changes. + */ + rollback(): Promise; +} + +/** Return type for handleL2Block */ +export type HandleL2BlockResult = { + /** Whether the block processed was emitted by our sequencer */ isBlockOurs: boolean; +}; + +/** + * Outputs a tree leaves using for debugging purposes. + */ +export async function inspectTree( + db: MerkleTreeOperations, + treeId: MerkleTreeId, + log = createDebugLogger('aztec:inspect-tree'), +) { + const info = await db.getTreeInfo(treeId); + const output = [`Tree id=${treeId} size=${info.size} root=0x${info.root.toString('hex')}`]; + for (let i = 0; i < info.size; i++) { + output.push( + ` Leaf ${i}: ${await db.getLeafValue(treeId, BigInt(i)).then(x => x?.toString('hex') ?? '[undefined]')}`, + ); + } + log(output.join('\n')); +} diff --git a/yarn-project/world-state/src/world-state-db/merkle_trees.ts b/yarn-project/world-state/src/world-state-db/merkle_trees.ts index c41555b52be..4ae2e41b858 100644 --- a/yarn-project/world-state/src/world-state-db/merkle_trees.ts +++ b/yarn-project/world-state/src/world-state-db/merkle_trees.ts @@ -1,6 +1,5 @@ import { CONTRACT_TREE_HEIGHT, - CircuitsWasm, Fr, GlobalVariables, HISTORIC_BLOCKS_TREE_HEIGHT, @@ -14,7 +13,6 @@ import { computeBlockHash, computeGlobalsHash } from '@aztec/circuits.js/abis'; import { Committable } from '@aztec/foundation/committable'; import { SerialQueue } from '@aztec/foundation/fifo'; import { createDebugLogger } from '@aztec/foundation/log'; -import { IWasmModule } from '@aztec/foundation/wasm'; import { AppendOnlyTree, IndexedTree, @@ -42,7 +40,7 @@ import { MerkleTreeOperations, PublicTreeId, TreeInfo, -} from './index.js'; +} from './merkle_tree_db.js'; /** * Data necessary to reinitialize the merkle trees from Db. @@ -71,12 +69,11 @@ export class MerkleTrees implements MerkleTreeDb { * @param optionalWasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used). * @param fromDbOptions - Options to initialize the trees from the database. */ - public async init(optionalWasm?: IWasmModule, fromDbOptions?: FromDbOptions) { + public async init(fromDbOptions?: FromDbOptions) { const fromDb = fromDbOptions !== undefined; const initializeTree = fromDb ? loadTree : newTree; - const wasm = optionalWasm ?? (await CircuitsWasm.get()); - const hasher = new Pedersen(wasm); + const hasher = new Pedersen(); const contractTree: AppendOnlyTree = await initializeTree( StandardTree, this.db, @@ -126,12 +123,12 @@ export class MerkleTrees implements MerkleTreeDb { // The first leaf in the blocks tree contains the empty roots of the other trees and empty global variables. if (!fromDb) { - const initialGlobalVariablesHash = computeGlobalsHash(wasm, GlobalVariables.empty()); + const initialGlobalVariablesHash = computeGlobalsHash(GlobalVariables.empty()); await this._updateLatestGlobalVariablesHash(initialGlobalVariablesHash); await this._updateHistoricBlocksTree(initialGlobalVariablesHash, true); await this._commit(); } else { - await this._updateLatestGlobalVariablesHash(computeGlobalsHash(wasm, fromDbOptions.globalVariables)); + await this._updateLatestGlobalVariablesHash(computeGlobalsHash(fromDbOptions.globalVariables)); } } @@ -141,9 +138,9 @@ export class MerkleTrees implements MerkleTreeDb { * @param wasm - WASM instance to use for hashing (if not provided PrimitivesWasm will be used). * @returns - A fully initialized MerkleTrees instance. */ - public static async new(db: levelup.LevelUp, wasm?: IWasmModule) { + public static async new(db: levelup.LevelUp) { const merkleTrees = new MerkleTrees(db); - await merkleTrees.init(wasm); + await merkleTrees.init(); return merkleTrees; } @@ -226,8 +223,7 @@ export class MerkleTrees implements MerkleTreeDb { private async _getCurrentBlockHash(globalsHash: Fr, includeUncommitted: boolean): Promise { const roots = (await this._getAllTreeRoots(includeUncommitted)).map(root => Fr.fromBuffer(root)); - const wasm = await CircuitsWasm.get(); - return computeBlockHash(wasm, globalsHash, roots[0], roots[1], roots[2], roots[3], roots[4]); + return computeBlockHash(globalsHash, roots[0], roots[1], roots[2], roots[3], roots[4]); } private _getAllTreeRoots(includeUncommitted: boolean): Promise { @@ -574,7 +570,7 @@ export class MerkleTrees implements MerkleTreeDb { } // Sync and add the block to the historic blocks tree - const globalVariablesHash = computeGlobalsHash(await CircuitsWasm.get(), l2Block.globalVariables); + const globalVariablesHash = computeGlobalsHash(l2Block.globalVariables); await this._updateLatestGlobalVariablesHash(globalVariablesHash); this.log(`Synced global variables with hash ${globalVariablesHash}`); diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 4d92493bd06..0ce208ab3d3 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -42,12 +42,21 @@ # FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/circuits-wasm-linux-clang as circuits FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/l1-contracts as contracts +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/bb.js as bb.js FROM node:18-alpine RUN apk update && apk add --no-cache bash jq curl -WORKDIR /usr/src/yarn-project +# Bring in circuits wasms. +COPY --from=circuits /usr/src/circuits/cpp/build-wasm/bin /usr/src/circuits/cpp/build-wasm/bin +# Copy ignition download script. +COPY --from=circuits /usr/src/barretenberg/cpp/srs_db/download_ignition.sh /usr/src/barretenberg/cpp/srs_db/download_ignition.sh +# Copy L1 contracts. +COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts +# Copy in bb.js +COPY --from=bb.js /usr/src/barretenberg/ts /usr/src/barretenberg/ts +WORKDIR /usr/src/yarn-project # The dockerignore file ensures the context only contains package.json and tsconfig.json files. COPY . . @@ -67,13 +76,5 @@ RUN echo "enableNetwork: false" >> .yarnrc.yml # Check package.json inheritance and tsconfig project references. RUN yarn prepare:check -# Bring in circuits wasms. -COPY --from=circuits /usr/src/circuits/cpp/build-wasm/bin /usr/src/circuits/cpp/build-wasm/bin - -# Copy ignition download script. -COPY --from=circuits /usr/src/barretenberg/cpp/srs_db/download_ignition.sh /usr/src/barretenberg/cpp/srs_db/download_ignition.sh - -# Copy L1 contracts. -COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts # Generate L1 contract TypeScript artifacts. -RUN cd l1-artifacts && ./scripts/generate-artifacts.sh +RUN cd l1-artifacts && ./scripts/generate-artifacts.sh \ No newline at end of file diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 9d6cd934b86..faf9ff5debb 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -272,6 +272,7 @@ __metadata: eslint: ^8.21.0 eslint-import-resolver-typescript: ^3.5.5 eslint-plugin-import: ^2.27.5 + madge: ^6.1.0 prettier: ^2.8.8 typedoc: ^0.24.8 typescript: ^5.0.4 @@ -292,6 +293,19 @@ __metadata: languageName: node linkType: hard +"@aztec/bb.js@portal:../../barretenberg/ts::locator=%40aztec%2Ffoundation%40workspace%3Afoundation": + version: 0.0.0-use.local + resolution: "@aztec/bb.js@portal:../../barretenberg/ts::locator=%40aztec%2Ffoundation%40workspace%3Afoundation" + dependencies: + comlink: ^4.4.1 + commander: ^10.0.1 + debug: ^4.3.4 + tslib: ^2.4.0 + bin: + bb.js: ./dest/node/main.js + languageName: node + linkType: soft + "@aztec/canary@workspace:canary": version: 0.0.0-use.local resolution: "@aztec/canary@workspace:canary" @@ -475,12 +489,15 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/foundation@workspace:foundation" dependencies: + "@aztec/bb.js": "portal:../../barretenberg/ts" "@jest/globals": ^29.5.0 "@koa/cors": ^4.0.0 "@noble/curves": ^1.2.0 "@rushstack/eslint-patch": ^1.1.4 + "@types/bn.js": ^5.1.3 "@types/debug": ^4.1.7 "@types/detect-node": ^2.0.0 + "@types/elliptic": ^6.4.16 "@types/jest": ^29.5.0 "@types/koa": ^2.13.5 "@types/koa-bodyparser": ^4.3.10 @@ -497,9 +514,11 @@ __metadata: "@types/supertest": ^2.0.12 "@typescript-eslint/eslint-plugin": ^6.2.1 "@typescript-eslint/parser": ^6.2.1 + bn.js: ^5.2.1 comlink: ^4.4.1 debug: ^4.3.4 detect-node: ^2.1.0 + elliptic: ^6.5.4 eslint: ^8.21.0 eslint-config-prettier: ^8.5.0 eslint-plugin-jsdoc: ^40.1.0 @@ -1108,6 +1127,15 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.21.4": + version: 7.23.0 + resolution: "@babel/parser@npm:7.23.0" + bin: + parser: ./bin/babel-parser.js + checksum: 453fdf8b9e2c2b7d7b02139e0ce003d1af21947bbc03eb350fb248ee335c9b85e4ab41697ddbdd97079698de825a265e45a0846bb2ed47a2c7c1df833f42a354 + languageName: node + linkType: hard + "@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.17.3, @babel/parser@npm:^7.20.5, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.22.5, @babel/parser@npm:^7.22.7": version: 7.22.7 resolution: "@babel/parser@npm:7.22.7" @@ -1478,6 +1506,16 @@ __metadata: languageName: node linkType: hard +"@dependents/detective-less@npm:^3.0.1": + version: 3.0.2 + resolution: "@dependents/detective-less@npm:3.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 2c263ab64fcd1f76117bc35f2b29a150c64bd2b105c96a909a63ce2f2baf07efd93d9ae80e612161d003fb71fbe46598292375f5cc3f447a1b83cfb545dc8f8f + languageName: node + linkType: hard + "@discoveryjs/json-ext@npm:^0.5.0": version: 0.5.7 resolution: "@discoveryjs/json-ext@npm:0.5.7" @@ -4278,6 +4316,15 @@ __metadata: languageName: node linkType: hard +"@types/bn.js@npm:*, @types/bn.js@npm:^5.1.3": + version: 5.1.3 + resolution: "@types/bn.js@npm:5.1.3" + dependencies: + "@types/node": "*" + checksum: 6cd144b8192b6655a009021a4f838a725ea3eb4c5e6425ffc5b144788f7612fb09018c2359954edef32ab7db15f7070b77d05499318b6d9824a55cb7e6776620 + languageName: node + linkType: hard + "@types/body-parser@npm:*": version: 1.19.2 resolution: "@types/body-parser@npm:1.19.2" @@ -4367,6 +4414,15 @@ __metadata: languageName: node linkType: hard +"@types/elliptic@npm:^6.4.16": + version: 6.4.16 + resolution: "@types/elliptic@npm:6.4.16" + dependencies: + "@types/bn.js": "*" + checksum: fedecadbab1a469a22bc9f8e44ce730bd945faed82230174c9df4748f29948d34d9d6f7c79122049cd37f048522e28019a470df7a55c86765a82fb0d05f3f415 + languageName: node + linkType: hard + "@types/eslint-scope@npm:^3.7.3": version: 3.7.4 resolution: "@types/eslint-scope@npm:3.7.4" @@ -5355,6 +5411,20 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/types@npm:4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/types@npm:4.33.0" + checksum: 3baae1ca35872421b4eb60f5d3f3f32dc1d513f2ae0a67dee28c7d159fd7a43ed0d11a8a5a0f0c2d38507ffa036fc7c511cb0f18a5e8ac524b3ebde77390ec53 + languageName: node + linkType: hard + +"@typescript-eslint/types@npm:5.62.0": + version: 5.62.0 + resolution: "@typescript-eslint/types@npm:5.62.0" + checksum: 48c87117383d1864766486f24de34086155532b070f6264e09d0e6139449270f8a9559cfef3c56d16e3bcfb52d83d42105d61b36743626399c7c2b5e0ac3b670 + languageName: node + linkType: hard + "@typescript-eslint/types@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/types@npm:6.2.1" @@ -5405,6 +5475,42 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:^4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/typescript-estree@npm:4.33.0" + dependencies: + "@typescript-eslint/types": 4.33.0 + "@typescript-eslint/visitor-keys": 4.33.0 + debug: ^4.3.1 + globby: ^11.0.3 + is-glob: ^4.0.1 + semver: ^7.3.5 + tsutils: ^3.21.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 2566984390c76bd95f43240057215c068c69769e406e27aba41e9f21fd300074d6772e4983fa58fe61e80eb5550af1548d2e31e80550d92ba1d051bb00fe6f5c + languageName: node + linkType: hard + +"@typescript-eslint/typescript-estree@npm:^5.55.0": + version: 5.62.0 + resolution: "@typescript-eslint/typescript-estree@npm:5.62.0" + dependencies: + "@typescript-eslint/types": 5.62.0 + "@typescript-eslint/visitor-keys": 5.62.0 + debug: ^4.3.4 + globby: ^11.1.0 + is-glob: ^4.0.3 + semver: ^7.3.7 + tsutils: ^3.21.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 3624520abb5807ed8f57b1197e61c7b1ed770c56dfcaca66372d584ff50175225798bccb701f7ef129d62c5989070e1ee3a0aa2d84e56d9524dcf011a2bb1a52 + languageName: node + linkType: hard + "@typescript-eslint/utils@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/utils@npm:6.2.1" @@ -5439,6 +5545,26 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/visitor-keys@npm:4.33.0": + version: 4.33.0 + resolution: "@typescript-eslint/visitor-keys@npm:4.33.0" + dependencies: + "@typescript-eslint/types": 4.33.0 + eslint-visitor-keys: ^2.0.0 + checksum: 59953e474ad4610c1aa23b2b1a964445e2c6201521da6367752f37939d854352bbfced5c04ea539274065e012b1337ba3ffa49c2647a240a4e87155378ba9873 + languageName: node + linkType: hard + +"@typescript-eslint/visitor-keys@npm:5.62.0": + version: 5.62.0 + resolution: "@typescript-eslint/visitor-keys@npm:5.62.0" + dependencies: + "@typescript-eslint/types": 5.62.0 + eslint-visitor-keys: ^3.3.0 + checksum: 976b05d103fe8335bef5c93ad3f76d781e3ce50329c0243ee0f00c0fcfb186c81df50e64bfdd34970148113f8ade90887f53e3c4938183afba830b4ba8e30a35 + languageName: node + linkType: hard + "@typescript-eslint/visitor-keys@npm:6.2.1": version: 6.2.1 resolution: "@typescript-eslint/visitor-keys@npm:6.2.1" @@ -6654,6 +6780,13 @@ __metadata: languageName: node linkType: hard +"any-promise@npm:^1.1.0": + version: 1.3.0 + resolution: "any-promise@npm:1.3.0" + checksum: 0ee8a9bdbe882c90464d75d1f55cf027f5458650c4bd1f0467e65aec38ccccda07ca5844969ee77ed46d04e7dded3eaceb027e8d32f385688523fe305fa7e1de + languageName: node + linkType: hard + "any-signal@npm:^4.1.1": version: 4.1.1 resolution: "any-signal@npm:4.1.1" @@ -6671,6 +6804,13 @@ __metadata: languageName: node linkType: hard +"app-module-path@npm:^2.2.0": + version: 2.2.0 + resolution: "app-module-path@npm:2.2.0" + checksum: b52aa49cfa809efbad41b514222e8ef3f8ee9e147f5eccf79280b45eddcc61f7aeb302b0049474e3f42072dd53a28348c57dd96f36cd461d2e31cc8ab1ef56b5 + languageName: node + linkType: hard + "aproba@npm:^1.0.3 || ^2.0.0": version: 2.0.0 resolution: "aproba@npm:2.0.0" @@ -6853,6 +6993,27 @@ __metadata: languageName: node linkType: hard +"ast-module-types@npm:^2.7.1": + version: 2.7.1 + resolution: "ast-module-types@npm:2.7.1" + checksum: 6238647bcf34eeff2a1390cb60388da8a5064dd598acf48d68f8d972d9a332dc8d0382a5a7c511b16470e314b313bcbb95de4b0b669515393e043282c0489538 + languageName: node + linkType: hard + +"ast-module-types@npm:^3.0.0": + version: 3.0.0 + resolution: "ast-module-types@npm:3.0.0" + checksum: c6ef35d9b286f84c7942aeb0e2b50e389e0b6f44ee3b6d2c46aeed4852dbca0681dde8c3c0ec1d456dad5dbc84fced2e1c607b10b4b4c3b065b901b40f45bbe7 + languageName: node + linkType: hard + +"ast-module-types@npm:^4.0.0": + version: 4.0.0 + resolution: "ast-module-types@npm:4.0.0" + checksum: 12705ff906e57d1440a2ff82f30cf5b3c93e1734076ea5868936477d5812a6fc257eb1e44fb2b7f8c22f7483987251d72251d2a295542f64df8768434f3f06db + languageName: node + linkType: hard + "ast-types@npm:^0.13.4": version: 0.13.4 resolution: "ast-types@npm:0.13.4" @@ -7151,6 +7312,17 @@ __metadata: languageName: node linkType: hard +"bl@npm:^4.1.0": + version: 4.1.0 + resolution: "bl@npm:4.1.0" + dependencies: + buffer: ^5.5.0 + inherits: ^2.0.4 + readable-stream: ^3.4.0 + checksum: 9e8521fa7e83aa9427c6f8ccdcba6e8167ef30cc9a22df26effcc5ab682ef91d2cbc23a239f945d099289e4bbcfae7a192e9c28c84c6202e710a0dfec3722662 + languageName: node + linkType: hard + "blank-contract-react@workspace:boxes/blank-react": version: 0.0.0-use.local resolution: "blank-contract-react@workspace:boxes/blank-react" @@ -7525,7 +7697,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:^5.2.1, buffer@npm:^5.4.3": +"buffer@npm:^5.2.1, buffer@npm:^5.4.3, buffer@npm:^5.5.0": version: 5.7.1 resolution: "buffer@npm:5.7.1" dependencies: @@ -7901,6 +8073,22 @@ __metadata: languageName: node linkType: hard +"cli-cursor@npm:^3.1.0": + version: 3.1.0 + resolution: "cli-cursor@npm:3.1.0" + dependencies: + restore-cursor: ^3.1.0 + checksum: 2692784c6cd2fd85cfdbd11f53aea73a463a6d64a77c3e098b2b4697a20443f430c220629e1ca3b195ea5ac4a97a74c2ee411f3807abf6df2b66211fec0c0a29 + languageName: node + linkType: hard + +"cli-spinners@npm:^2.5.0": + version: 2.9.1 + resolution: "cli-spinners@npm:2.9.1" + checksum: 1780618be58309c469205bc315db697934bac68bce78cd5dfd46248e507a533172d623c7348ecfd904734f597ce0a4e5538684843d2cfb7af485d4466699940c + languageName: node + linkType: hard + "clipboardy@npm:3.0.0": version: 3.0.0 resolution: "clipboardy@npm:3.0.0" @@ -7967,6 +8155,13 @@ __metadata: languageName: node linkType: hard +"clone@npm:^1.0.2": + version: 1.0.4 + resolution: "clone@npm:1.0.4" + checksum: d06418b7335897209e77bdd430d04f882189582e67bd1f75a04565f3f07f5b3f119a9d670c943b6697d0afb100f03b866b3b8a1f91d4d02d72c4ecf2bb64b5dd + languageName: node + linkType: hard + "clsx@npm:1.1.1": version: 1.1.1 resolution: "clsx@npm:1.1.1" @@ -8032,7 +8227,7 @@ __metadata: languageName: node linkType: hard -"color-name@npm:^1.0.0, color-name@npm:~1.1.4": +"color-name@npm:^1.0.0, color-name@npm:^1.1.4, color-name@npm:~1.1.4": version: 1.1.4 resolution: "color-name@npm:1.1.4" checksum: b0445859521eb4021cd0fb0cc1a75cecf67fceecae89b63f62b201cca8d345baf8b952c966862a9d9a2632987d4f6581f0ec8d957dfacece86f0a7919316f610 @@ -8108,14 +8303,21 @@ __metadata: languageName: node linkType: hard -"commander@npm:^2.20.0, commander@npm:^2.20.3": +"commander@npm:^2.16.0, commander@npm:^2.20.0, commander@npm:^2.20.3, commander@npm:^2.8.1": version: 2.20.3 resolution: "commander@npm:2.20.3" checksum: ab8c07884e42c3a8dbc5dd9592c606176c7eb5c1ca5ff274bcf907039b2c41de3626f684ea75ccf4d361ba004bbaff1f577d5384c155f3871e456bdf27becf9e languageName: node linkType: hard -"commander@npm:^9.0.0": +"commander@npm:^7.2.0": + version: 7.2.0 + resolution: "commander@npm:7.2.0" + checksum: 53501cbeee61d5157546c0bef0fedb6cdfc763a882136284bed9a07225f09a14b82d2a84e7637edfd1a679fb35ed9502fd58ef1d091e6287f60d790147f68ddc + languageName: node + linkType: hard + +"commander@npm:^9.0.0, commander@npm:^9.5.0": version: 9.5.0 resolution: "commander@npm:9.5.0" checksum: c7a3e27aa59e913b54a1bafd366b88650bc41d6651f0cbe258d4ff09d43d6a7394232a4dadd0bf518b3e696fdf595db1028a0d82c785b88bd61f8a440cecfade @@ -8141,6 +8343,13 @@ __metadata: languageName: node linkType: hard +"commondir@npm:^1.0.1": + version: 1.0.1 + resolution: "commondir@npm:1.0.1" + checksum: 59715f2fc456a73f68826285718503340b9f0dd89bfffc42749906c5cf3d4277ef11ef1cca0350d0e79204f00f1f6d83851ececc9095dc88512a697ac0b9bdcb + languageName: node + linkType: hard + "component-emitter@npm:^1.3.0": version: 1.3.0 resolution: "component-emitter@npm:1.3.0" @@ -8574,7 +8783,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": +"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.0.0, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" dependencies: @@ -8746,6 +8955,15 @@ __metadata: languageName: node linkType: hard +"defaults@npm:^1.0.3": + version: 1.0.4 + resolution: "defaults@npm:1.0.4" + dependencies: + clone: ^1.0.2 + checksum: 3a88b7a587fc076b84e60affad8b85245c01f60f38fc1d259e7ac1d89eb9ce6abb19e27215de46b98568dd5bc48471730b327637e6f20b0f1bc85cf00440c80a + languageName: node + linkType: hard + "deferred-leveldown@npm:^7.0.0": version: 7.0.0 resolution: "deferred-leveldown@npm:7.0.0" @@ -8833,6 +9051,21 @@ __metadata: languageName: node linkType: hard +"dependency-tree@npm:^9.0.0": + version: 9.0.0 + resolution: "dependency-tree@npm:9.0.0" + dependencies: + commander: ^2.20.3 + debug: ^4.3.1 + filing-cabinet: ^3.0.1 + precinct: ^9.0.0 + typescript: ^4.0.0 + bin: + dependency-tree: bin/cli.js + checksum: 38f95ec248f350f3ed443e0aac520c8ad979b3801262a1e67f6a5972c14f972887150d88972fb9e2630cef8c75efcd82719f93a55f9fc3207e64174ab9d3b0f3 + languageName: node + linkType: hard + "des.js@npm:^1.0.0": version: 1.1.0 resolution: "des.js@npm:1.1.0" @@ -8885,6 +9118,191 @@ __metadata: languageName: node linkType: hard +"detective-amd@npm:^3.1.0": + version: 3.1.2 + resolution: "detective-amd@npm:3.1.2" + dependencies: + ast-module-types: ^3.0.0 + escodegen: ^2.0.0 + get-amd-module-type: ^3.0.0 + node-source-walk: ^4.2.0 + bin: + detective-amd: bin/cli.js + checksum: 0b71555edad8e85c9a2ae85e2799d5faf2bdfe0de969587c9288ca76e717494678e34f444dffe32ffdd432e85ce50ca7017a5d0441a4855677a45a40c4590c74 + languageName: node + linkType: hard + +"detective-amd@npm:^4.0.1, detective-amd@npm:^4.1.0": + version: 4.2.0 + resolution: "detective-amd@npm:4.2.0" + dependencies: + ast-module-types: ^4.0.0 + escodegen: ^2.0.0 + get-amd-module-type: ^4.1.0 + node-source-walk: ^5.0.1 + bin: + detective-amd: bin/cli.js + checksum: c1e829a3202045796105680c9fe90ac61f63b0ccecc12cc30c7204c9e7ec22a4e2c3e2357719b9346a4e3579eba778cdce9a050e642938e2a4c8b57b091278e4 + languageName: node + linkType: hard + +"detective-cjs@npm:^3.1.1": + version: 3.1.3 + resolution: "detective-cjs@npm:3.1.3" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.0.0 + checksum: a691cb4afbbfea59d9aae0ee00752ec1a825a7ef18fc9178b53664975f162f3b537268590def009d9ce1cccfc5bc4f38cf775df08d0872aaacc05d96c72de85a + languageName: node + linkType: hard + +"detective-cjs@npm:^4.0.0, detective-cjs@npm:^4.1.0": + version: 4.1.0 + resolution: "detective-cjs@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + checksum: 17e40183959e9f377333a9fd03dcf4cbabf1b7a9f588882311066ecaaad68ad16765a7b63ffc096fc91d2a3c14ac044ed1823257c76105c9cb96dfc141a806e2 + languageName: node + linkType: hard + +"detective-es6@npm:^2.2.1": + version: 2.2.2 + resolution: "detective-es6@npm:2.2.2" + dependencies: + node-source-walk: ^4.0.0 + checksum: 9ee9909c089f5dcd1f89eccd347d509197996280ba24e2e08742bbc5ca3eef655ff07b4edfd76b52d6b4376ba03b8ec17d621c9f9c4382a6ba233dc1b1d00d33 + languageName: node + linkType: hard + +"detective-es6@npm:^3.0.0, detective-es6@npm:^3.0.1": + version: 3.0.1 + resolution: "detective-es6@npm:3.0.1" + dependencies: + node-source-walk: ^5.0.0 + checksum: 881a0c16b49504c212e61a521231ebbb4299a6102b178230959c74d2ca22d5f7538dfaf9518d01fb568ff93eadcf61d865d4428c9fed893dd4c91a7f29d515c5 + languageName: node + linkType: hard + +"detective-less@npm:^1.0.2": + version: 1.0.2 + resolution: "detective-less@npm:1.0.2" + dependencies: + debug: ^4.0.0 + gonzales-pe: ^4.2.3 + node-source-walk: ^4.0.0 + checksum: 858936fbad87423bd5d7502ff5fafca023e7c99e4006ed01b31c12c4b5ff8697edce91419798479d857efec68ee8f022fcac64de5530db6a64012be600a2249e + languageName: node + linkType: hard + +"detective-postcss@npm:^4.0.0": + version: 4.0.0 + resolution: "detective-postcss@npm:4.0.0" + dependencies: + debug: ^4.1.1 + is-url: ^1.2.4 + postcss: ^8.1.7 + postcss-values-parser: ^2.0.1 + checksum: e4c9fed31613df43466357fb104c4c5cdaf45a12909f7c1174161a45ebb2ebe77bb0843b3c0c117b68f55c9acb4e0578668298594c7f0108dfb73e54aaec8513 + languageName: node + linkType: hard + +"detective-postcss@npm:^6.1.0, detective-postcss@npm:^6.1.1": + version: 6.1.3 + resolution: "detective-postcss@npm:6.1.3" + dependencies: + is-url: ^1.2.4 + postcss: ^8.4.23 + postcss-values-parser: ^6.0.2 + checksum: 54c58227d5a1ec27e1b2b23bd992d823d0161d80e3d8ff6b202094e9841d53e88ac96a4d4cc9762ba4f09a9e038832b5d7c7a45b5e373c1c995c424a8289857b + languageName: node + linkType: hard + +"detective-sass@npm:^3.0.1": + version: 3.0.2 + resolution: "detective-sass@npm:3.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^4.0.0 + checksum: 7489e5ae7dbed2eba89855cea21ad32321e8e92bd9f2d3b925e7feec0dd9aa8b4b865296525275938e573a3be9759715490038103cbc970570a1c48c4f2fd23d + languageName: node + linkType: hard + +"detective-sass@npm:^4.0.1, detective-sass@npm:^4.1.1": + version: 4.1.3 + resolution: "detective-sass@npm:4.1.3" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 91681e90037cc935f38b2867fab2aa5585848491b3a269dfb44b37721146ff83f57a540d964b15db22dc1f232623568bedfd13470ec7363e6111991d4d3fe573 + languageName: node + linkType: hard + +"detective-scss@npm:^2.0.1": + version: 2.0.2 + resolution: "detective-scss@npm:2.0.2" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^4.0.0 + checksum: 515ff1b8946ec92baead48ef435efe1ea0f33ee1d98a7537dd700f1d06dd192f9ea0971c10343adcb08b561ab296d01c18a1f62d0b63163a8f4c09885a956e1a + languageName: node + linkType: hard + +"detective-scss@npm:^3.0.0, detective-scss@npm:^3.0.1": + version: 3.1.1 + resolution: "detective-scss@npm:3.1.1" + dependencies: + gonzales-pe: ^4.3.0 + node-source-walk: ^5.0.1 + checksum: 3d9c0468216c822c25572e700b9aba1e2e2797d336b6b84fd455d83ce849263324855008d1e58d6ccdf9c7a4f099e31277b99e885407cd19674e0bb10fc458cd + languageName: node + linkType: hard + +"detective-stylus@npm:^1.0.0": + version: 1.0.3 + resolution: "detective-stylus@npm:1.0.3" + checksum: 2723da93545f3a55a2a7eaa76b50712457af3c93c2b003e95d02f4c240d5e5206a5df99209a4f5b54128c11fc4270c2de1d7316b4f7d02b359483ae74f5a6637 + languageName: node + linkType: hard + +"detective-stylus@npm:^2.0.1": + version: 2.0.1 + resolution: "detective-stylus@npm:2.0.1" + checksum: c701ba6df3e6b5346aa5dd37b8329a9069a20fd7d075933e2e3b819a75922a2adab809143591151e7337183d59c980e6bc64ad6e51ce96de864575221c1b9506 + languageName: node + linkType: hard + +"detective-stylus@npm:^3.0.0": + version: 3.0.0 + resolution: "detective-stylus@npm:3.0.0" + checksum: e82eda490406d289f7b22050423ad69eb1c0f0d88414adaa292de4ab533be3c50d4cf512a9fefba426f3ad20789f0c0db3b0d32f70162112ca89034bbc5ca9d3 + languageName: node + linkType: hard + +"detective-typescript@npm:^7.0.0": + version: 7.0.2 + resolution: "detective-typescript@npm:7.0.2" + dependencies: + "@typescript-eslint/typescript-estree": ^4.33.0 + ast-module-types: ^2.7.1 + node-source-walk: ^4.2.0 + typescript: ^3.9.10 + checksum: 77703410baa242029dc5e7d02cca7a26278dea498ec1c3320f92efa08a85263affc3b102fc2b09952ece1d2c851a3808733d7bfa9ed11944a7c0f39920e33ec9 + languageName: node + linkType: hard + +"detective-typescript@npm:^9.0.0, detective-typescript@npm:^9.1.1": + version: 9.1.1 + resolution: "detective-typescript@npm:9.1.1" + dependencies: + "@typescript-eslint/typescript-estree": ^5.55.0 + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + typescript: ^4.9.5 + checksum: 5f50801f622740d4e9d724ce04518ceb81591215bf18c18c5d22f6f3948df49dfb0a8bbe3596dac47220a37028bc2879ccd7a968f265217c9855817bda4622f5 + languageName: node + linkType: hard + "devtools-protocol@npm:0.0.1179426": version: 0.0.1179426 resolution: "devtools-protocol@npm:0.0.1179426" @@ -9059,7 +9477,7 @@ __metadata: languageName: node linkType: hard -"elliptic@npm:6.5.4, elliptic@npm:^6.5.3": +"elliptic@npm:6.5.4, elliptic@npm:^6.5.3, elliptic@npm:^6.5.4": version: 6.5.4 resolution: "elliptic@npm:6.5.4" dependencies: @@ -9141,7 +9559,7 @@ __metadata: languageName: node linkType: hard -"enhanced-resolve@npm:^5.0.0, enhanced-resolve@npm:^5.12.0, enhanced-resolve@npm:^5.15.0": +"enhanced-resolve@npm:^5.0.0, enhanced-resolve@npm:^5.12.0, enhanced-resolve@npm:^5.15.0, enhanced-resolve@npm:^5.8.3": version: 5.15.0 resolution: "enhanced-resolve@npm:5.15.0" dependencies: @@ -9420,7 +9838,7 @@ __metadata: languageName: node linkType: hard -"escodegen@npm:^2.1.0": +"escodegen@npm:^2.0.0, escodegen@npm:^2.1.0": version: 2.1.0 resolution: "escodegen@npm:2.1.0" dependencies: @@ -9591,6 +10009,13 @@ __metadata: languageName: node linkType: hard +"eslint-visitor-keys@npm:^2.0.0": + version: 2.1.0 + resolution: "eslint-visitor-keys@npm:2.1.0" + checksum: e3081d7dd2611a35f0388bbdc2f5da60b3a3c5b8b6e928daffff7391146b434d691577aa95064c8b7faad0b8a680266bcda0a42439c18c717b80e6718d7e267d + languageName: node + linkType: hard + "eslint-visitor-keys@npm:^3.3.0, eslint-visitor-keys@npm:^3.4.1, eslint-visitor-keys@npm:^3.4.2": version: 3.4.2 resolution: "eslint-visitor-keys@npm:3.4.2" @@ -10151,6 +10576,29 @@ __metadata: languageName: node linkType: hard +"filing-cabinet@npm:^3.0.1": + version: 3.3.1 + resolution: "filing-cabinet@npm:3.3.1" + dependencies: + app-module-path: ^2.2.0 + commander: ^2.20.3 + debug: ^4.3.3 + enhanced-resolve: ^5.8.3 + is-relative-path: ^1.0.2 + module-definition: ^3.3.1 + module-lookup-amd: ^7.0.1 + resolve: ^1.21.0 + resolve-dependency-path: ^2.0.0 + sass-lookup: ^3.0.0 + stylus-lookup: ^3.0.1 + tsconfig-paths: ^3.10.1 + typescript: ^3.9.7 + bin: + filing-cabinet: bin/cli.js + checksum: f6511c2e93e236c0d882244b49936a2c8cb2fde47e0d1a0a93345ce171995c2734670c38ed1c0aceaee9ed4958fcce48bfbbb687efe4dedf04b6ea46b0a8c1c0 + languageName: node + linkType: hard + "fill-range@npm:^7.0.1": version: 7.0.1 resolution: "fill-range@npm:7.0.1" @@ -10237,6 +10685,13 @@ __metadata: languageName: node linkType: hard +"flatten@npm:^1.0.2": + version: 1.0.3 + resolution: "flatten@npm:1.0.3" + checksum: 5c57379816f1692aaa79fbc6390e0a0644e5e8442c5783ed57c6d315468eddbc53a659eaa03c9bb1e771b0f4a9bd8dd8a2620286bf21fd6538a7857321fdfb20 + languageName: node + linkType: hard + "fn.name@npm:1.x.x": version: 1.1.0 resolution: "fn.name@npm:1.1.0" @@ -10437,6 +10892,13 @@ __metadata: languageName: node linkType: hard +"function-bind@npm:^1.1.2": + version: 1.1.2 + resolution: "function-bind@npm:1.1.2" + checksum: 2b0ff4ce708d99715ad14a6d1f894e2a83242e4a52ccfcefaee5e40050562e5f6dafc1adbb4ce2d4ab47279a45dc736ab91ea5042d843c3c092820dfe032efb1 + languageName: node + linkType: hard + "function.prototype.name@npm:^1.1.5": version: 1.1.5 resolution: "function.prototype.name@npm:1.1.5" @@ -10495,6 +10957,26 @@ __metadata: languageName: node linkType: hard +"get-amd-module-type@npm:^3.0.0": + version: 3.0.2 + resolution: "get-amd-module-type@npm:3.0.2" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.2.2 + checksum: d16fac5037f63027992e6ebd2d642e6d4feef2f8fa71ff3da6aa76006e05b3dcd4aa6044b4c5966f13ba5d412fd7c1367d910df86b58f9c13f53cbb35d2e4b72 + languageName: node + linkType: hard + +"get-amd-module-type@npm:^4.1.0": + version: 4.1.0 + resolution: "get-amd-module-type@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + checksum: dd3f58e88efb6a2224bb38325fe21b1ab417ba105b7f90d49089141b0eb3c24aab1866a2e2bf370430bbfc7ef226fc0a2a5c657e161d1d42d8a243f44ebd4fbe + languageName: node + linkType: hard + "get-caller-file@npm:^2.0.1, get-caller-file@npm:^2.0.5": version: 2.0.5 resolution: "get-caller-file@npm:2.0.5" @@ -10542,6 +11024,13 @@ __metadata: languageName: node linkType: hard +"get-own-enumerable-property-symbols@npm:^3.0.0": + version: 3.0.2 + resolution: "get-own-enumerable-property-symbols@npm:3.0.2" + checksum: 8f0331f14159f939830884799f937343c8c0a2c330506094bc12cbee3665d88337fe97a4ea35c002cc2bdba0f5d9975ad7ec3abb925015cdf2a93e76d4759ede + languageName: node + linkType: hard + "get-package-type@npm:^0.1.0": version: 0.1.0 resolution: "get-package-type@npm:0.1.0" @@ -10672,7 +11161,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.0.0, glob@npm:^7.0.3, glob@npm:^7.1.3, glob@npm:^7.1.4": +"glob@npm:^7.0.0, glob@npm:^7.0.3, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -10738,7 +11227,7 @@ __metadata: languageName: node linkType: hard -"globby@npm:^11.0.1, globby@npm:^11.1.0": +"globby@npm:^11.0.1, globby@npm:^11.0.3, globby@npm:^11.1.0": version: 11.1.0 resolution: "globby@npm:11.1.0" dependencies: @@ -10776,6 +11265,17 @@ __metadata: languageName: node linkType: hard +"gonzales-pe@npm:^4.2.3, gonzales-pe@npm:^4.3.0": + version: 4.3.0 + resolution: "gonzales-pe@npm:4.3.0" + dependencies: + minimist: ^1.2.5 + bin: + gonzales: bin/gonzales.js + checksum: 49d60fc49ad35639e5d55923c1516d3ec2e4de5e6e5913ec3458a479b66623e54a060d568295349b0bb9f96ee970c473ff984d4b82a5cfeaf736c55f0d6dc3b7 + languageName: node + linkType: hard + "gopd@npm:^1.0.1": version: 1.0.1 resolution: "gopd@npm:1.0.1" @@ -10917,6 +11417,15 @@ __metadata: languageName: node linkType: hard +"hasown@npm:^2.0.0": + version: 2.0.0 + resolution: "hasown@npm:2.0.0" + dependencies: + function-bind: ^1.1.2 + checksum: 6151c75ca12554565098641c98a40f4cc86b85b0fd5b6fe92360967e4605a4f9610f7757260b4e8098dd1c2ce7f4b095f2006fe72a570e3b6d2d28de0298c176 + languageName: node + linkType: hard + "he@npm:1.2.0": version: 1.2.0 resolution: "he@npm:1.2.0" @@ -11273,6 +11782,13 @@ __metadata: languageName: node linkType: hard +"indexes-of@npm:^1.0.1": + version: 1.0.1 + resolution: "indexes-of@npm:1.0.1" + checksum: 4f9799b1739a62f3e02d09f6f4162cf9673025282af7fa36e790146e7f4e216dad3e776a25b08536c093209c9fcb5ea7bd04b082d42686a45f58ff401d6da32e + languageName: node + linkType: hard + "infer-owner@npm:^1.0.4": version: 1.0.4 resolution: "infer-owner@npm:1.0.4" @@ -11484,6 +12000,15 @@ __metadata: languageName: node linkType: hard +"is-core-module@npm:^2.13.0": + version: 2.13.1 + resolution: "is-core-module@npm:2.13.1" + dependencies: + hasown: ^2.0.0 + checksum: 256559ee8a9488af90e4bad16f5583c6d59e92f0742e9e8bb4331e758521ee86b810b93bae44f390766ffbc518a0488b18d9dab7da9a5ff997d499efc9403f7c + languageName: node + linkType: hard + "is-core-module@npm:^2.5.0": version: 2.13.0 resolution: "is-core-module@npm:2.13.0" @@ -11584,6 +12109,13 @@ __metadata: languageName: node linkType: hard +"is-interactive@npm:^1.0.0": + version: 1.0.0 + resolution: "is-interactive@npm:1.0.0" + checksum: 824808776e2d468b2916cdd6c16acacebce060d844c35ca6d82267da692e92c3a16fdba624c50b54a63f38bdc4016055b6f443ce57d7147240de4f8cdabaf6f9 + languageName: node + linkType: hard + "is-lambda@npm:^1.0.1": version: 1.0.1 resolution: "is-lambda@npm:1.0.1" @@ -11628,6 +12160,13 @@ __metadata: languageName: node linkType: hard +"is-obj@npm:^1.0.1": + version: 1.0.1 + resolution: "is-obj@npm:1.0.1" + checksum: 3ccf0efdea12951e0b9c784e2b00e77e87b2f8bd30b42a498548a8afcc11b3287342a2030c308e473e93a7a19c9ea7854c99a8832a476591c727df2a9c79796c + languageName: node + linkType: hard + "is-path-inside@npm:^3.0.3": version: 3.0.3 resolution: "is-path-inside@npm:3.0.3" @@ -11682,6 +12221,20 @@ __metadata: languageName: node linkType: hard +"is-regexp@npm:^1.0.0": + version: 1.0.0 + resolution: "is-regexp@npm:1.0.0" + checksum: be692828e24cba479ec33644326fa98959ec68ba77965e0291088c1a741feaea4919d79f8031708f85fd25e39de002b4520622b55460660b9c369e6f7187faef + languageName: node + linkType: hard + +"is-relative-path@npm:^1.0.2": + version: 1.0.2 + resolution: "is-relative-path@npm:1.0.2" + checksum: 6c2ccffd3c0a3e3990535d0571370883d558b825b51940085f3446ec338857f4552f44521dfec3e83b7e067de08c0b0369de290208a91200bcae2c569533e340 + languageName: node + linkType: hard + "is-set@npm:^2.0.1, is-set@npm:^2.0.2": version: 2.0.2 resolution: "is-set@npm:2.0.2" @@ -11753,6 +12306,20 @@ __metadata: languageName: node linkType: hard +"is-url-superb@npm:^4.0.0": + version: 4.0.0 + resolution: "is-url-superb@npm:4.0.0" + checksum: fd55e91c96349acb0d688f95fcb1ac67450e5db934976e3a8ff13ef446841e779a6f4d18b15f02331f05a3429c8fdaba2382ac1ab444059e86e9ffcde1ec8db0 + languageName: node + linkType: hard + +"is-url@npm:^1.2.4": + version: 1.2.4 + resolution: "is-url@npm:1.2.4" + checksum: 100e74b3b1feab87a43ef7653736e88d997eb7bd32e71fd3ebc413e58c1cbe56269699c776aaea84244b0567f2a7d68dfaa512a062293ed2f9fdecb394148432 + languageName: node + linkType: hard + "is-weakmap@npm:^2.0.1": version: 2.0.1 resolution: "is-weakmap@npm:2.0.1" @@ -13871,7 +14438,7 @@ __metadata: languageName: node linkType: hard -"log-symbols@npm:4.1.0": +"log-symbols@npm:4.1.0, log-symbols@npm:^4.1.0": version: 4.1.0 resolution: "log-symbols@npm:4.1.0" dependencies: @@ -13978,6 +14545,43 @@ __metadata: languageName: node linkType: hard +"madge@npm:^6.1.0": + version: 6.1.0 + resolution: "madge@npm:6.1.0" + dependencies: + chalk: ^4.1.1 + commander: ^7.2.0 + commondir: ^1.0.1 + debug: ^4.3.1 + dependency-tree: ^9.0.0 + detective-amd: ^4.0.1 + detective-cjs: ^4.0.0 + detective-es6: ^3.0.0 + detective-less: ^1.0.2 + detective-postcss: ^6.1.0 + detective-sass: ^4.0.1 + detective-scss: ^3.0.0 + detective-stylus: ^2.0.1 + detective-typescript: ^9.0.0 + ora: ^5.4.1 + pluralize: ^8.0.0 + precinct: ^8.1.0 + pretty-ms: ^7.0.1 + rc: ^1.2.7 + stream-to-array: ^2.3.0 + ts-graphviz: ^1.5.0 + walkdir: ^0.4.1 + peerDependencies: + typescript: ^3.9.5 || ^4.9.5 || ^5 + peerDependenciesMeta: + typescript: + optional: true + bin: + madge: bin/cli.js + checksum: cb8a629c1eb837640ca2416dbd2236f1ea8657eb188725ff42294718dd1769ece5ec635ef02c344c72e3b4faab3cd8f084b043ce8ecccf4018915738b3329096 + languageName: node + linkType: hard + "make-dir@npm:^4.0.0": version: 4.0.0 resolution: "make-dir@npm:4.0.0" @@ -14404,7 +15008,7 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.2.0, minimist@npm:^1.2.6": +"minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6": version: 1.2.8 resolution: "minimist@npm:1.2.8" checksum: 75a6d645fb122dad29c06a7597bddea977258957ed88d7a6df59b5cd3fe4a527e253e9bbf2e783e4b73657f9098b96a5fe96ab8a113655d4109108577ecf85b0 @@ -14580,6 +15184,45 @@ __metadata: languageName: node linkType: hard +"module-definition@npm:^3.3.1": + version: 3.4.0 + resolution: "module-definition@npm:3.4.0" + dependencies: + ast-module-types: ^3.0.0 + node-source-walk: ^4.0.0 + bin: + module-definition: bin/cli.js + checksum: 5cbfd38aab1a9169b5c31924e208e430a87a1b1512ab9736a9a368d950e3cc8e2f5cf642e37fe74123e25402cae50bfb8fdf1f5f0fd3d4d9270df705a2360bfa + languageName: node + linkType: hard + +"module-definition@npm:^4.1.0": + version: 4.1.0 + resolution: "module-definition@npm:4.1.0" + dependencies: + ast-module-types: ^4.0.0 + node-source-walk: ^5.0.1 + bin: + module-definition: bin/cli.js + checksum: d9b6397c9ba04b08bc035fd87a3652900530b9a5d6e5263f8a1e05c927dfc103fdffcecd7071a9fd6cd7813fc9feafbbe828f5277e5b706e5de82831153ef0fb + languageName: node + linkType: hard + +"module-lookup-amd@npm:^7.0.1": + version: 7.0.1 + resolution: "module-lookup-amd@npm:7.0.1" + dependencies: + commander: ^2.8.1 + debug: ^4.1.0 + glob: ^7.1.6 + requirejs: ^2.3.5 + requirejs-config-file: ^4.0.0 + bin: + lookup-amd: bin/cli.js + checksum: 911abd6b8fb1d82cfae4ef38050981d4eb7e710bfeba898903c5c49a4d3a44b3cacb6201ddf9930a39fae3473faf9b96d39930cfa8766dbf0da86689108895b1 + languageName: node + linkType: hard + "moment@npm:^2.29.1": version: 2.29.4 resolution: "moment@npm:2.29.4" @@ -14910,6 +15553,24 @@ __metadata: languageName: node linkType: hard +"node-source-walk@npm:^4.0.0, node-source-walk@npm:^4.2.0, node-source-walk@npm:^4.2.2": + version: 4.3.0 + resolution: "node-source-walk@npm:4.3.0" + dependencies: + "@babel/parser": ^7.0.0 + checksum: 124bcec61f73141a5f13e63f773beb00c9a9620e9eec6d7505b9de8fa884797f3eb0b9e9d225bb324930234ae03b28a4a7a231e2c2f23d71405d4a562b404e34 + languageName: node + linkType: hard + +"node-source-walk@npm:^5.0.0, node-source-walk@npm:^5.0.1": + version: 5.0.2 + resolution: "node-source-walk@npm:5.0.2" + dependencies: + "@babel/parser": ^7.21.4 + checksum: 1031bc0871bb77ace33bd09fb1e9ef7589b03e6a2fa441b8e684023102362da6dba77d6b9b086dc1f995c7e69e3517666d5316c3831b9d9ff077cb36d57179e8 + languageName: node + linkType: hard + "nopt@npm:^5.0.0": version: 5.0.0 resolution: "nopt@npm:5.0.0" @@ -15139,7 +15800,7 @@ __metadata: languageName: node linkType: hard -"onetime@npm:^5.1.2": +"onetime@npm:^5.1.0, onetime@npm:^5.1.2": version: 5.1.2 resolution: "onetime@npm:5.1.2" dependencies: @@ -15201,6 +15862,23 @@ __metadata: languageName: node linkType: hard +"ora@npm:^5.4.1": + version: 5.4.1 + resolution: "ora@npm:5.4.1" + dependencies: + bl: ^4.1.0 + chalk: ^4.1.0 + cli-cursor: ^3.1.0 + cli-spinners: ^2.5.0 + is-interactive: ^1.0.0 + is-unicode-supported: ^0.1.0 + log-symbols: ^4.1.0 + strip-ansi: ^6.0.0 + wcwidth: ^1.0.1 + checksum: 28d476ee6c1049d68368c0dc922e7225e3b5600c3ede88fade8052837f9ed342625fdaa84a6209302587c8ddd9b664f71f0759833cbdb3a4cf81344057e63c63 + languageName: node + linkType: hard + "outdent@npm:^0.8.0": version: 0.8.0 resolution: "outdent@npm:0.8.0" @@ -15404,6 +16082,13 @@ __metadata: languageName: node linkType: hard +"parse-ms@npm:^2.1.0": + version: 2.1.0 + resolution: "parse-ms@npm:2.1.0" + checksum: d5c66c76cca8df5bd0574e2d11b9c3752893b59b466e74308d4a2f09760dc5436a1633f549cad300fc8c3c19154d14959a3b8333d3b2f7bd75898fe18149d564 + languageName: node + linkType: hard + "parseurl@npm:^1.3.2, parseurl@npm:~1.3.2, parseurl@npm:~1.3.3": version: 1.3.3 resolution: "parseurl@npm:1.3.3" @@ -15623,6 +16308,13 @@ __metadata: languageName: node linkType: hard +"pluralize@npm:^8.0.0": + version: 8.0.0 + resolution: "pluralize@npm:8.0.0" + checksum: 08931d4a6a4a5561a7f94f67a31c17e6632cb21e459ab3ff4f6f629d9a822984cf8afef2311d2005fbea5d7ef26016ebb090db008e2d8bce39d0a9a9d218736e + languageName: node + linkType: hard + "pngjs@npm:^3.3.0": version: 3.4.0 resolution: "pngjs@npm:3.4.0" @@ -15712,6 +16404,41 @@ __metadata: languageName: node linkType: hard +"postcss-values-parser@npm:^2.0.1": + version: 2.0.1 + resolution: "postcss-values-parser@npm:2.0.1" + dependencies: + flatten: ^1.0.2 + indexes-of: ^1.0.1 + uniq: ^1.0.1 + checksum: 050877880937e15af8d18bf48902e547e2123d7cc32c1f215b392642bc5e2598a87a341995d62f38e450aab4186b8afeb2c9541934806d458ad8b117020b2ebf + languageName: node + linkType: hard + +"postcss-values-parser@npm:^6.0.2": + version: 6.0.2 + resolution: "postcss-values-parser@npm:6.0.2" + dependencies: + color-name: ^1.1.4 + is-url-superb: ^4.0.0 + quote-unquote: ^1.0.0 + peerDependencies: + postcss: ^8.2.9 + checksum: 615fea3d7996b3fae84a8674fb0e7c6bd0bc006beddb126692c2e43112b772625329c5f10121b00d69fe7a24f7f18dd25e24745574556735c4e9671774df0eb1 + languageName: node + linkType: hard + +"postcss@npm:^8.1.7, postcss@npm:^8.4.23": + version: 8.4.31 + resolution: "postcss@npm:8.4.31" + dependencies: + nanoid: ^3.3.6 + picocolors: ^1.0.0 + source-map-js: ^1.0.2 + checksum: 1d8611341b073143ad90486fcdfeab49edd243377b1f51834dc4f6d028e82ce5190e4f11bb2633276864503654fb7cab28e67abdc0fbf9d1f88cad4a0ff0beea + languageName: node + linkType: hard + "postcss@npm:^8.4.21, postcss@npm:^8.4.29": version: 8.4.29 resolution: "postcss@npm:8.4.29" @@ -15748,6 +16475,51 @@ __metadata: languageName: node linkType: hard +"precinct@npm:^8.1.0": + version: 8.3.1 + resolution: "precinct@npm:8.3.1" + dependencies: + commander: ^2.20.3 + debug: ^4.3.3 + detective-amd: ^3.1.0 + detective-cjs: ^3.1.1 + detective-es6: ^2.2.1 + detective-less: ^1.0.2 + detective-postcss: ^4.0.0 + detective-sass: ^3.0.1 + detective-scss: ^2.0.1 + detective-stylus: ^1.0.0 + detective-typescript: ^7.0.0 + module-definition: ^3.3.1 + node-source-walk: ^4.2.0 + bin: + precinct: bin/cli.js + checksum: 16ba57e545fc53481b3a194f9d7843cefd562ce5e847280355eed360ca4c55def4d03d501776fb49fdf79bfe84a03ec6138003d8387c0426f6a68e1931688399 + languageName: node + linkType: hard + +"precinct@npm:^9.0.0": + version: 9.2.1 + resolution: "precinct@npm:9.2.1" + dependencies: + "@dependents/detective-less": ^3.0.1 + commander: ^9.5.0 + detective-amd: ^4.1.0 + detective-cjs: ^4.1.0 + detective-es6: ^3.0.1 + detective-postcss: ^6.1.1 + detective-sass: ^4.1.1 + detective-scss: ^3.0.1 + detective-stylus: ^3.0.0 + detective-typescript: ^9.1.1 + module-definition: ^4.1.0 + node-source-walk: ^5.0.1 + bin: + precinct: bin/cli.js + checksum: 0352553cca8aff0baa04412429bbe3fab278e9e574fd9bcb2b1bb87dc3ed608f3e08b66c86aee90eed6bac5c4091fe78753ae094d54b01a803189d3259817fe7 + languageName: node + linkType: hard + "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -15786,6 +16558,15 @@ __metadata: languageName: node linkType: hard +"pretty-ms@npm:^7.0.1": + version: 7.0.1 + resolution: "pretty-ms@npm:7.0.1" + dependencies: + parse-ms: ^2.1.0 + checksum: d76c4920283b48be91f1d3797a2ce4bd51187d58d2a609ae993c028f73c92d16439449d857af57ccad91ae3a38b30c87307f5589749a056102ebb494c686957e + languageName: node + linkType: hard + "private-ip@npm:^3.0.0": version: 3.0.1 resolution: "private-ip@npm:3.0.1" @@ -16134,6 +16915,13 @@ __metadata: languageName: node linkType: hard +"quote-unquote@npm:^1.0.0": + version: 1.0.0 + resolution: "quote-unquote@npm:1.0.0" + checksum: 955a2ead534f5b6a3f8d4dc5a4b95ac6468213d3fb11f8c1592a0a56345c45a3d14d5ca04d3de2bc9891493fcac38c03dfa91c48a6159aef50124e9c5afcea49 + languageName: node + linkType: hard + "randombytes@npm:^2.0.0, randombytes@npm:^2.0.1, randombytes@npm:^2.0.5, randombytes@npm:^2.1.0": version: 2.1.0 resolution: "randombytes@npm:2.1.0" @@ -16198,7 +16986,7 @@ __metadata: languageName: node linkType: hard -"rc@npm:^1.0.1, rc@npm:^1.1.6": +"rc@npm:^1.0.1, rc@npm:^1.1.6, rc@npm:^1.2.7": version: 1.2.8 resolution: "rc@npm:1.2.8" dependencies: @@ -16518,6 +17306,26 @@ __metadata: languageName: node linkType: hard +"requirejs-config-file@npm:^4.0.0": + version: 4.0.0 + resolution: "requirejs-config-file@npm:4.0.0" + dependencies: + esprima: ^4.0.0 + stringify-object: ^3.2.1 + checksum: 61ac1c419a8978df9484211827047f0a43d48a97e242ebca9628a2e52da8c739ee068bd67dc4d5dc5fd7be6d1c9a863006bb02df691c86914921fe12713fbebb + languageName: node + linkType: hard + +"requirejs@npm:^2.3.5": + version: 2.3.6 + resolution: "requirejs@npm:2.3.6" + bin: + r.js: ./bin/r.js + r_js: ./bin/r.js + checksum: 7c3c006bf5e1887d93ac7adb7f600328918d23cf3d28282a505a2873d4ddde499c7ec560e55cee3440d17fe1205cb4dcb72b07f35b39e8940372eca850e49b62 + languageName: node + linkType: hard + "requires-port@npm:^1.0.0": version: 1.0.0 resolution: "requires-port@npm:1.0.0" @@ -16534,6 +17342,13 @@ __metadata: languageName: node linkType: hard +"resolve-dependency-path@npm:^2.0.0": + version: 2.0.0 + resolution: "resolve-dependency-path@npm:2.0.0" + checksum: 161296969a0a7853ebb7710847154ffb5bd11a51c370b67a0d0c89cacfcb57063d204587617fd030ea227bfd19a3c4af79d39e9d20ae0fbe354c27598d1ea8a8 + languageName: node + linkType: hard + "resolve-from@npm:^4.0.0": version: 4.0.0 resolution: "resolve-from@npm:4.0.0" @@ -16596,6 +17411,19 @@ __metadata: languageName: node linkType: hard +"resolve@npm:^1.21.0": + version: 1.22.8 + resolution: "resolve@npm:1.22.8" + dependencies: + is-core-module: ^2.13.0 + path-parse: ^1.0.7 + supports-preserve-symlinks-flag: ^1.0.0 + bin: + resolve: bin/resolve + checksum: f8a26958aa572c9b064562750b52131a37c29d072478ea32e129063e2da7f83e31f7f11e7087a18225a8561cfe8d2f0df9dbea7c9d331a897571c0a2527dbb4c + languageName: node + linkType: hard + "resolve@npm:~1.19.0": version: 1.19.0 resolution: "resolve@npm:1.19.0" @@ -16619,6 +17447,19 @@ __metadata: languageName: node linkType: hard +"resolve@patch:resolve@^1.21.0#~builtin": + version: 1.22.8 + resolution: "resolve@patch:resolve@npm%3A1.22.8#~builtin::version=1.22.8&hash=c3c19d" + dependencies: + is-core-module: ^2.13.0 + path-parse: ^1.0.7 + supports-preserve-symlinks-flag: ^1.0.0 + bin: + resolve: bin/resolve + checksum: 5479b7d431cacd5185f8db64bfcb7286ae5e31eb299f4c4f404ad8aa6098b77599563ac4257cb2c37a42f59dfc06a1bec2bcf283bb448f319e37f0feb9a09847 + languageName: node + linkType: hard + "resolve@patch:resolve@~1.19.0#~builtin": version: 1.19.0 resolution: "resolve@patch:resolve@npm%3A1.19.0#~builtin::version=1.19.0&hash=c3c19d" @@ -16629,6 +17470,16 @@ __metadata: languageName: node linkType: hard +"restore-cursor@npm:^3.1.0": + version: 3.1.0 + resolution: "restore-cursor@npm:3.1.0" + dependencies: + onetime: ^5.1.0 + signal-exit: ^3.0.2 + checksum: f877dd8741796b909f2a82454ec111afb84eb45890eb49ac947d87991379406b3b83ff9673a46012fca0d7844bb989f45cc5b788254cf1a39b6b5a9659de0630 + languageName: node + linkType: hard + "retry@npm:^0.12.0": version: 0.12.0 resolution: "retry@npm:0.12.0" @@ -16845,6 +17696,17 @@ __metadata: languageName: node linkType: hard +"sass-lookup@npm:^3.0.0": + version: 3.0.0 + resolution: "sass-lookup@npm:3.0.0" + dependencies: + commander: ^2.16.0 + bin: + sass-lookup: bin/cli.js + checksum: fd4bf1ad9c54111617dec30dd90aff083e87c96aef50aff6cec443ad2fbbfa65da09f6e67a7e5ef99fa39dff65c937dc7358f18d319e083c6031f21def85ce6d + languageName: node + linkType: hard + "sass@npm:^1.58.0": version: 1.67.0 resolution: "sass@npm:1.67.0" @@ -16967,7 +17829,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": +"semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": version: 7.5.4 resolution: "semver@npm:7.5.4" dependencies: @@ -17195,7 +18057,7 @@ __metadata: languageName: node linkType: hard -"signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7": +"signal-exit@npm:^3.0.2, signal-exit@npm:^3.0.3, signal-exit@npm:^3.0.7": version: 3.0.7 resolution: "signal-exit@npm:3.0.7" checksum: a2f098f247adc367dffc27845853e9959b9e88b01cb301658cfe4194352d8d2bb32e18467c786a7fe15f1d44b233ea35633d076d5e737870b7139949d1ab6318 @@ -17556,6 +18418,15 @@ __metadata: languageName: node linkType: hard +"stream-to-array@npm:^2.3.0": + version: 2.3.0 + resolution: "stream-to-array@npm:2.3.0" + dependencies: + any-promise: ^1.1.0 + checksum: 7feaf63b38399b850615e6ffcaa951e96e4c8f46745dbce4b553a94c5dc43966933813747014935a3ff97793e7f30a65270bde19f82b2932871a1879229a77cf + languageName: node + linkType: hard + "stream-to-it@npm:^0.2.2": version: 0.2.4 resolution: "stream-to-it@npm:0.2.4" @@ -17690,6 +18561,17 @@ __metadata: languageName: node linkType: hard +"stringify-object@npm:^3.2.1": + version: 3.3.0 + resolution: "stringify-object@npm:3.3.0" + dependencies: + get-own-enumerable-property-symbols: ^3.0.0 + is-obj: ^1.0.1 + is-regexp: ^1.0.0 + checksum: 6827a3f35975cfa8572e8cd3ed4f7b262def260af18655c6fde549334acdac49ddba69f3c861ea5a6e9c5a4990fe4ae870b9c0e6c31019430504c94a83b7a154 + languageName: node + linkType: hard + "strip-ansi-cjs@npm:strip-ansi@^6.0.1, strip-ansi@npm:^6.0.0, strip-ansi@npm:^6.0.1": version: 6.0.1 resolution: "strip-ansi@npm:6.0.1" @@ -17777,6 +18659,18 @@ __metadata: languageName: node linkType: hard +"stylus-lookup@npm:^3.0.1": + version: 3.0.2 + resolution: "stylus-lookup@npm:3.0.2" + dependencies: + commander: ^2.8.1 + debug: ^4.1.0 + bin: + stylus-lookup: bin/cli.js + checksum: 460e9b6e7e662e2cf98d41ee670cb5da9ec8b8dbc1d4574de29ac422c632d5c7933772822fc12792f2ee9f9c2f62b3f60ed5850690e7c780ab7b6f07010199e4 + languageName: node + linkType: hard + "superagent@npm:^8.0.5": version: 8.0.9 resolution: "superagent@npm:8.0.9" @@ -18208,6 +19102,13 @@ __metadata: languageName: node linkType: hard +"ts-graphviz@npm:^1.5.0": + version: 1.8.1 + resolution: "ts-graphviz@npm:1.8.1" + checksum: c560fc3a70fc7743bb1cacd21fdeb68661e78132cad4c0cb53c071d2485b1e5975350f0a754c2a797912e9d9022dc375b47e6b023a2eafe4b824c0bb9b7d58ed + languageName: node + linkType: hard + "ts-jest@npm:29.1.1": version: 29.1.1 resolution: "ts-jest@npm:29.1.1" @@ -18343,7 +19244,7 @@ __metadata: languageName: node linkType: hard -"tsconfig-paths@npm:^3.14.2": +"tsconfig-paths@npm:^3.10.1, tsconfig-paths@npm:^3.14.2": version: 3.14.2 resolution: "tsconfig-paths@npm:3.14.2" dependencies: @@ -18355,7 +19256,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:1.14.1, tslib@npm:^1.9.0": +"tslib@npm:1.14.1, tslib@npm:^1.8.1, tslib@npm:^1.9.0": version: 1.14.1 resolution: "tslib@npm:1.14.1" checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd @@ -18390,6 +19291,17 @@ __metadata: languageName: node linkType: hard +"tsutils@npm:^3.21.0": + version: 3.21.0 + resolution: "tsutils@npm:3.21.0" + dependencies: + tslib: ^1.8.1 + peerDependencies: + typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 + languageName: node + linkType: hard + "tty-browserify@npm:^0.0.1": version: 0.0.1 resolution: "tty-browserify@npm:0.0.1" @@ -18544,6 +19456,26 @@ __metadata: languageName: node linkType: hard +"typescript@npm:^3.9.10, typescript@npm:^3.9.7": + version: 3.9.10 + resolution: "typescript@npm:3.9.10" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92 + languageName: node + linkType: hard + +"typescript@npm:^4.0.0, typescript@npm:^4.9.5": + version: 4.9.5 + resolution: "typescript@npm:4.9.5" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db + languageName: node + linkType: hard + "typescript@npm:^5.0.4": version: 5.1.6 resolution: "typescript@npm:5.1.6" @@ -18554,6 +19486,26 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@^3.9.10#~builtin, typescript@patch:typescript@^3.9.7#~builtin": + version: 3.9.10 + resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin::version=3.9.10&hash=3bd3d3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2 + languageName: node + linkType: hard + +"typescript@patch:typescript@^4.0.0#~builtin, typescript@patch:typescript@^4.9.5#~builtin": + version: 4.9.5 + resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=289587" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68 + languageName: node + linkType: hard + "typescript@patch:typescript@^5.0.4#~builtin": version: 5.1.6 resolution: "typescript@patch:typescript@npm%3A5.1.6#~builtin::version=5.1.6&hash=5da071" @@ -18662,6 +19614,13 @@ __metadata: languageName: node linkType: hard +"uniq@npm:^1.0.1": + version: 1.0.1 + resolution: "uniq@npm:1.0.1" + checksum: 8206535f83745ea83f9da7035f3b983fd6ed5e35b8ed7745441944e4065b616bc67cf0d0a23a86b40ee0074426f0607f0a138f9b78e124eb6a7a6a6966055709 + languageName: node + linkType: hard + "unique-filename@npm:^1.1.1": version: 1.1.1 resolution: "unique-filename@npm:1.1.1" @@ -19076,6 +20035,13 @@ __metadata: languageName: node linkType: hard +"walkdir@npm:^0.4.1": + version: 0.4.1 + resolution: "walkdir@npm:0.4.1" + checksum: 71045c21dc19aae3321f897b6e9e507cf8039202665c35a0b908eecccaf25636aab769b31cbd61ef8267237fe22fc316923a691ecc2d9d38840a15c59c0f2594 + languageName: node + linkType: hard + "walker@npm:^1.0.8": version: 1.0.8 resolution: "walker@npm:1.0.8" @@ -19104,6 +20070,15 @@ __metadata: languageName: node linkType: hard +"wcwidth@npm:^1.0.1": + version: 1.0.1 + resolution: "wcwidth@npm:1.0.1" + dependencies: + defaults: ^1.0.3 + checksum: 814e9d1ddcc9798f7377ffa448a5a3892232b9275ebb30a41b529607691c0491de47cba426e917a4d08ded3ee7e9ba2f3fe32e62ee3cd9c7d3bafb7754bd553c + languageName: node + linkType: hard + "web-streams-polyfill@npm:^3.0.3": version: 3.2.1 resolution: "web-streams-polyfill@npm:3.2.1"