Skip to content

Commit

Permalink
Merge aztec3
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad0 committed Mar 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5ece704 commit 9ea1a07
Showing 254 changed files with 8,397 additions and 6,223 deletions.
69 changes: 53 additions & 16 deletions cpp/src/aztec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Enable the following warnings project wide.
# If any compilation issues arise in the future, they should not be silenced here but rather in the
# If any compilation issues arise in the future, they should not be silenced here but rather in the
# module's own CMakeLists.txt by adding conditional compilation flags like the following
# ```
# if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# target_compile_options(crypto_blake3s_full_objects PRIVATE -Wno-error=shorten-64-to-32)
# endif()
# if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# target_compile_options(crypto_blake3s_full_objects PRIVATE -Wno-error=shorten-64-to-32)
# endif()
# ```
# Specifying `-Wno-${ERROR_NAME}` will silence the error completely.
# To preserve the warning, but prevent them from causing the build to fail,
@@ -16,6 +16,7 @@ add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wfatal

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fconstexpr-steps=100000000)

if(MEMORY_CHECKS)
message(STATUS "Compiling with memory checks.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
@@ -37,6 +38,7 @@ else()
message(STATUS "Using optimized assembly for field arithmetic.")
endif()

add_subdirectory(common)
add_subdirectory(env)
add_subdirectory(numeric)
add_subdirectory(srs)
@@ -49,20 +51,21 @@ add_subdirectory(honk)
add_subdirectory(plonk)
add_subdirectory(stdlib)
add_subdirectory(join_split_example)
add_subdirectory(lagrange_base_gen)

if(BENCHMARKS)
add_subdirectory(benchmark)
endif()

include(GNUInstallDirs)

if(WASM)
# Well, this is awkward. We can't build a wasm module by just linking to the libraries as that produces, nothing.
# There are a couple of other ways to avoiding listing all the object files here and leveraging the dependency
# tree, but they come with the problem that they will import the 'env' object files. We explicitly want to avoid
# that as functions in 'env' should be implemented in JS itself.
# It turns out that just explicitly telling the wasm module which object files to include was easiest.
add_executable(
barretenberg-step1.wasm
barretenberg.wasm
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
@@ -97,22 +100,28 @@ if(WASM)
# Presumably the -O3 when compiling the object files is fine as it's llvms IR optimiser.
# The backend optimiser is presumably triggered after linking.
target_link_options(
barretenberg-step1.wasm
barretenberg.wasm
PRIVATE
-nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
)

find_program(WASM_OPT wasm-opt)

if(NOT WASM_OPT)
message(FATAL_ERROR "wasm-opt executable not found. Please install binaryen.")
endif()

add_custom_command(
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm
COMMAND wasm-opt ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg-step1.wasm -O2 --asyncify -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm
DEPENDS barretenberg-step1.wasm
TARGET barretenberg.wasm
POST_BUILD
COMMAND wasm-opt "$<TARGET_FILE:barretenberg.wasm>" -O2 --asyncify -o "$<TARGET_FILE:barretenberg.wasm>"
VERBATIM
)

add_custom_target(
barretenberg.wasm
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm
)
if(INSTALL_BARRETENBERG)
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# For use when compiling dependent cpp projects for WASM
message(STATUS "Compiling all-in-one barretenberg WASM archive")
add_library(
@@ -145,7 +154,6 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
)

else()
# For use when compiling dependent cpp projects
message(STATUS "Compiling all-in-one barretenberg archive")
@@ -180,4 +188,33 @@ else()
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:env_objects>
)
endif()

if(INSTALL_BARRETENBERG)
# The `install` function takes targets to install in different destinations on the system.
install(
TARGETS barretenberg barretenberg_headers
# We also give it an optional export name in case something wants to target the install.
EXPORT barretenbergTargets
# The ARCHIVE output signifies static libraries that should be installed
# and we use the GNUInstallDirs location to install into the standard system library location
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
# The FILE_SET output is used instead of PUBLIC_HEADER & PRIVATE_HEADER outputs because
# our headers don't have a clear delineation between public & private, but we still use
# the GNUInstallDirs location to install into the standard system header location
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

set(pkg_config "${PROJECT_BINARY_DIR}/barretenberg.pc")

configure_file(
"${PROJECT_SOURCE_DIR}/cmake/barretenberg.pc.in"
"${pkg_config}"
@ONLY
)

install(
FILES "${pkg_config}"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()
endif()
2 changes: 1 addition & 1 deletion cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ target_link_libraries(
honk_bench
stdlib_primitives
env
benchmark
benchmark::benchmark
)

add_custom_target(
10 changes: 5 additions & 5 deletions cpp/src/aztec/benchmark/honk_bench/compare_honk_bench.sh
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
echo -e '\nComparing Honk benchmarks between master and current branch:'
# Set some directories
BASE_DIR="$HOME/barretenberg/cpp"
BUILD_DIR="$BASE_DIR/build"
BUILD_DIR="$BASE_DIR/build-bench"
BENCH_RESULTS_DIR="$BASE_DIR/tmp_bench_results"
BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools"

@@ -22,17 +22,17 @@ mkdir $BENCH_RESULTS_DIR
# Checkout master, run honk_bench, save results in json format
echo -e '\nConfiguring and building honk_bench in master branch..'
git checkout master > /dev/null
rm -rf $BUILD_DIR && mkdir $BUILD_DIR && cd $BUILD_DIR
cmake .. > /dev/null && make honk_bench > /dev/null
rm -rf $BUILD_DIR
cmake --preset bench > /dev/null && cmake --build --preset bench --target honk_bench > /dev/null
MASTER_HONK_BENCH_RESULTS="$BENCH_RESULTS_DIR/honk_bench_results_master.json"
echo -e '\nRunning honk_bench in master..'
bin/honk_bench --benchmark_format=json > $MASTER_HONK_BENCH_RESULTS

# Checkout working branch (-), run honk_bench, save results in json format
echo -e '\nConfiguring and building honk_bench in current feature branch..'
git checkout -
rm -rf $BUILD_DIR && mkdir $BUILD_DIR && cd $BUILD_DIR
cmake .. > /dev/null && make honk_bench > /dev/null
rm -rf $BUILD_DIR
cmake --preset bench > /dev/null && cmake --build --preset bench --target honk_bench > /dev/null
BRANCH_HONK_BENCH_RESULTS="$BENCH_RESULTS_DIR/honk_bench_results_branch.json"
echo -e '\nRunning honk_bench in feature branch..'
bin/honk_bench --benchmark_format=json > $BRANCH_HONK_BENCH_RESULTS
30 changes: 13 additions & 17 deletions cpp/src/aztec/benchmark/honk_bench/honk.bench.cpp
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ void generate_test_plonk_circuit(auto& composer, size_t num_gates)
}

/**
* @brief Benchmark: Creation of an unrolled standard Honk prover
* @brief Benchmark: Creation of a Standard Honk prover
*/
void create_unrolled_prover_bench(State& state) noexcept
void create_prover_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
@@ -39,17 +39,15 @@ void create_unrolled_prover_bench(State& state) noexcept
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
state.ResumeTiming();

composer.create_unrolled_prover();
composer.create_prover();
}
}
BENCHMARK(create_unrolled_prover_bench)
->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, 1)
->Repetitions(NUM_REPETITIONS);
BENCHMARK(create_prover_bench)->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, 1)->Repetitions(NUM_REPETITIONS);

/**
* @brief Benchmark: Creation of an unrolled standard Honk verifier
* @brief Benchmark: Creation of a Standard Honk verifier
*/
void create_unrolled_verifier_bench(State& state) noexcept
void create_verifier_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
@@ -58,15 +56,13 @@ void create_unrolled_verifier_bench(State& state) noexcept
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
state.ResumeTiming();

composer.create_unrolled_verifier();
composer.create_verifier();
}
}
BENCHMARK(create_unrolled_verifier_bench)
->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, 1)
->Repetitions(NUM_REPETITIONS);
BENCHMARK(create_verifier_bench)->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, 1)->Repetitions(NUM_REPETITIONS);

/**
* @brief Benchmark: Construction of an unrolled standard Honk proof
* @brief Benchmark: Construction of a Standard Honk proof
*/
void construct_proof_bench(State& state) noexcept
{
@@ -75,7 +71,7 @@ void construct_proof_bench(State& state) noexcept
state.PauseTiming();
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
auto ext_prover = composer.create_unrolled_prover();
auto ext_prover = composer.create_prover();
state.ResumeTiming();

auto proof = ext_prover.construct_proof();
@@ -88,7 +84,7 @@ BENCHMARK(construct_proof_bench)
->Complexity(oN);

/**
* @brief Benchmark: Verification of an unrolled standard Honk proof
* @brief Benchmark: Verification of a Standard Honk proof
*/
void verify_proof_bench(State& state) noexcept
{
@@ -97,9 +93,9 @@ void verify_proof_bench(State& state) noexcept
auto num_gates = (size_t)state.range(0);
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
auto prover = composer.create_unrolled_prover();
auto prover = composer.create_prover();
auto proof = prover.construct_proof();
auto verifier = composer.create_unrolled_verifier();
auto verifier = composer.create_verifier();
state.ResumeTiming();

verifier.verify_proof(proof);
2 changes: 1 addition & 1 deletion cpp/src/aztec/benchmark/pippenger_bench/main.cpp
Original file line number Diff line number Diff line change
@@ -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<waffle::FileReferenceString>(NUM_POINTS, "../srs_db/ignition");
auto reference_string = std::make_shared<bonk::FileReferenceString>(NUM_POINTS, "../srs_db/ignition");

const auto init = []() {
small_domain = barretenberg::evaluation_domain(NUM_POINTS);
2 changes: 1 addition & 1 deletion cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ target_link_libraries(
plonk_bench
stdlib_primitives
env
benchmark
benchmark::benchmark
)

add_custom_target(
18 changes: 9 additions & 9 deletions cpp/src/aztec/benchmark/plonk_bench/plonk.bench.cpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ constexpr size_t START = (MAX_GATES) >> (NUM_CIRCUITS - 1);
// constexpr size_t MAX_HASH_ROUNDS = 8192;
// constexpr size_t START_HASH_ROUNDS = 64;

void generate_test_plonk_circuit(waffle::StandardComposer& composer, size_t num_gates)
void generate_test_plonk_circuit(plonk::StandardComposer& composer, size_t num_gates)
{
plonk::stdlib::field_t a(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element()));
plonk::stdlib::field_t b(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element()));
@@ -28,15 +28,15 @@ void generate_test_plonk_circuit(waffle::StandardComposer& composer, size_t num_
}
}

waffle::Prover provers[NUM_CIRCUITS];
waffle::Verifier verifiers[NUM_CIRCUITS];
waffle::plonk_proof proofs[NUM_CIRCUITS];
plonk::Prover provers[NUM_CIRCUITS];
plonk::Verifier verifiers[NUM_CIRCUITS];
plonk::proof proofs[NUM_CIRCUITS];

void construct_witnesses_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
waffle::StandardComposer composer = waffle::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
composer.compute_proving_key();
state.ResumeTiming();
@@ -49,13 +49,13 @@ BENCHMARK(construct_witnesses_bench)->RangeMultiplier(2)->Range(START, MAX_GATES
void construct_proving_keys_bench(State& state) noexcept
{
for (auto _ : state) {
waffle::StandardComposer composer = waffle::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
size_t idx = static_cast<size_t>(numeric::get_msb((uint64_t)state.range(0))) -
static_cast<size_t>(numeric::get_msb(START));
composer.compute_proving_key();
state.PauseTiming();
provers[idx] = composer.preprocess();
provers[idx] = composer.create_prover();
state.ResumeTiming();
}
}
@@ -65,11 +65,11 @@ void construct_instances_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
waffle::StandardComposer composer = waffle::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
size_t idx = static_cast<size_t>(numeric::get_msb((uint64_t)state.range(0))) -
static_cast<size_t>(numeric::get_msb(START));
composer.preprocess();
composer.create_prover();
state.ResumeTiming();
verifiers[idx] = composer.create_verifier();
}
10 changes: 10 additions & 0 deletions cpp/src/aztec/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Collect our common/*.hpp files and include in installation
# This is only necessary because nothing in `common/` has an
# implementation and doesn't use the `barretenberg_module` function
file(GLOB_RECURSE HEADER_FILES *.hpp)
target_sources(
barretenberg_headers
INTERFACE
FILE_SET HEADERS
FILES ${HEADER_FILES}
)
Loading

0 comments on commit 9ea1a07

Please sign in to comment.