Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aztec3 Specific Work in Barretenberg #142

Merged
merged 46 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
398190c
Split Pedersen Hash & Commitment Gadgets (#95)
dbanks12 Feb 13, 2023
0b29ecc
Changes in stdlib necessary for aztec3.
suyash67 Feb 14, 2023
ade1a3c
need <optional> include in streams.hpp
dbanks12 Feb 15, 2023
8964062
[CPM] add missing dependencies to libbarretenberg.a (#154)
dbanks12 Feb 16, 2023
6783f5f
add missing to_nt converts (#167)
iAmMichaelConnor Feb 20, 2023
78e0de4
Increase Pedersen Generator indices and subindices. (#169)
suyash67 Feb 20, 2023
d1caa69
Switch to Turbo Temporarily. (#174)
suyash67 Feb 22, 2023
f5e48a6
`waffle`->`plonk` in rebase fixes.
suyash67 Feb 27, 2023
e2a5c67
Add ecdsa signature in types. (#193)
suyash67 Mar 2, 2023
91afe2a
Rebase fixes.
suyash67 Mar 13, 2023
d7c5c67
Switch to turbo for dsl to work.
suyash67 Mar 13, 2023
eec7c9a
Remove a3 specific types. (#252)
suyash67 Mar 20, 2023
bea224c
Native workalike to `compute_tree_root` in `plonk::stlib::merkle_tree…
dbanks12 Mar 21, 2023
b93e447
Address Luke's Comments on `aztec3 -> master` (#263)
suyash67 Mar 23, 2023
d3445b0
Tests for Array Object in `stdlib` (#262)
suyash67 Mar 23, 2023
0b7b72a
Pedersen compression of vk data (#259)
dbanks12 Mar 23, 2023
4e14e43
Add `contains_recursive_proof` to Recursive VK (#268)
suyash67 Mar 25, 2023
4816f81
`recursion_output` -> `aggregation_state` (#257)
suyash67 Mar 27, 2023
fd79c25
proof serialisation. (#269)
suyash67 Mar 27, 2023
4b0c08c
Read native vk. (#270)
suyash67 Mar 27, 2023
2877bf5
Fix proof.write method (#273)
spalladino Mar 27, 2023
85d9aa4
fix: broken wasm constants (#278)
ludamad Mar 27, 2023
d886b7a
Fix serialization native agg state (#283) (#284)
Maddiaa0 Mar 28, 2023
6e5b9b5
feat: debug utility for serialization (#290)
ludamad Mar 29, 2023
b96aa88
feat: enable asan config
ludamad Mar 29, 2023
b582036
`array_push` for Generic Type (#291)
suyash67 Mar 29, 2023
ec4f571
Add Indexed Merkle Tree (#281)
suyash67 Mar 29, 2023
0844204
remove ts (consulted with Adam and we're good to go). (#292)
suyash67 Mar 29, 2023
98a0d80
[Rebase fix] Fix pedersen includes.
suyash67 Mar 29, 2023
fa617dc
Add cout for verification_key struct (#295)
spalladino Mar 30, 2023
03dc6af
bump generators back up for wasm
dbanks12 Mar 30, 2023
570771f
read, write, stream agg state
iAmMichaelConnor Mar 30, 2023
4356e86
compute tree (#298)
dbanks12 Mar 30, 2023
bb99de7
[SQUASHED] fixing `push_array_to_array` method. (#304)
suyash67 Apr 1, 2023
afb2f57
feat(memory_tree|a3): add sibling path calculations (#301)
Maddiaa0 Apr 3, 2023
254725b
fix array and resolve merge conflicts (#305)
iAmMichaelConnor Apr 4, 2023
4de735f
Mc/hash vk (#306)
iAmMichaelConnor Apr 4, 2023
faf2c94
Increase number of sub-generators to 128.
suyash67 Apr 4, 2023
efd03fb
Build a3crypto.wasm (#311)
spalladino Apr 5, 2023
ec24fa5
More Tests on A3 `stdlib` methods (#316)
suyash67 Apr 5, 2023
0922559
test: more vk tests to compare circuit/native/vk_data (#310)
dbanks12 Apr 5, 2023
5cbc33d
fix. (#318)
suyash67 Apr 5, 2023
58d4d72
Added test for `compute_tree_native`. (#319)
suyash67 Apr 5, 2023
fdbca65
Install instructions for apt on ubuntu (#312)
spalladino Apr 5, 2023
88c5800
Rebase fixes (06-04-23).
suyash67 Apr 6, 2023
9fecf75
Fix address compilation. (#329)
suyash67 Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@
- libomp (if multithreading is required. Multithreading can be disabled using the compiler flag `-DMULTITHREADING 0`)
- wasm-opt (part of the [Binaryen](https://github.com/WebAssembly/binaryen) toolkit)

To install on Ubuntu, run:
```
sudo apt-get install cmake clang clang-format ninja-build binaryen
```

### Installing openMP (Linux)

Install from source:

```
RUN git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \
git clone -b release/10.x --depth 1 https://github.com/llvm/llvm-project.git \
&& cd llvm-project && mkdir build-openmp && cd build-openmp \
&& cmake ../openmp -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMP_ENABLE_SHARED=OFF \
&& cmake --build . --parallel \
&& cmake --build . --parallel --target install \
&& cd ../.. && rm -rf llvm-project
```

Or install from a package manager, on Ubuntu:

```
sudo apt-get install libomp-dev
```

> Note: on a fresh Ubuntu Kinetic installation, installing OpenMP from source yields a `Could NOT find OpenMP_C (missing: OpenMP_omp_LIBRARY) (found version "5.0")` error when trying to build Barretenberg. Installing from apt worked fine.
### Getting started

Run the bootstrap script. (The bootstrap script will build both the native and wasm versions of barretenberg)
Expand Down
11 changes: 11 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ option(BENCHMARKS "Build benchmarks" ON)
option(FUZZING "Build fuzzing harnesses" OFF)
option(DISABLE_TBB "Intel Thread Building Blocks" ON)
option(COVERAGE "Enable collecting coverage from tests" OFF)
option(SERIALIZE_CANARY "Build with serialize canary" OFF)
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON)
option(USE_TURBO "Enable the use of TurboPlonk in barretenberg." OFF)
Expand All @@ -39,6 +41,15 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "a
set(DISABLE_TBB 0)
endif()

if(ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

if(SERIALIZE_CANARY)
add_definitions(-DENABLE_SERIALIZE_CANARY)
endif()

if(FUZZING)
add_definitions(-DFUZZING=1)

Expand Down
5 changes: 3 additions & 2 deletions cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ WORKDIR /usr/src/barretenberg/cpp/src
RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv -
WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Build both honk_tests barretenberg.wasm
# Build both honk_tests barretenberg.wasm primitives.wasm
# This ensures that we aren't using features that would be incompatible with WASM for Honk
RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm
RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target primitives.wasm

FROM alpine:3.17
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/primitives.wasm /usr/src/barretenberg/cpp/build/bin/primitives.wasm
COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/
4 changes: 2 additions & 2 deletions cpp/scripts/bb-tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ crypto_aes128_tests
crypto_blake2s_tests
crypto_blake3s_tests
crypto_ecdsa_tests
crypto_pedersen_tests
crypto_pedersen_commitment_tests
crypto_schnorr_tests
crypto_sha256_tests
ecc_tests
Expand All @@ -18,7 +18,7 @@ stdlib_blake2s_tests
stdlib_blake3s_tests
stdlib_ecdsa_tests
stdlib_merkle_tree_tests
stdlib_pedersen_tests
stdlib_pedersen_commitment_tests
stdlib_schnorr_tests
stdlib_sha256_tests
transcript_tests
56 changes: 49 additions & 7 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,28 @@ if(WASM)
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
)

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

# Repeat the above but for the smaller primitives.wasm
# Used in packages where we don't need the full contents of barretenberg
add_executable(
primitives.wasm
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:ecc_objects>
)

target_link_options(
primitives.wasm
PRIVATE
-nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
)

# TODO(blaine): Figure out how to Asyncify the wasm output.
# Binaryen's Asyncify transform produces wasm that has too many local variables to run in a WebAssembly
# instance. This likely would be "solved" by enabling the optimizations to reduce the number of locals,
# but using any optimization level results in a wasm file that takes an unusable amount of time to solve the
# most simple prood.

# find_program(WASM_OPT wasm-opt)

# if(NOT WASM_OPT)
Expand All @@ -124,6 +153,13 @@ if(WASM)
# VERBATIM
# )

add_custom_command(
TARGET primitives.wasm
POST_BUILD
COMMAND wasm-opt "$<TARGET_FILE:primitives.wasm>" -O2 -o "$<TARGET_FILE:primitives.wasm>"
VERBATIM
)

if(INSTALL_BARRETENBERG)
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand All @@ -142,15 +178,18 @@ if(WASM)
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
Expand All @@ -174,15 +213,18 @@ else()
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/barretenberg/common/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ InnerCont flatten(Cont<InnerCont, Args...> const& in)
result.insert(result.end(), e.begin(), e.end());
}
return result;
}

// Return the first index at which a given item can be found in the vector.
// Only safe for vectors with length less than the size_t overflow size.
template <typename T> long index_of(std::vector<T> const& vec, T const& item)
{
auto const& begin = vec.begin();
auto const& end = vec.end();

auto const& itr = std::find(begin, end, item);

return itr == end ? -1 : std::distance(begin, itr);
}
18 changes: 17 additions & 1 deletion cpp/src/barretenberg/common/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ template <template <typename, typename...> typename Cont,
typename... Args,
typename F,
typename OutElem = typename std::invoke_result<F, InElem const&>::type>
Cont<OutElem> map(Cont<InElem, Args...> const& in, F op)
Cont<OutElem> map(Cont<InElem, Args...> const& in, F&& op)
{
Cont<OutElem> result;
std::transform(in.begin(), in.end(), std::back_inserter(result), op);
return result;
}

/*
* Generic map function for mapping a std::array's elements to another type.
* TODO: this has only been added because I (Mike) couldn't get the above to work
* with an array.
*/
template <std::size_t SIZE,
typename InElem,
typename F,
typename OutElem = typename std::invoke_result<F, InElem const&>::type>
std::array<OutElem, SIZE> map(std::array<InElem, SIZE> const& in, F&& op)
{
std::array<OutElem, SIZE> result;
std::transform(in.begin(), in.end(), result.begin(), op);
return result;
}

/*
* Generic map function for mapping a containers element to another type.
* This version passes the element index as a second argument to the operator function.
Expand Down
Loading