-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: Replace computing hashes in circuits wasm, with computing the…
…m 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. #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?
- Loading branch information
1 parent
1c71a0c
commit 87eeb71
Showing
147 changed files
with
3,559 additions
and
1,656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...nberg/cpp/src/barretenberg/common/mem.cpp → .../cpp/src/barretenberg/common/bbmalloc.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
#include "./wasm_export.hpp" | ||
#include <cstddef> | ||
|
||
WASM_EXPORT void* bbmalloc(size_t size); | ||
|
||
WASM_EXPORT void bbfree(void* ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
18 changes: 0 additions & 18 deletions
18
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.hpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind_new.cpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.