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

bb.js is standalone prover that handles noir constraint/witness output. #471

Merged
merged 33 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0038bb6
Initial
charlielye May 21, 2023
284eac2
Separate thread build dir.
charlielye May 21, 2023
afef842
Large vector slab allocator.
charlielye May 22, 2023
4c39ac6
format msgpack serialization and excldue msgpack-c from clang-format …
vezenovm May 22, 2023
e1318c1
patch: temporarily remove broken solidity ci (#470)
Maddiaa0 May 23, 2023
efc3926
progress.
charlielye May 23, 2023
0e7d32f
Sumcheck improvements (#455)
ledwards2225 May 23, 2023
0e0b04d
working. but cant compute pk independently :/
charlielye May 23, 2023
b2635b6
Fixed.
charlielye May 23, 2023
2a7e1d0
Better key construction separation.
charlielye May 24, 2023
6477f82
Merge remote-tracking branch 'origin/master' into cl/acir_cbinds
charlielye May 24, 2023
f108b22
Clean
charlielye May 24, 2023
130c944
tests pass
charlielye May 24, 2023
72e4c98
Commander
charlielye May 24, 2023
b600d99
Fix.
charlielye May 24, 2023
e51ab64
Fix
charlielye May 24, 2023
14acc50
Fix serve.
charlielye May 24, 2023
e660b55
Fix
charlielye May 24, 2023
d3278fd
More commands.
charlielye May 24, 2023
ad28215
Fixed a bug in biggroup tests (#478)
Rumata888 May 25, 2023
ada5d9d
Add back custom libc++ build.
charlielye May 25, 2023
f815187
Fix.
charlielye May 25, 2023
0fee875
write_vk
charlielye May 25, 2023
fa7984a
Merge branch 'cl/acir_cbinds' of github.com:aztecprotocol/barretenber…
charlielye May 25, 2023
0834791
DSL: Add KeccakVar opcode (#476)
kevaundray May 25, 2023
4d851dd
Multi-constraint Relations (#444)
ledwards2225 May 25, 2023
dff766b
Clean up srs package. Add a global crs that the wasm can init once.
charlielye May 26, 2023
97a2fdf
Add back vk serialization for a3
charlielye May 27, 2023
04b6024
Clean
charlielye May 27, 2023
cf4b674
Merge remote-tracking branch 'origin/master' into cl/acir_cbinds
charlielye May 27, 2023
7065b1f
Merge branch 'cl/acir_cbinds' of github.com:aztecprotocol/barretenber…
charlielye May 27, 2023
7cfc53a
Exclude env from lib.
charlielye May 27, 2023
3683800
feat(dsl)!: DSL recursion changes w/ bb.js (#485)
vezenovm Jun 1, 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
23 changes: 0 additions & 23 deletions .github/workflows/solidity_verifier_test.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"solidity.compileUsingRemoteVersion": "v0.6.10+commit.00c0fcaf",
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
"**/.pnp.*": true,
"**/msgpack-c/**": true
},
"typescript.tsdk": "ts/.yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
Expand Down
1 change: 1 addition & 0 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"displayName": "Build for pthread enabled WASM",
"description": "Build for pthread enabled WASM",
"inherits": "wasm",
"binaryDir": "build-wasm-threads",
"environment": {
"WASI_SDK_PREFIX": "${sourceDir}/src/wasi-sdk-20.0+threads",
"CMAKE_BUILD_TYPE": "Release"
Expand Down
4 changes: 4 additions & 0 deletions cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@ cmake --build --preset $PRESET ${@/#/--target }
./scripts/install-wasi-sdk.sh

# Build WASM.
cmake --preset wasm
cmake --build --preset wasm

# Build WASM with new threading.
cmake --preset wasm-threads
cmake --build --preset wasm-threads
51 changes: 51 additions & 0 deletions cpp/scripts/build_libacvm_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -eu

BB_TARGETS=(
libenv.a
libcommon.a
libcrypto_blake2s.a
libcrypto_pedersen_hash.a
libcrypto_pedersen_commitment.a
libcrypto_keccak.a
libcrypto_schnorr.a
libcrypto_generators.a
libnumeric.a
)

CMD="cmake --preset wasm && cmake --build --preset wasm"
for target in "${BB_TARGETS[@]}"; do CMD="$CMD --target $target"; done
eval $CMD

cd ./build-wasm/lib

LIBS=(
$PWD/libenv.a
$PWD/libcommon.a
$PWD/libcrypto_blake2s.a
$PWD/libcrypto_pedersen_hash.a
$PWD/libcrypto_pedersen_commitment.a
$PWD/libcrypto_keccak.a
$PWD/libcrypto_schnorr.a
$PWD/libcrypto_generators.a
$PWD/libnumeric.a
$PWD/../../src/wasi-sdk-20.0/share/wasi-sysroot/lib/wasm32-wasi/libc++.a
$PWD/../../src/wasi-sdk-20.0/share/wasi-sysroot/lib/wasm32-wasi/libc++abi.a
)

rm -rf scratch
mkdir -p scratch
cd scratch

for LIB_FILE_PATH in "${LIBS[@]}"; do
LIB=$(basename $LIB_FILE_PATH)
echo Extracting lib: $LIB
mkdir $LIB
cd $LIB
ar x $LIB_FILE_PATH
cd ..
done

rm -f ../libacvm_backend.a
#../../../src/wasi-sdk-12.0/bin/ar rcs ../libxyz.a libcrypto_blake2s.a/* libc++.a/* libc++abi.a/* libcrypto_pedersen_commitment.a/*
find . -type f -print0 | xargs -0 ../../../src/wasi-sdk-20.0/bin/ar rcs ../libacvm_backend.a
3 changes: 1 addition & 2 deletions cpp/scripts/install-wasi-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ else
# Replace wasi-sysroot in wasi-sdk-20.0+threads with our custom build.
# It contains libc++ and a patch by yamt to improve thread join stability.
# Can remove once future releases are more stable.
# UPDATE: Commenting out as we switched to "parallel_for_mutex_pool" as this we actually not very stable.
# curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sysroot-20.0.threads.tgz | tar zxfv -
curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sysroot-20.0.threads.tgz | tar zxfv -
fi
72 changes: 64 additions & 8 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
endif()

# We enable -O1 level optimsations, even when compiling debug wasm, otherwise we get "local count too large" at runtime.
# We prioritise reducing size of final artefacts in release with -Oz.
if(WASM)
set(CMAKE_CXX_FLAGS_DEBUG "-O1 -g")
set(CMAKE_C_FLAGS_DEBUG "-O1 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
add_link_options(-Wl,--export-memory,--import-memory,--stack-first,-z,stack-size=1048576,--max-memory=4294967296)
endif()

Expand Down Expand Up @@ -70,6 +73,10 @@ endif()

include(GNUInstallDirs)

# For this library we include everything but the env and wasi modules, as it is the responsibility of the
# consumer of this library to define how and in what environment its artefact will run.
# libbarretenberg + libwasi = a wasi "reactor" that implements it's own env (e.g. logstr), e.g. barretenberg.wasm.
# libbarretenberg + env = a wasi "command" that expects a full wasi runtime (e.g. wasmtime), e.g. test binaries.
message(STATUS "Compiling all-in-one barretenberg archive")
add_library(
barretenberg
Expand Down Expand Up @@ -108,24 +115,73 @@ add_library(
$<TARGET_OBJECTS:transcript_objects>
)

if(WASM)
add_executable(
barretenberg.wasm
$<TARGET_OBJECTS:wasi_objects>
)

target_link_libraries(barretenberg.wasm barretenberg)
# Small library to provide necessary primitives for rust crate.
add_library(
acvm_backend
$<TARGET_OBJECTS:env_objects>
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
)

if(WASM)
# With binaryen installed, it seems its wasm backend optimiser gets invoked automatically.
# Due to either a bug in the optimiser, or non-standards compliant c++ in crypto/aes, tests start failing with
# -O3 level optimisations. We force down to -O2 for current workaround.
# TODO: Time has passed, check if this is still needed.
# UPDATE: Uninstall binaryen and any need downstream.
set(CMAKE_CXX_FLAGS_RELEASE "-O2")

# When building this wasm "executable", we include the wasi module but exclude the env module.
# That's because we expect this wasm to be run as a wasi "reactor" and for the host environment
# to implement the functions in env.
add_executable(
barretenberg.wasm
$<TARGET_OBJECTS:wasi_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_ecdsa_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:examples_objects>
$<TARGET_OBJECTS:honk_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:plonk_objects>
$<TARGET_OBJECTS:polynomials_objects>
$<TARGET_OBJECTS:proof_system_objects>
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_keccak_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:transcript_objects>
)

target_link_options(
barretenberg.wasm
PRIVATE
-nostartfiles -Wl,--whole-archive,--no-entry,--export-dynamic,--allow-undefined
-nostartfiles -Wl,--no-entry,--export-dynamic,--allow-undefined
)

if(INSTALL_BARRETENBERG)
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/benchmark/pippenger_bench/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "barretenberg/common/assert.hpp"
#include <cstdlib>
#include "barretenberg/ecc/curves/bn254/scalar_multiplication/scalar_multiplication.hpp"
#include "barretenberg/srs/reference_string/file_reference_string.hpp"
#include "barretenberg/srs/factories/file_crs_factory.hpp"
#include "barretenberg/polynomials/polynomial_arithmetic.hpp"

// #include <valgrind/callgrind.h>
Expand Down Expand Up @@ -41,7 +41,7 @@ constexpr size_t NUM_POINTS = 1 << 16;
std::vector<fr> scalars;
static barretenberg::evaluation_domain small_domain;
static barretenberg::evaluation_domain large_domain;
auto reference_string = std::make_shared<proof_system::FileReferenceString>(NUM_POINTS, "../srs_db/ignition");
auto reference_string = std::make_shared<barretenberg::srs::factories::FileProverCrs>(NUM_POINTS, "../srs_db/ignition");

const auto init = []() {
small_domain = barretenberg::evaluation_domain(NUM_POINTS);
Expand Down
9 changes: 7 additions & 2 deletions cpp/src/barretenberg/common/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef NO_MULTITHREADING
#include "./c_bind.hpp"
#include "./mem.hpp"
#include "./timer.hpp"
#include "./serialize.hpp"
#include "./slab_allocator.hpp"
#include <algorithm>
#include <thread>

Expand Down Expand Up @@ -31,8 +33,6 @@ void thread_test_abort_entry_point(void*)
std::abort();
}

extern "C" {

WASM_EXPORT void test_threads(uint32_t const* thread_num, uint32_t const* iterations, uint32_t* out)
{
info("test starting...");
Expand Down Expand Up @@ -66,4 +66,9 @@ WASM_EXPORT void test_abort()
info("test_abort aborting");
std::abort();
}

WASM_EXPORT void common_init_slab_allocator(uint32_t const* circuit_size)
{
barretenberg::init_slab_allocator(ntohl(*circuit_size));
}
#endif
5 changes: 2 additions & 3 deletions cpp/src/barretenberg/common/c_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#include "./wasm_export.hpp"
#include "./serialize.hpp"

extern "C" {

WASM_EXPORT void test_threads(uint32_t const* threads, uint32_t const* iterations, uint32_t* out);

WASM_EXPORT void test_thread_abort();

WASM_EXPORT void test_abort();
}

WASM_EXPORT void common_init_slab_allocator(uint32_t const* circuit_size);
Loading