Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The structured reference string contains monomials up to x^{2^20}. This SRS was
RUN 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 \
&& make -j$(nproc) \
&& make install \
&& cmake --build . --parallel \
&& cmake --build . --parallel --target install \
&& cd ../.. && rm -rf llvm-project
```

Expand All @@ -33,7 +33,7 @@ cd cpp

### Parallelise the build

Make sure your MAKEFLAGS environment variable is set to run jobs equal to number of cores. e.g. `MAKEFLAGS=-j$(nproc)`.
Use the `--parallel` option to `cmake --build <path>` to parallelize builds. This is roughly equivalent to `make -j$(nproc)` but is more portable.

### Formatting

Expand All @@ -45,20 +45,20 @@ If you've installed the C++ Vscode extension you should configure it to format o
Each module has its own tests. e.g. To build and run `ecc` tests:

```
make ecc_tests
cmake --build . --parallel --target ecc_tests
./bin/ecc_tests
```

A shorthand for the above is:

```
make run_ecc_tests
cmake --build . --parallel --target run_ecc_tests
```

Running the entire suite of tests using `ctest`:

```
make test
cmake --build . --parallel --target test
```

You can run specific tests, e.g.
Expand All @@ -72,14 +72,14 @@ You can run specific tests, e.g.
Some modules have benchmarks. The build targets are named `<module_name>_bench`. To build and run, for example `ecc` benchmarks.

```
make ecc_bench
cmake --build . --parallel --target ecc_bench
./src/aztec/ecc/ecc_bench
```

A shorthand for the above is:

```
make run_ecc_bench
cmake --build . --parallel --target run_ecc_bench
```

### CMake Build Options
Expand All @@ -102,10 +102,10 @@ To build:
```
mkdir build-wasm && cd build-wasm
cmake -DTOOLCHAIN=wasm-linux-clang ..
make barretenberg.wasm
cmake --build . --parallel --target barretenberg.wasm
```

The resulting wasm binary will be at `./src/aztec/barretenberg.wasm`.
The resulting wasm binary will be at `./build-wasm/bin/barretenberg.wasm`.

To run the tests, you'll need to install `wasmtime`.

Expand All @@ -116,7 +116,7 @@ curl https://wasmtime.dev/install.sh -sSf | bash
Tests can be built and run like:

```
make ecc_tests
cmake --build . --parallel --target ecc_tests
wasmtime --dir=.. ./bin/ecc_tests
```

Expand All @@ -126,11 +126,11 @@ To build:
```
mkdir build-fuzzing && cd build-fuzzing
cmake -DTOOLCHAIN=x86_64-linux-clang -DFUZZING=ON ..
make
cmake --build . --parallel
```
Fuzzing build turns off building tests and benchmarks, since they are incompatible with libfuzzer interface.

To turn on address sanitizer add `-DADDRESS_SANITIZER=ON`. Note that address sanitizer can be used to explore crashes.
Sometimes you might have to specify the address of llvm-symbolizer. You have to do it with `export ASAN_SYMBOLIZER_PATH=<PATH_TO_SYMBOLIZER>`.
For undefined behaviour sanitizer `-DUNDEFINED_BEHAVIOUR_SANITIZER=ON`.
Note that the fuzzer can be orders of magnitude slower with ASan (2-3x slower) or UBSan on, so it is best to run a non-sanitized build first, minimize the testcase and then run it for a bit of time with sanitizers.
Note that the fuzzer can be orders of magnitude slower with ASan (2-3x slower) or UBSan on, so it is best to run a non-sanitized build first, minimize the testcase and then run it for a bit of time with sanitizers.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(FUZZING)
if(UNDEFINED_BEHAVIOUR_SANITIZER)
set(SANITIZER_OPTIONS ${SANITIZER_OPTIONS} -fsanitize=undefined -fno-sanitize=alignment)
endif()

add_compile_options(-fsanitize=fuzzer-no-link ${SANITIZER_OPTIONS})

set(WASM OFF)
Expand Down
8 changes: 3 additions & 5 deletions cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ else
fi

# Download ignition transcripts.
cd ./srs_db
./download_ignition.sh 3
cd ..
(cd ./srs_db && ./download_ignition.sh 3)

# Pick native toolchain file.
if [ "$OS" == "macos" ]; then
Expand All @@ -51,7 +49,7 @@ fi
# Build native.
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DTOOLCHAIN=$TOOLCHAIN ..
make -j$(getconf _NPROCESSORS_ONLN) $@
cmake --build . --parallel ${@/#/--target }
cd ..

# Install the webassembly toolchain.
Expand All @@ -64,4 +62,4 @@ cd ..
mkdir -p build-wasm && cd build-wasm
cmake -DTOOLCHAIN=wasm-linux-clang ..
cmake --build . --parallel --target barretenberg.wasm
cd ..
cd ..
5 changes: 4 additions & 1 deletion cpp/cmake/toolchains/wasm-linux-clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR wasm32)
set(triple wasm32-wasi)

set(WASI_SDK_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/src/wasi-sdk-12.0")
if (NOT WASI_SDK_PREFIX)
# can be set by a dependent project
set(WASI_SDK_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/src/wasi-sdk-12.0")
endif()
set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang)
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++)
set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar CACHE STRING "wasi-sdk build")
Expand Down
2 changes: 1 addition & 1 deletion cpp/dockerfiles/Dockerfile.arm64-linux-gcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM aztecprotocol/crosstool-ng-arm64:latest
WORKDIR /usr/src/barretenberg/cpp
COPY . .
RUN mkdir build && cd build && cmake -DTOOLCHAIN=arm64-linux-gcc .. && make -j$(nproc)
RUN mkdir build && cd build && cmake -DTOOLCHAIN=arm64-linux-gcc .. && cmake --build . --parallel
RUN cd build && qemu-aarch64 ./test/barretenberg_tests
ENTRYPOINT /bin/bash
4 changes: 2 additions & 2 deletions cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 . .
RUN mkdir build && cd build && cmake -DTOOLCHAIN=wasm-linux-clang .. && make -j$(nproc) barretenberg.wasm
RUN mkdir build && cd build && cmake -DTOOLCHAIN=wasm-linux-clang .. && cmake --build . --parallel --target barretenberg.wasm

FROM alpine:3.13
COPY --from=builder /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm
COPY --from=builder /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm
6 changes: 3 additions & 3 deletions cpp/dockerfiles/Dockerfile.x86_64-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ RUN apk update \
RUN 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 \
&& make -j$(nproc) \
&& make install \
&& cmake --build . --parallel \
&& cmake --build . --parallel --target install \
&& cd ../.. && rm -rf llvm-project
WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Only build binaries that are needed upstream.
RUN mkdir build && cd build && cmake -DOpenMP_omp_LIBRARY=/usr/local/lib/libomp.a .. && make -j$(nproc) db_cli rollup_cli tx_factory keygen
RUN mkdir build && cd build && cmake -DOpenMP_omp_LIBRARY=/usr/local/lib/libomp.a .. && cmake --build . --parallel --target db_cli --target rollup_cli --target tx_factory --target keygen

FROM alpine:3.13
RUN apk update && apk add llvm10-libs
Expand Down
6 changes: 3 additions & 3 deletions cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ RUN apk update \
RUN 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 \
&& make -j$(nproc) \
&& make install \
&& cmake --build . --parallel \
&& cmake --build . --parallel --target install \
&& cd ../.. && rm -rf llvm-project
WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Build everything to ensure everything builds. All tests will be run from the result of this build.
RUN mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DOpenMP_omp_LIBRARY=/usr/local/lib/libomp.a -DCI=ON .. && make -j$(nproc)
RUN mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DOpenMP_omp_LIBRARY=/usr/local/lib/libomp.a -DCI=ON .. && cmake --build . --parallel

FROM alpine:3.13
RUN apk update && apk add llvm10-libs curl
Expand Down
2 changes: 1 addition & 1 deletion cpp/dockerfiles/Dockerfile.x86_64-linux-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apk update \
WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Build the entire project (not just rollup_cli and db_cli), as we want to check everything builds under gcc.
RUN mkdir build && cd build && cmake -DTOOLCHAIN=x86_64-linux-gcc -DCI=ON .. && make -j$(nproc)
RUN mkdir build && cd build && cmake -DTOOLCHAIN=x86_64-linux-gcc -DCI=ON .. && cmake --build . --parallel

FROM alpine:3.13
RUN apk update && apk add libstdc++ libgomp
Expand Down
2 changes: 1 addition & 1 deletion cpp/docs/Fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Build with coverage instrumentation:
mkdir build-coverage/
cd build-coverage/
cmake -DFUZZING=ON -DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" ..
make -j$(nproc)
cmake --build . --parallel
```

Then run the fuzzer on the corpus and generate the HTML coverage reports:
Expand Down
54 changes: 53 additions & 1 deletion cpp/src/aztec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wno-deprecated -Wno-tautological-compare -Wfatal-errors)

Expand Down Expand Up @@ -62,6 +63,7 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
# TODO: remove all except those needed for testing (join_split)
$<TARGET_OBJECTS:rollup_proofs_inner_proof_data_objects>
$<TARGET_OBJECTS:rollup_proofs_notes_objects>
$<TARGET_OBJECTS:rollup_proofs_account_objects>
Expand Down Expand Up @@ -91,5 +93,55 @@ if(WASM)
barretenberg.wasm
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm
)
# For use when compiling dependent cpp projects for WASM
message(STATUS "Compiling all-in-one barretenberg WASM archive")
add_library(
barretenberg
STATIC
$<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_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
)

endif()
else()
# For use when compiling dependent cpp projects
message(STATUS "Compiling all-in-one barretenberg archive")
add_library(
barretenberg
STATIC
$<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_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_pedersen_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:env_objects>
)
endif()
3 changes: 3 additions & 0 deletions cpp/src/aztec/ecc/curves/grumpkin/grumpkin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "../bn254/fr.hpp"

namespace grumpkin {

constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = 252;

typedef barretenberg::fr fq;
typedef barretenberg::fq fr;

Expand Down
4 changes: 3 additions & 1 deletion cpp/src/aztec/rollup/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#include <stddef.h>
#include <stdint.h>
#include <numeric/uint256/uint256.hpp>
#include <ecc/curves/grumpkin/grumpkin.hpp>

namespace rollup {

constexpr size_t DATA_TREE_DEPTH = 32;
constexpr size_t NULL_TREE_DEPTH = 256;
constexpr size_t ROOT_TREE_DEPTH = 28;
constexpr size_t DEFI_TREE_DEPTH = 30;

constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = 252;
constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH;
constexpr size_t MAX_TXS_BIT_LENGTH = 10;
constexpr size_t TX_FEE_BIT_LENGTH = MAX_NO_WRAP_INTEGER_BIT_LENGTH - MAX_TXS_BIT_LENGTH;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <numeric/uint256/uint256.hpp>
#include <numeric/random/engine.hpp>
#include <stdlib/primitives/bigfield/bigfield.hpp>
#include "../../../rollup/constants.hpp"
#include <ecc/curves/bn254/fq.hpp>

// This is a global variable, so that the execution handling class could alter it and signal to the input tester
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <numeric/random/engine.hpp>
#include <stdlib/primitives/bit_array/bit_array.hpp>
#include "../../../rollup/constants.hpp"

#define MAX_ARRAY_SIZE 128

Expand Down
1 change: 0 additions & 1 deletion cpp/src/aztec/stdlib/primitives/bool/bool.fuzzer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <numeric/random/engine.hpp>
#include <stdlib/primitives/bit_array/bit_array.hpp>
#include "../../../rollup/constants.hpp"

// This is a global variable, so that the execution handling class could alter it and signal to the input tester that
// the input should fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <numeric/random/engine.hpp>
#include <stdlib/primitives/byte_array/byte_array.hpp>
#include <stdlib/primitives/safe_uint/safe_uint.hpp>
#include "../../../rollup/constants.hpp"

#define MAX_ARRAY_SIZE 128

Expand Down
5 changes: 2 additions & 3 deletions cpp/src/aztec/stdlib/primitives/field/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include <functional>
#include "../bool/bool.hpp"
#include "../composers/composers.hpp"
#include "../../../rollup/constants.hpp"
#include "pow.hpp"
#include "../../../rollup/constants.hpp"
#include <ecc/curves/grumpkin/grumpkin.hpp>

// #pragma GCC diagnostic ignored "-Wunused-variable"
// #pragma GCC diagnostic ignored "-Wunused-parameter"
Expand Down Expand Up @@ -824,7 +823,7 @@ std::array<field_t<ComposerContext>, 3> field_t<ComposerContext>::slice(const ui
const field_t lo_wit = field_t(witness_t(ctx, lo));
const field_t slice_wit = field_t(witness_t(ctx, slice));

hi_wit.create_range_constraint(rollup::MAX_NO_WRAP_INTEGER_BIT_LENGTH - uint32_t(msb),
hi_wit.create_range_constraint(grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH - uint32_t(msb),
"slice: hi value too large.");
lo_wit.create_range_constraint(lsb, "slice: lo value too large.");
slice_wit.create_range_constraint(msb_plus_one - lsb, "slice: sliced value too large.");
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/aztec/stdlib/primitives/field/field.fuzzer.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <numeric/uint256/uint256.hpp>
#include <numeric/random/engine.hpp>
#include <stdlib/primitives/field/field.hpp>
#include "../../../rollup/constants.hpp"
#include <stdlib/primitives/bool/bool.hpp>
#include <ecc/curves/grumpkin/grumpkin.hpp>
#include <ecc/curves/bn254/fr.hpp>

// This is a global variable, so that the execution handling class could alter it and signal to the input tester
Expand Down Expand Up @@ -1575,7 +1575,7 @@ template <typename Composer> class FieldBase {
// Check assert conditions
if ((lsb > msb) || (msb > 252) ||
(static_cast<uint256_t>(stack[first_index].f().get_value()) >=
(static_cast<uint256_t>(1) << rollup::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) {
(static_cast<uint256_t>(1) << grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) {
return 0;
}
PRINT_SLICE(first_index, lsb, msb, stack)
Expand Down
Loading