Skip to content

Commit a9a029e

Browse files
suyash67dbanks12iAmMichaelConnordbanks12spalladino
authored
Aztec3 Specific Work in Barretenberg (AztecProtocol/barretenberg#142)
* Split Pedersen Hash & Commitment Gadgets (AztecProtocol/barretenberg#95) * [SQUASHED] Pedersen refactor into hash and commitment. Use lookup pedersen for merkle tree, fixed-base pedersen for commitments. --------- Co-authored-by: Suyash Bagad <[email protected]> Port `copy_as_new_witness`. Port `must_imply`. `operator++`. Port changes from `common`. Port `ecc/groups`. * [CPM] add missing dependencies to libbarretenberg.a (AztecProtocol/barretenberg#154) --------- * Increase Pedersen Generator indices and subindices. (AztecProtocol/barretenberg#169) * Remove a3 specific types. (AztecProtocol/barretenberg#252) * Address Luke's Comments on `aztec3 -> master` (AztecProtocol/barretenberg#263) * Add must_imply tests. * Added a test for `field_t::copy_as_new_witness` * add test for `conditional_assign` * Added `infinity` test. * Add `add_affine_test`. * Tests for Array Object in `stdlib` (AztecProtocol/barretenberg#262) * basic array tests. * Add `composer_type` while hashing/compressing a vkey. * Add `contains_recursive_proof` to Recursive VK (AztecProtocol/barretenberg#268) * feat: debug utility for serialization (AztecProtocol/barretenberg#290) * feat: enable asan config * `array_push` for Generic Type (AztecProtocol/barretenberg#291) * Add Indexed Merkle Tree (AztecProtocol/barretenberg#281) * remove ts (consulted with Adam and we're good to go). (AztecProtocol/barretenberg#292) * Add cout for verification_key struct (AztecProtocol/barretenberg#295) * compute tree (AztecProtocol/barretenberg#298) * [SQUASHED] fixing `push_array_to_array` method. (AztecProtocol/barretenberg#304) * feat(memory_tree|a3): add sibling path calculations (AztecProtocol/barretenberg#301) * feat(memory_tree): frontier paths * fix array and resolve merge conflicts (AztecProtocol/barretenberg#305) * Mc/hash vk (AztecProtocol/barretenberg#306) * Increase number of sub-generators to 128. * Build a3crypto.wasm (AztecProtocol/barretenberg#311) * More Tests on A3 `stdlib` methods (AztecProtocol/barretenberg#316) * test: more vk tests to compare circuit/native/vk_data (AztecProtocol/barretenberg#310) * Mc/hash vk (AztecProtocol/barretenberg#306) * inc num_generators_per_hash_index to 128. (AztecProtocol/barretenberg#309) * fix. (AztecProtocol/barretenberg#318) * Added test for `compute_tree_native`. (AztecProtocol/barretenberg#319) * Install instructions for apt on ubuntu (AztecProtocol/barretenberg#312) * Fix address compilation. (AztecProtocol/barretenberg#329) --------- Co-authored-by: David Banks <[email protected]> Co-authored-by: Michael Connor <[email protected]> Co-authored-by: dbanks12 <[email protected]> Co-authored-by: Santiago Palladino <[email protected]> Co-authored-by: ludamad <[email protected]> Co-authored-by: Maddiaa <[email protected]> Co-authored-by: Santiago Palladino <[email protected]> Co-authored-by: ludamad <[email protected]> Co-authored-by: cheethas <[email protected]>
1 parent 0d77d3f commit a9a029e

File tree

182 files changed

+5225
-1381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+5225
-1381
lines changed

barretenberg/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,32 @@
1111
- libomp (if multithreading is required. Multithreading can be disabled using the compiler flag `-DMULTITHREADING 0`)
1212
- wasm-opt (part of the [Binaryen](https://github.com/WebAssembly/binaryen) toolkit)
1313

14+
To install on Ubuntu, run:
15+
```
16+
sudo apt-get install cmake clang clang-format ninja-build binaryen
17+
```
18+
1419
### Installing openMP (Linux)
1520

21+
Install from source:
22+
1623
```
17-
RUN git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \
24+
git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \
1825
&& cd llvm-project && mkdir build-openmp && cd build-openmp \
1926
&& cmake ../openmp -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMP_ENABLE_SHARED=OFF \
2027
&& cmake --build . --parallel \
2128
&& cmake --build . --parallel --target install \
2229
&& cd ../.. && rm -rf llvm-project
2330
```
2431

32+
Or install from a package manager, on Ubuntu:
33+
34+
```
35+
sudo apt-get install libomp-dev
36+
```
37+
38+
> Note: on a fresh Ubuntu Kinetic installation, installing OpenMP from source yields a `Could NOT find OpenMP_C (missing: OpenMP_omp_LIBRARY) (found version "5.0")` error when trying to build Barretenberg. Installing from apt worked fine.
39+
2540
### Getting started
2641

2742
Run the bootstrap script. (The bootstrap script will build both the native and wasm versions of barretenberg)

barretenberg/cpp/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ option(BENCHMARKS "Build benchmarks" ON)
1818
option(FUZZING "Build fuzzing harnesses" OFF)
1919
option(DISABLE_TBB "Intel Thread Building Blocks" ON)
2020
option(COVERAGE "Enable collecting coverage from tests" OFF)
21+
option(SERIALIZE_CANARY "Build with serialize canary" OFF)
22+
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
2123
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
2224
option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON)
2325
option(USE_TURBO "Enable the use of TurboPlonk in barretenberg." OFF)
@@ -39,6 +41,15 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "a
3941
set(DISABLE_TBB 0)
4042
endif()
4143

44+
if(ENABLE_ASAN)
45+
add_compile_options(-fsanitize=address)
46+
add_link_options(-fsanitize=address)
47+
endif()
48+
49+
if(SERIALIZE_CANARY)
50+
add_definitions(-DENABLE_SERIALIZE_CANARY)
51+
endif()
52+
4253
if(FUZZING)
4354
add_definitions(-DFUZZING=1)
4455

barretenberg/cpp/dockerfiles/Dockerfile.wasm-linux-clang

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ WORKDIR /usr/src/barretenberg/cpp/src
55
RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv -
66
WORKDIR /usr/src/barretenberg/cpp
77
COPY . .
8-
# Build both honk_tests barretenberg.wasm
8+
# Build both honk_tests barretenberg.wasm primitives.wasm
99
# This ensures that we aren't using features that would be incompatible with WASM for Honk
10-
RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm
10+
RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target primitives.wasm
1111

1212
FROM alpine:3.17
1313
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm
14+
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/primitives.wasm /usr/src/barretenberg/cpp/build/bin/primitives.wasm
1415
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/

barretenberg/cpp/scripts/bb-tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ crypto_aes128_tests
22
crypto_blake2s_tests
33
crypto_blake3s_tests
44
crypto_ecdsa_tests
5-
crypto_pedersen_tests
5+
crypto_pedersen_commitment_tests
66
crypto_schnorr_tests
77
crypto_sha256_tests
88
ecc_tests
@@ -18,7 +18,7 @@ stdlib_blake2s_tests
1818
stdlib_blake3s_tests
1919
stdlib_ecdsa_tests
2020
stdlib_merkle_tree_tests
21-
stdlib_pedersen_tests
21+
stdlib_pedersen_commitment_tests
2222
stdlib_schnorr_tests
2323
stdlib_sha256_tests
2424
transcript_tests

barretenberg/cpp/src/CMakeLists.txt

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,28 @@ if(WASM)
7676
$<TARGET_OBJECTS:crypto_blake3s_objects>
7777
$<TARGET_OBJECTS:crypto_keccak_objects>
7878
$<TARGET_OBJECTS:crypto_schnorr_objects>
79-
$<TARGET_OBJECTS:crypto_pedersen_objects>
79+
$<TARGET_OBJECTS:crypto_generators_objects>
80+
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
81+
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
8082
$<TARGET_OBJECTS:ecc_objects>
8183
$<TARGET_OBJECTS:polynomials_objects>
8284
$<TARGET_OBJECTS:plonk_objects>
8385
$<TARGET_OBJECTS:honk_objects>
8486
$<TARGET_OBJECTS:proof_system_objects>
8587
$<TARGET_OBJECTS:stdlib_primitives_objects>
8688
$<TARGET_OBJECTS:stdlib_schnorr_objects>
87-
$<TARGET_OBJECTS:stdlib_pedersen_objects>
89+
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
90+
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
8891
$<TARGET_OBJECTS:stdlib_blake2s_objects>
8992
$<TARGET_OBJECTS:stdlib_blake3s_objects>
9093
$<TARGET_OBJECTS:stdlib_sha256_objects>
9194
$<TARGET_OBJECTS:stdlib_aes128_objects>
9295
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
9396
$<TARGET_OBJECTS:acir_format_objects>
9497
$<TARGET_OBJECTS:acir_proofs_objects>
98+
$<TARGET_OBJECTS:stdlib_sha256_objects>
99+
$<TARGET_OBJECTS:stdlib_aes128_objects>
100+
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
95101
)
96102

97103
# With binaryen installed, it seems its wasm backend optimiser gets invoked automatically.
@@ -105,12 +111,35 @@ if(WASM)
105111
-nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
106112
)
107113

114+
# Repeat the above but for the smaller primitives.wasm
115+
# Used in packages where we don't need the full contents of barretenberg
116+
add_executable(
117+
primitives.wasm
118+
$<TARGET_OBJECTS:srs_objects>
119+
$<TARGET_OBJECTS:numeric_objects>
120+
$<TARGET_OBJECTS:crypto_sha256_objects>
121+
$<TARGET_OBJECTS:crypto_aes128_objects>
122+
$<TARGET_OBJECTS:crypto_blake2s_objects>
123+
$<TARGET_OBJECTS:crypto_blake3s_objects>
124+
$<TARGET_OBJECTS:crypto_generators_objects>
125+
$<TARGET_OBJECTS:crypto_keccak_objects>
126+
$<TARGET_OBJECTS:crypto_schnorr_objects>
127+
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
128+
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
129+
$<TARGET_OBJECTS:ecc_objects>
130+
)
131+
132+
target_link_options(
133+
primitives.wasm
134+
PRIVATE
135+
-nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
136+
)
137+
108138
# TODO(blaine): Figure out how to Asyncify the wasm output.
109139
# Binaryen's Asyncify transform produces wasm that has too many local variables to run in a WebAssembly
110140
# instance. This likely would be "solved" by enabling the optimizations to reduce the number of locals,
111141
# but using any optimization level results in a wasm file that takes an unusable amount of time to solve the
112142
# most simple prood.
113-
114143
# find_program(WASM_OPT wasm-opt)
115144

116145
# if(NOT WASM_OPT)
@@ -124,6 +153,13 @@ if(WASM)
124153
# VERBATIM
125154
# )
126155

156+
add_custom_command(
157+
TARGET primitives.wasm
158+
POST_BUILD
159+
COMMAND wasm-opt "$<TARGET_FILE:primitives.wasm>" -O2 -o "$<TARGET_FILE:primitives.wasm>"
160+
VERBATIM
161+
)
162+
127163
if(INSTALL_BARRETENBERG)
128164
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
129165
endif()
@@ -142,15 +178,18 @@ if(WASM)
142178
$<TARGET_OBJECTS:crypto_blake3s_objects>
143179
$<TARGET_OBJECTS:crypto_keccak_objects>
144180
$<TARGET_OBJECTS:crypto_schnorr_objects>
145-
$<TARGET_OBJECTS:crypto_pedersen_objects>
181+
$<TARGET_OBJECTS:crypto_generators_objects>
182+
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
183+
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
146184
$<TARGET_OBJECTS:ecc_objects>
147185
$<TARGET_OBJECTS:polynomials_objects>
148186
$<TARGET_OBJECTS:plonk_objects>
149187
$<TARGET_OBJECTS:honk_objects>
150188
$<TARGET_OBJECTS:proof_system_objects>
151189
$<TARGET_OBJECTS:stdlib_primitives_objects>
152190
$<TARGET_OBJECTS:stdlib_schnorr_objects>
153-
$<TARGET_OBJECTS:stdlib_pedersen_objects>
191+
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
192+
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
154193
$<TARGET_OBJECTS:stdlib_blake2s_objects>
155194
$<TARGET_OBJECTS:stdlib_blake3s_objects>
156195
$<TARGET_OBJECTS:stdlib_sha256_objects>
@@ -174,15 +213,18 @@ else()
174213
$<TARGET_OBJECTS:crypto_blake3s_objects>
175214
$<TARGET_OBJECTS:crypto_keccak_objects>
176215
$<TARGET_OBJECTS:crypto_schnorr_objects>
177-
$<TARGET_OBJECTS:crypto_pedersen_objects>
216+
$<TARGET_OBJECTS:crypto_generators_objects>
217+
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
218+
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
178219
$<TARGET_OBJECTS:ecc_objects>
179220
$<TARGET_OBJECTS:polynomials_objects>
180221
$<TARGET_OBJECTS:plonk_objects>
181222
$<TARGET_OBJECTS:honk_objects>
182223
$<TARGET_OBJECTS:proof_system_objects>
183224
$<TARGET_OBJECTS:stdlib_primitives_objects>
184225
$<TARGET_OBJECTS:stdlib_schnorr_objects>
185-
$<TARGET_OBJECTS:stdlib_pedersen_objects>
226+
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
227+
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
186228
$<TARGET_OBJECTS:stdlib_blake2s_objects>
187229
$<TARGET_OBJECTS:stdlib_blake3s_objects>
188230
$<TARGET_OBJECTS:stdlib_sha256_objects>

barretenberg/cpp/src/barretenberg/common/container.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,16 @@ InnerCont flatten(Cont<InnerCont, Args...> const& in)
4848
result.insert(result.end(), e.begin(), e.end());
4949
}
5050
return result;
51+
}
52+
53+
// Return the first index at which a given item can be found in the vector.
54+
// Only safe for vectors with length less than the size_t overflow size.
55+
template <typename T> long index_of(std::vector<T> const& vec, T const& item)
56+
{
57+
auto const& begin = vec.begin();
58+
auto const& end = vec.end();
59+
60+
auto const& itr = std::find(begin, end, item);
61+
62+
return itr == end ? -1 : std::distance(begin, itr);
5163
}

barretenberg/cpp/src/barretenberg/common/map.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ template <template <typename, typename...> typename Cont,
1010
typename... Args,
1111
typename F,
1212
typename OutElem = typename std::invoke_result<F, InElem const&>::type>
13-
Cont<OutElem> map(Cont<InElem, Args...> const& in, F op)
13+
Cont<OutElem> map(Cont<InElem, Args...> const& in, F&& op)
1414
{
1515
Cont<OutElem> result;
1616
std::transform(in.begin(), in.end(), std::back_inserter(result), op);
1717
return result;
1818
}
1919

20+
/*
21+
* Generic map function for mapping a std::array's elements to another type.
22+
* TODO: this has only been added because I (Mike) couldn't get the above to work
23+
* with an array.
24+
*/
25+
template <std::size_t SIZE,
26+
typename InElem,
27+
typename F,
28+
typename OutElem = typename std::invoke_result<F, InElem const&>::type>
29+
std::array<OutElem, SIZE> map(std::array<InElem, SIZE> const& in, F&& op)
30+
{
31+
std::array<OutElem, SIZE> result;
32+
std::transform(in.begin(), in.end(), result.begin(), op);
33+
return result;
34+
}
35+
2036
/*
2137
* Generic map function for mapping a containers element to another type.
2238
* This version passes the element index as a second argument to the operator function.

0 commit comments

Comments
 (0)