Skip to content

Commit

Permalink
feat: Initial native version of bb binary. (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielye authored Jul 5, 2023
1 parent 656d794 commit 4a1b532
Show file tree
Hide file tree
Showing 45 changed files with 614 additions and 127 deletions.
39 changes: 38 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 bb-tests
command: cond_spot_run_test_script ./scripts/bb-tests.sh barretenberg-x86_64-linux-clang-assert
- *save_logs

honk-tests:
Expand Down Expand Up @@ -266,6 +266,18 @@ jobs:
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 3 join_split_example_proofs_join_split_tests --gtest_filter=-*full_proof*
- *save_logs

bb-bin-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_test_script ./scripts/bin-test.sh barretenberg-x86_64-linux-clang-assert
- *save_logs

benchmark-aggregator:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -302,6 +314,29 @@ jobs:
name: "Test"
command: cond_spot_run_tests bb.js

# These machines cost a fortune (10x other machines).
# There is a branch coming for github actions that will build mac stuff on releases.
# I'll leave this here for now, just in case proves useful to be able to do CI mac builds on branches,
# but let's not uncomment in master.
#
# aarch64-macos-clang:
# macos:
# xcode: "14.3.1"
# resource_class: macos.m1.medium.gen1
# steps:
# - *checkout
# - run:
# name: "Install toolchain"
# command: brew install cmake ninja
# - run:
# name: "Build"
# working_directory: ~/project/cpp
# command: cmake --preset default && cmake --build --preset default --target bb
# - run:
# name: "Test"
# working_directory: ~/project/cpp/bin-test
# command: ./bin-test.sh

###################################
# Aztec integration tests
#circuits-wasm-linux-clang-builder-runner:
Expand Down Expand Up @@ -381,6 +416,7 @@ notmaster: &notmaster
workflows:
system:
jobs:
# - aarch64-macos-clang: *defaults
- x86_64-linux-gcc: *defaults
- x86_64-linux-clang: *defaults
- x86_64-linux-clang-assert: *defaults
Expand All @@ -393,6 +429,7 @@ workflows:
- stdlib-recursion-turbo-tests: *bb_test
- stdlib-recursion-ultra-tests: *bb_test
- join-split-tests: *bb_test
- bb-bin-tests: *bb_test
- benchmark-aggregator:
requires:
- barretenberg-tests
Expand Down
7 changes: 5 additions & 2 deletions barretenberg-wasm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ stdenv.mkDerivation

src = ./cpp;

nativeBuildInputs = [ cmake ninja binaryen wasi-sdk ];
nativeBuildInputs = [ cmake ninja wasi-sdk ];

buildInputs = [ ];

cmakeFlags = [
"-GNinja"
"-DTESTING=OFF"
"-DBENCHMARKS=OFF"
"-DCMAKE_TOOLCHAIN_FILE=${toolchain_file}"
Expand All @@ -31,5 +32,7 @@ stdenv.mkDerivation
"-DCMAKE_CXX_COMPILER_WORKS=ON"
];

enableParallelBuilding = true;
buildPhase = ''
cmake --build . --target barretenberg.wasm --parallel
'';
}
33 changes: 25 additions & 8 deletions cpp/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
build*
docker*
.*
src/wasi-sdk*
src/barretenberg/rollup/proofs/root_*/fixtures/account
src/barretenberg/rollup/proofs/root_*/fixtures/join_split
src/barretenberg/rollup/proofs/root_*/fixtures/**/proving_key
srs_db/ignition/transcript*
# We want to explicitly define what's allowed into the context.
*

# Important cmake files.
!CMakeLists.txt
!CMakePresets.json
!cmake

# Important srs_db files.
!srs_db/download_ignition.sh
!srs_db/ignition/checksums

# Source code.
!src/CMakeLists.txt
!src/barretenberg
!src/msgpack-c

# Needed scripts.
!scripts/install-wasi-sdk.sh

# Noir project for testing bb binary.
!bin-test
bin-test/crs
bin-test/proof
bin-test/vk
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ project(
option(DISABLE_ASM "Disable custom assembly" OFF)
option(DISABLE_ADX "Disable ADX assembly variant" OFF)
option(MULTITHREADING "Enable multi-threading" ON)
option(OMP_MULTITHREADING "Enable OMP multi-threading" ON)
option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF)
option(TESTING "Build tests" ON)
option(BENCHMARKS "Build benchmarks" ON)
option(FUZZING "Build fuzzing harnesses" OFF)
Expand Down
4 changes: 1 addition & 3 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"inherits": "default",
"environment": {
"CC": "$env{BREW_PREFIX}/opt/llvm/bin/clang",
"CXX": "$env{BREW_PREFIX}/opt/llvm/bin/clang++",
"LDFLAGS": "-L$env{BREW_PREFIX}/opt/libomp/lib",
"CPPFLAGS": "-I$env{BREW_PREFIX}/opt/libomp/include"
"CXX": "$env{BREW_PREFIX}/opt/llvm/bin/clang++"
}
},
{
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions cpp/bin-test/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.6.0"

[dependencies]
6 changes: 6 additions & 0 deletions cpp/bin-test/Prover.toml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions cpp/bin-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# bb.js Binary Test

This test runs a sequence of commands that tests a Noir double recursion circuit verifies (src/main.nr).
The circuit has already been compiled and its witness generated in nargo via `nargo compile && nargo execute witness`.

To test:

```
./bin-test.sh
```
1 change: 1 addition & 0 deletions cpp/bin-test/Verifier.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
12 changes: 12 additions & 0 deletions cpp/bin-test/bin-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Script is assumed to be run from
set -eu

bb() {
../build/bin/bb "$@" -v
}

bb gates
bb prove -o proof
bb write_vk -o vk
bb verify -k vk -p proof
28 changes: 8 additions & 20 deletions ts/test/README.md → cpp/bin-test/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
# Binary Test

Run:

```
./bin-test.sh
```

To run a sequence of commands that ultimately tests the following Noir double recursion circuit verifies.

```rust
use dep::std;

fn main(
verification_key : [Field; 114],
proof : [Field; 94],
public_inputs : [Field; 1],
key_hash : Field,
verification_key : [Field; 114],
proof : [Field; 94],
public_inputs : [Field; 1],
key_hash : Field,
input_aggregation_object : [Field; 16],
proof_b : [Field; 94],
) -> pub [Field; 16] {
let output_aggregation_object_a = std::verify_proof(
verification_key,
proof,
public_inputs,
key_hash,
verification_key,
proof,
public_inputs,
key_hash,
input_aggregation_object
);

Expand All @@ -41,4 +30,3 @@ fn main(
}
output
}
```
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions cpp/cmake/threading.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
if(MULTITHREADING)
message(STATUS "Multithreading is enabled.")
add_compile_options(-pthread)
add_link_options(-pthread)
if(WASM)
add_compile_options(--target=wasm32-wasi-threads -pthread)
add_link_options(--target=wasm32-wasi-threads -pthread)
add_compile_options(--target=wasm32-wasi-threads)
add_link_options(--target=wasm32-wasi-threads)
endif()
#add_compile_options(-fsanitize=thread)
#add_link_options(-fsanitize=thread)
Expand Down
4 changes: 2 additions & 2 deletions cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ WORKDIR /usr/src/barretenberg/cpp
COPY . .
# Build everything to ensure everything builds. All tests will be run from the result of this build.
RUN cmake --preset default -DCMAKE_BUILD_TYPE=RelWithAssert -DCI=ON && cmake --build --preset default
RUN cd build && ./bin/grumpkin_srs_gen 1048576 && cd ../

FROM alpine:3.18
RUN apk update && apk add curl openmp
COPY --from=builder /usr/src/barretenberg/cpp/srs_db /usr/src/barretenberg/cpp/srs_db
COPY --from=builder /usr/src/barretenberg/cpp/build/bin/*_tests /usr/src/barretenberg/cpp/build/bin/
COPY --from=builder /usr/src/barretenberg/cpp/build/bin /usr/src/barretenberg/cpp/build/bin
COPY --from=builder /usr/src/barretenberg/cpp/bin-test /usr/src/barretenberg/cpp/bin-test
15 changes: 0 additions & 15 deletions cpp/scripts/bb-tests

This file was deleted.

37 changes: 37 additions & 0 deletions cpp/scripts/bb-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# This script runs all test suites that have not been broken out into their own jobs for parallelisation.
# Might be better to list exclusions here rather than inclusions as risky to maintain.
set -e

$(aws ecr get-login --region us-east-2 --no-include-email) 2> /dev/null

IMAGE_URI=278380418400.dkr.ecr.us-east-2.amazonaws.com/barretenberg-x86_64-linux-clang-assert:cache-$COMMIT_HASH

docker pull $IMAGE_URI

TESTS=(
crypto_aes128_tests
crypto_blake2s_tests
crypto_blake3s_tests
crypto_ecdsa_tests
crypto_pedersen_commitment_tests
crypto_schnorr_tests
crypto_sha256_tests
ecc_tests
numeric_tests
plonk_tests
polynomials_tests
join_split_example_proofs_inner_proof_data_tests
join_split_example_proofs_notes_tests
srs_tests
transcript_tests
)
TESTS_STR="${TESTS[@]}"

docker run --rm -t $IMAGE_URI /bin/sh -c "\
set -e; \
cd /usr/src/barretenberg/cpp; \
(cd srs_db && ./download_ignition.sh 1); \
cd build; \
./bin/grumpkin_srs_gen 1048576; \
for BIN in $TESTS_STR; do ./bin/\$BIN; done"
14 changes: 14 additions & 0 deletions cpp/scripts/bin-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Executes the bb binary test script.
set -eu

$(aws ecr get-login --region us-east-2 --no-include-email) 2> /dev/null

IMAGE_URI=278380418400.dkr.ecr.us-east-2.amazonaws.com/barretenberg-x86_64-linux-clang-assert:cache-$COMMIT_HASH

docker pull $IMAGE_URI

docker run --rm -t $IMAGE_URI /bin/sh -c "\
set -e; \
cd /usr/src/barretenberg/cpp/bin-test; \
./bin-test.sh"
51 changes: 0 additions & 51 deletions cpp/scripts/build_libacvm_backend.sh

This file was deleted.

4 changes: 4 additions & 0 deletions cpp/scripts/run_tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
# This is the default test runner which takes the as arguments:
# 1. The number of ignition transcripts to download.
# 2. The set of gtest binary names to run.
# 3-n. The arguments to pass to the gtest binaries.
set -e

NUM_TRANSCRIPTS=$1
Expand Down
1 change: 1 addition & 0 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ add_subdirectory(barretenberg/serialize)
add_subdirectory(barretenberg/solidity_helpers)
add_subdirectory(barretenberg/wasi)
add_subdirectory(barretenberg/grumpkin_srs_gen)
add_subdirectory(barretenberg/bb)

if(BENCHMARKS)
add_subdirectory(barretenberg/benchmark)
Expand Down
Loading

0 comments on commit 4a1b532

Please sign in to comment.