From 136a9f444a8e62bc5fc9e2cf9dde99a3c07d5dfb Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Mon, 13 Feb 2023 11:07:07 +0000 Subject: [PATCH] Add barretenberg submodule. Change to `aztec3` branch. Compilation fixes 1. Fixes 2. More fixes. More fixes. Some more fixes. --- .clang-format | 28 +++ .gitignore | 11 ++ .gitmodules | 4 + CMakeLists.txt | 54 ++++++ barretenberg | 1 + bootstrap.sh | 57 ++++++ cmake/arch.cmake | 10 + cmake/barretenberg.cmake | 57 ++++++ cmake/benchmark.cmake | 20 ++ cmake/build.cmake | 9 + cmake/gtest.cmake | 32 ++++ cmake/module.cmake | 179 ++++++++++++++++++ cmake/threading.cmake | 38 ++++ cmake/toolchain.cmake | 10 + cmake/toolchains/arm-apple-clang.cmake | 4 + cmake/toolchains/arm64-linux-gcc.cmake | 21 ++ cmake/toolchains/i386-linux-clang.cmake | 13 ++ cmake/toolchains/wasm-linux-clang.cmake | 35 ++++ cmake/toolchains/x86_64-apple-clang.cmake | 3 + cmake/toolchains/x86_64-linux-clang.cmake | 2 + cmake/toolchains/x86_64-linux-gcc.cmake | 5 + cmake/toolchains/x86_64-linux-gcc10.cmake | 5 + format.sh | 21 ++ src/CMakeLists.txt | 32 ++++ src/aztec3/circuits/abis/.test.cpp | 22 +-- src/aztec3/circuits/abis/call_context.hpp | 3 +- .../abis/contract_deployment_data.hpp | 2 +- .../circuits/abis/function_signature.hpp | 3 +- .../abis/private_circuit_public_inputs.hpp | 2 +- src/aztec3/circuits/abis/tx_context.hpp | 2 +- src/aztec3/circuits/apps/.test.cpp | 6 +- .../apps/function_execution_context.hpp | 4 +- .../apps/notes/default_private_note/note.tpp | 4 +- .../default_private_note/note_preimage.hpp | 4 +- .../nullifier_preimage.hpp | 4 +- .../default_singleton_private_note/note.tpp | 4 +- .../note_preimage.hpp | 4 +- .../nullifier_preimage.hpp | 4 +- .../circuits/apps/private_state.test.cpp | 6 +- .../apps/state_vars/mapping_state_var.tpp | 4 +- .../apps/state_vars/state_var_base.tpp | 6 +- .../circuits/apps/test_apps/escrow/.test.cpp | 26 +-- .../circuits/apps/test_apps/escrow/init.hpp | 4 +- .../.test.cpp | 8 +- .../private_to_private_function_call/init.hpp | 4 +- src/aztec3/circuits/kernel/private/.test.cpp | 10 +- src/aztec3/circuits/kernel/private/init.hpp | 6 +- .../kernel/private/private_kernel_circuit.cpp | 10 +- .../circuits/mock/mock_kernel_circuit.hpp | 6 +- src/aztec3/circuits/recursion/aggregator.hpp | 8 +- src/aztec3/circuits/recursion/play.test.cpp | 32 ++-- .../circuits/recursion/play_app_circuit.hpp | 4 +- .../recursion/play_recursive_circuit.hpp | 14 +- src/aztec3/circuits/types/address.hpp | 153 --------------- src/aztec3/circuits/types/array.hpp | 177 ----------------- 55 files changed, 760 insertions(+), 437 deletions(-) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 160000 barretenberg create mode 100755 bootstrap.sh create mode 100644 cmake/arch.cmake create mode 100644 cmake/barretenberg.cmake create mode 100644 cmake/benchmark.cmake create mode 100644 cmake/build.cmake create mode 100644 cmake/gtest.cmake create mode 100644 cmake/module.cmake create mode 100644 cmake/threading.cmake create mode 100644 cmake/toolchain.cmake create mode 100644 cmake/toolchains/arm-apple-clang.cmake create mode 100644 cmake/toolchains/arm64-linux-gcc.cmake create mode 100644 cmake/toolchains/i386-linux-clang.cmake create mode 100644 cmake/toolchains/wasm-linux-clang.cmake create mode 100644 cmake/toolchains/x86_64-apple-clang.cmake create mode 100644 cmake/toolchains/x86_64-linux-clang.cmake create mode 100644 cmake/toolchains/x86_64-linux-gcc.cmake create mode 100644 cmake/toolchains/x86_64-linux-gcc10.cmake create mode 100755 format.sh create mode 100644 src/CMakeLists.txt delete mode 100644 src/aztec3/circuits/types/address.hpp delete mode 100644 src/aztec3/circuits/types/array.hpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000000..bcd87ae23b2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,28 @@ +PointerAlignment: Left +ColumnLimit: 120 +BreakBeforeBraces: Allman +IndentWidth: 4 +BinPackArguments: false +BinPackParameters: false +AllowShortFunctionsOnASingleLine: None +Cpp11BracedListStyle: false +AlwaysBreakAfterReturnType: None +AlwaysBreakAfterDefinitionReturnType: None +PenaltyReturnTypeOnItsOwnLine: 1000000 +BreakConstructorInitializers: BeforeComma +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +AllowShortFunctionsOnASingleLine : Inline +SortIncludes: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..3af23ba15cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.cache/ +build*/ +src/wasi-sdk-* +src/aztec/proof_system/proving_key/fixtures +src/aztec/rollup/proofs/*/fixtures +srs_db/ignition/transcript* +srs_db/lagrange +srs_db/coset_lagrange +srs_db/modified_lagrange +# to be unignored when we agree on clang-tidy rules +.clangd \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..079abe5b958 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "barretenberg"] + path = barretenberg + url = git@github.com:AztecProtocol/barretenberg.git + branch = aztec3 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..4930ba0321a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +# aztec-connect-cpp +# copyright 2019 Spilsbury Holdings Ltd + +cmake_minimum_required(VERSION 3.16) + +# Get the full path to barretenberg. This is helpful because the required +# relative path changes based on where in cmake the path is used. +# `BBERG_DIR` must be set before toolchain.cmake is imported because +# `BBERG_DIR` is used in toolchain.cmake to determine `WASI_SDK_PREFIX` +get_filename_component(BBERG_DIR ../barretenberg/cpp + REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") + +include(cmake/toolchain.cmake) + +set(PROJECT_VERSION 0.1.0) +project(Aztec3Circuits + DESCRIPTION "Project containing Aztec3 Circuits Infrastucture in C++." + LANGUAGES CXX C) + +# include barretenberg as ExternalProject +include(cmake/barretenberg.cmake) + +option(DISABLE_ASM "Disable custom assembly" OFF) +option(DISABLE_ADX "Disable ADX assembly variant" OFF) +option(MULTITHREADING "Enable multi-threading" ON) +option(TESTING "Build tests" ON) + +if(ARM) + message(STATUS "Compiling for ARM.") + set(DISABLE_ASM ON) + set(DISABLE_ADX ON) + set(RUN_HAVE_STD_REGEX 0) + set(RUN_HAVE_POSIX_REGEX 0) +endif() + +if(WASM) + message(STATUS "Compiling for WebAssembly.") + set(DISABLE_ASM ON) + set(MULTITHREADING OFF) +endif() + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS ON) + +include(cmake/build.cmake) +include(cmake/arch.cmake) +include(cmake/threading.cmake) +include(cmake/gtest.cmake) +include(cmake/module.cmake) + +add_subdirectory(src) \ No newline at end of file diff --git a/barretenberg b/barretenberg new file mode 160000 index 00000000000..e98e16cf9cf --- /dev/null +++ b/barretenberg @@ -0,0 +1 @@ +Subproject commit e98e16cf9cfdc8e5d7a8dc1fa64befdea746517d diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 00000000000..94609d44d72 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +# Update the submodule +git submodule update --init --recursive --remote + +# Clean. +rm -rf ./build +rm -rf ./build-wasm +rm -rf ./src/wasi-sdk-* + +# Clean barretenberg. +rm -rf ../barretenberg/cpp/build +rm -rf ../barretenberg/cpp/build-wasm +rm -rf ../barretenberg/cpp/src/wasi-sdk-* + +# Install formatting git hook. +HOOKS_DIR=$(git rev-parse --git-path hooks) +echo "cd \$(git rev-parse --show-toplevel) && ./format.sh staged" > $HOOKS_DIR/pre-commit +chmod +x $HOOKS_DIR/pre-commit + +# Determine system. +if [[ "$OSTYPE" == "darwin"* ]]; then + OS=macos +elif [[ "$OSTYPE" == "linux-gnu" ]]; then + OS=linux +else + echo "Unknown OS: $OSTYPE" + exit 1 +fi + +# Download ignition transcripts. +(cd barretenberg/cpp/srs_db && ./download_ignition.sh 3) + +# Pick native toolchain file. +if [ "$OS" == "macos" ]; then + export BREW_PREFIX=$(brew --prefix) + # Ensure we have toolchain. + if [ ! "$?" -eq 0 ] || [ ! -f "$BREW_PREFIX/opt/llvm/bin/clang++" ]; then + echo "Default clang not sufficient. Install homebrew, and then: brew install llvm libomp clang-format" + exit 1 + fi + ARCH=$(uname -m) + if [ "$ARCH" = "arm64" ]; then + TOOLCHAIN=arm-apple-clang + else + TOOLCHAIN=x86_64-apple-clang + fi +else + TOOLCHAIN=x86_64-linux-clang +fi + +# Build native. +mkdir -p build && cd build +cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DTOOLCHAIN=$TOOLCHAIN .. +cmake --build . --parallel ${@/#/--target } +cd .. \ No newline at end of file diff --git a/cmake/arch.cmake b/cmake/arch.cmake new file mode 100644 index 00000000000..084c0b67df8 --- /dev/null +++ b/cmake/arch.cmake @@ -0,0 +1,10 @@ +if(WASM) + # Disable SLP vectorization on WASM as it's brokenly slow. To give an idea, with this off it still takes + # 2m:18s to compile scalar_multiplication.cpp, and with it on I estimate it's 50-100 times longer. I never + # had the patience to wait it out... + add_compile_options(-fno-exceptions -fno-slp-vectorize) +endif() + +if(NOT WASM AND NOT APPLE) + add_compile_options(-march=skylake-avx512) +endif() diff --git a/cmake/barretenberg.cmake b/cmake/barretenberg.cmake new file mode 100644 index 00000000000..70854c4458e --- /dev/null +++ b/cmake/barretenberg.cmake @@ -0,0 +1,57 @@ +# Here we Set up barretenberg as an ExternalProject +# - Point to its source and build directories +# - Construct its `configure` and `build` command lines +# - include its `src/` in `search path for includes +# - Depend on specific libraries from barretenberg +# +# If barretenberg's cmake files change, its configure and build are triggered +# If barretenberg's source files change, build is triggered + +include(ExternalProject) + +if (WASM) + set(BBERG_BUILD_DIR ${BBERG_DIR}/build-wasm) +else() + set(BBERG_BUILD_DIR ${BBERG_DIR}/build) +endif() + +# If the OpenMP library is included via this option, propogate to ExternalProject configure +if (OpenMP_omp_LIBRARY) + set(LIB_OMP_OPTION -DOpenMP_omp_LIBRARY=${OpenMP_omp_LIBRARY}) +endif() + +# Make sure barretenberg doesn't set its own WASI_SDK_PREFIX +if (WASI_SDK_PREFIX) + set(WASI_SDK_OPTION -DWASI_SDK_PREFIX=${WASI_SDK_PREFIX}) +endif() + +# cmake configure cli args for ExternalProject +set(BBERG_CONFIGURE_ARGS -DTOOLCHAIN=${TOOLCHAIN} ${WASI_SDK_OPTION} ${LIB_OMP_OPTION} -DCI=${CI}) + +# Naming: Project: Barretenberg, Libraries: barretenberg, env +# Need BUILD_ALWAYS to ensure that barretenberg is automatically reconfigured when its CMake files change +# "Enabling this option forces the build step to always be run. This can be the easiest way to robustly +# ensure that the external project's own build dependencies are evaluated rather than relying on the +# default success timestamp-based method." - https://cmake.org/cmake/help/latest/module/ExternalProject.html +ExternalProject_Add(Barretenberg + SOURCE_DIR ${BBERG_DIR} + BINARY_DIR ${BBERG_BUILD_DIR} # build directory + BUILD_ALWAYS TRUE + UPDATE_COMMAND "" + INSTALL_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_COMMAND} ${BBERG_CONFIGURE_ARGS} .. + BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel --target barretenberg --target env) + +include_directories(${BBERG_DIR}/src/aztec) + +# Add the imported barretenberg and env libraries, point to their library archives, +# and add a dependency of these libraries on the imported project +add_library(barretenberg STATIC IMPORTED) +set_target_properties(barretenberg PROPERTIES IMPORTED_LOCATION ${BBERG_BUILD_DIR}/lib/libbarretenberg.a) +add_dependencies(barretenberg Barretenberg) + +# env is needed for logstr in native executables and wasm tests +# It is otherwise omitted from wasm to prevent use of C++ logstr instead of imported/Typescript +add_library(env STATIC IMPORTED) +set_target_properties(env PROPERTIES IMPORTED_LOCATION ${BBERG_BUILD_DIR}/lib/libenv.a) +add_dependencies(env Barretenberg) \ No newline at end of file diff --git a/cmake/benchmark.cmake b/cmake/benchmark.cmake new file mode 100644 index 00000000000..889ddbbee0a --- /dev/null +++ b/cmake/benchmark.cmake @@ -0,0 +1,20 @@ +if(NOT TESTING) + set(BENCHMARKS OFF) +endif() + +if(BENCHMARKS) + include(FetchContent) + + FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark + GIT_TAG v1.6.1 + ) + + FetchContent_GetProperties(benchmark) + if(NOT benchmark_POPULATED) + fetchcontent_populate(benchmark) + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") + add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() +endif() diff --git a/cmake/build.cmake b/cmake/build.cmake new file mode 100644 index 00000000000..3eb2eddd060 --- /dev/null +++ b/cmake/build.cmake @@ -0,0 +1,9 @@ +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) +endif() +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") + +if(CMAKE_BUILD_TYPE STREQUAL "RelWithAssert") + add_compile_options(-O3) + remove_definitions(-DNDEBUG) +endif() \ No newline at end of file diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake new file mode 100644 index 00000000000..4ba7cf66b70 --- /dev/null +++ b/cmake/gtest.cmake @@ -0,0 +1,32 @@ +if(TESTING) + include(GoogleTest) + include(FetchContent) + + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.10.0 + ) + + FetchContent_GetProperties(googletest) + if(NOT googletest_POPULATED) + FetchContent_Populate(googletest) + add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() + + if(WASM) + target_compile_definitions( + gtest + PRIVATE + -DGTEST_HAS_EXCEPTIONS=0 + -DGTEST_HAS_STREAM_REDIRECTION=0) + endif() + + mark_as_advanced( + BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS + gmock_build_tests gtest_build_samples gtest_build_tests + gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols + ) + + enable_testing() +endif() diff --git a/cmake/module.cmake b/cmake/module.cmake new file mode 100644 index 00000000000..5be976d4e44 --- /dev/null +++ b/cmake/module.cmake @@ -0,0 +1,179 @@ +# copyright 2019 Spilsbury Holdings +# +# usage: barretenberg_module(module_name [dependencies ...]) +# +# Scans for all .cpp files in a subdirectory, and creates a library named . +# Scans for all .test.cpp files in a subdirectory, and creates a gtest binary named _tests. +# Scans for all .bench.cpp files in a subdirectory, and creates a benchmark binary named _bench. +# +# We have to get a bit complicated here, due to the fact CMake will not parallelise the building of object files +# between dependent targets, due to the potential of post-build code generation steps etc. +# To work around this, we create "object libraries" containing the object files. +# Then we declare executables/libraries that are to be built from these object files. +# These assets will only be linked as their dependencies complete, but we can parallelise the compilation at least. + +function(barretenberg_module MODULE_NAME) + file(GLOB_RECURSE SOURCE_FILES *.cpp) + file(GLOB_RECURSE HEADER_FILES *.hpp) + list(FILTER SOURCE_FILES EXCLUDE REGEX ".*\.(fuzzer|test|bench).cpp$") + + if(SOURCE_FILES) + add_library( + ${MODULE_NAME}_objects + OBJECT + ${SOURCE_FILES} + ) + + add_library( + ${MODULE_NAME} + STATIC + $ + ) + + target_link_libraries( + ${MODULE_NAME} + PUBLIC + ${ARGN} + barretenberg + ${TBB_IMPORTED_TARGETS} + ) + + set(MODULE_LINK_NAME ${MODULE_NAME}) + endif() + + file(GLOB_RECURSE TEST_SOURCE_FILES *.test.cpp) + if(TESTING AND TEST_SOURCE_FILES) + add_library( + ${MODULE_NAME}_test_objects + OBJECT + ${TEST_SOURCE_FILES} + ) + + target_link_libraries( + ${MODULE_NAME}_test_objects + PRIVATE + gtest + barretenberg + env + ${TBB_IMPORTED_TARGETS} + ) + + add_executable( + ${MODULE_NAME}_tests + $ + ) + + if(WASM) + target_link_options( + ${MODULE_NAME}_tests + PRIVATE + -Wl,-z,stack-size=8388608 + ) + endif() + + if(CI) + target_compile_definitions( + ${MODULE_NAME}_test_objects + PRIVATE + -DCI=1 + ) + endif() + + if(DISABLE_HEAVY_TESTS) + target_compile_definitions( + ${MODULE_NAME}_test_objects + PRIVATE + -DDISABLE_HEAVY_TESTS=1 + ) + endif() + + target_link_libraries( + ${MODULE_NAME}_tests + PRIVATE + ${MODULE_LINK_NAME} + ${ARGN} + gtest + gtest_main + barretenberg + env + ${TBB_IMPORTED_TARGETS} + ) + + if(NOT WASM AND NOT CI) + # Currently haven't found a way to easily wrap the calls in wasmtime when run from ctest. + gtest_discover_tests(${MODULE_NAME}_tests WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + endif() + + add_custom_target( + run_${MODULE_NAME}_tests + COMMAND ${MODULE_NAME}_tests + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + endif() + + file(GLOB_RECURSE FUZZERS_SOURCE_FILES *.fuzzer.cpp) + if(FUZZING AND FUZZERS_SOURCE_FILES) + foreach(FUZZER_SOURCE_FILE ${FUZZERS_SOURCE_FILES}) + get_filename_component(FUZZER_NAME_STEM ${FUZZER_SOURCE_FILE} NAME_WE) + add_executable( + ${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer + ${FUZZER_SOURCE_FILE} + ) + + target_link_options( + ${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer + PRIVATE + "-fsanitize=fuzzer" + ${SANITIZER_OPTIONS} + ) + + target_link_libraries( + ${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer + PRIVATE + ${MODULE_LINK_NAME} + barretenberg + env + ) + endforeach() + endif() + + file(GLOB_RECURSE BENCH_SOURCE_FILES *.bench.cpp) + if(BENCHMARKS AND BENCH_SOURCE_FILES) + add_library( + ${MODULE_NAME}_bench_objects + OBJECT + ${BENCH_SOURCE_FILES} + ) + + target_link_libraries( + ${MODULE_NAME}_bench_objects + PRIVATE + benchmark + barretenberg + env + ${TBB_IMPORTED_TARGETS} + ) + + add_executable( + ${MODULE_NAME}_bench + $ + ) + + target_link_libraries( + ${MODULE_NAME}_bench + PRIVATE + ${MODULE_LINK_NAME} + ${ARGN} + benchmark + barretenberg + env + ${TBB_IMPORTED_TARGETS} + ) + + add_custom_target( + run_${MODULE_NAME}_bench + COMMAND ${MODULE_NAME}_bench + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + endif() +endfunction() \ No newline at end of file diff --git a/cmake/threading.cmake b/cmake/threading.cmake new file mode 100644 index 00000000000..f91b86b3853 --- /dev/null +++ b/cmake/threading.cmake @@ -0,0 +1,38 @@ +if(APPLE) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + set(OpenMP_C_FLAGS "-fopenmp") + set(OpenMP_C_FLAGS_WORK "-fopenmp") + set(OpenMP_C_LIB_NAMES "libomp") + set(OpenMP_C_LIB_NAMES_WORK "libomp") + set(OpenMP_libomp_LIBRARY "$ENV{BREW_PREFIX}/opt/libomp/lib/libomp.dylib") + endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(OpenMP_CXX_FLAGS "-fopenmp") + set(OpenMP_CXX_FLAGS_WORK "-fopenmp") + set(OpenMP_CXX_LIB_NAMES "libomp") + set(OpenMP_CXX_LIB_NAMES_WORK "libomp") + set(OpenMP_libomp_LIBRARY "$ENV{BREW_PREFIX}/opt/libomp/lib/libomp.dylib") + endif() +endif() + +if(MULTITHREADING) + find_package(OpenMP REQUIRED) + message(STATUS "Multithreading is enabled.") + link_libraries(OpenMP::OpenMP_CXX) +else() + message(STATUS "Multithreading is disabled.") + add_definitions(-DNO_MULTITHREADING -DBOOST_SP_NO_ATOMIC_ACCESS) +endif() + +if(DISABLE_TBB) + message(STATUS "Intel Thread Building Blocks is disabled.") + add_definitions(-DNO_TBB) +else() + find_package(TBB REQUIRED tbb) + if(${TBB_FOUND}) + message(STATUS "Intel Thread Building Blocks is enabled.") + else() + message(STATUS "Could not locate TBB.") + add_definitions(-DNO_TBB) + endif() +endif() diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake new file mode 100644 index 00000000000..4de860fac49 --- /dev/null +++ b/cmake/toolchain.cmake @@ -0,0 +1,10 @@ +if (CMAKE_C_COMPILER AND CMAKE_CXX_COMPILER) + message(STATUS "Toolchain: manually chosen ${CMAKE_C_COMPILER} and ${CMAKE_CXX_COMPILER}") +else() + if(NOT TOOLCHAIN) + set(TOOLCHAIN "x86_64-linux-clang" CACHE STRING "Build toolchain." FORCE) + endif() + message(STATUS "Toolchain: ${TOOLCHAIN}") + + include("./cmake/toolchains/${TOOLCHAIN}.cmake") +endif() \ No newline at end of file diff --git a/cmake/toolchains/arm-apple-clang.cmake b/cmake/toolchains/arm-apple-clang.cmake new file mode 100644 index 00000000000..1b451ab08d5 --- /dev/null +++ b/cmake/toolchains/arm-apple-clang.cmake @@ -0,0 +1,4 @@ +set(APPLE ON) +set(ARM ON) +set(CMAKE_CXX_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang++") +set(CMAKE_C_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang") \ No newline at end of file diff --git a/cmake/toolchains/arm64-linux-gcc.cmake b/cmake/toolchains/arm64-linux-gcc.cmake new file mode 100644 index 00000000000..bc8bd0b8028 --- /dev/null +++ b/cmake/toolchains/arm64-linux-gcc.cmake @@ -0,0 +1,21 @@ +set(ARM ON) +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(cross_triple "aarch64-unknown-linux-gnu") +set(cross_root /usr/xcc/${cross_triple}) + +set(CMAKE_C_COMPILER $ENV{CC}) +set(CMAKE_CXX_COMPILER $ENV{CXX}) +set(CMAKE_Fortran_COMPILER $ENV{FC}) + +set(CMAKE_CXX_FLAGS "-I ${cross_root}/include/") + +set(CMAKE_FIND_ROOT_PATH ${cross_root} ${cross_root}/${cross_triple}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) +set(CMAKE_SYSROOT ${cross_root}/${cross_triple}/sysroot) + +set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-aarch64) \ No newline at end of file diff --git a/cmake/toolchains/i386-linux-clang.cmake b/cmake/toolchains/i386-linux-clang.cmake new file mode 100644 index 00000000000..acbdb3d47e1 --- /dev/null +++ b/cmake/toolchains/i386-linux-clang.cmake @@ -0,0 +1,13 @@ +# Sometimes we need to set compilers manually, for example for fuzzing +if(NOT CMAKE_C_COMPILER) + set(CMAKE_C_COMPILER "clang") +endif() + +if(NOT CMAKE_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "clang++") +endif() + +add_compile_options("-m32") +add_link_options("-m32") +set(MULTITHREADING OFF) +add_definitions(-DDISABLE_SHENANIGANS=1) \ No newline at end of file diff --git a/cmake/toolchains/wasm-linux-clang.cmake b/cmake/toolchains/wasm-linux-clang.cmake new file mode 100644 index 00000000000..f8e7796ff57 --- /dev/null +++ b/cmake/toolchains/wasm-linux-clang.cmake @@ -0,0 +1,35 @@ +# Cmake toolchain description file for the Makefile + +# This is arbitrary, AFAIK, for now. +cmake_minimum_required(VERSION 3.4.0) + +set(WASM ON) +set(CMAKE_SYSTEM_NAME Generic) +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") +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") +set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib CACHE STRING "wasi-sdk build") +set(CMAKE_C_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") +set(CMAKE_CXX_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") +#set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-threads" CACHE STRING "wasi-sdk build") + +set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") +set(CMAKE_STAGING_PREFIX ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") + +# Don't look in the sysroot for executables to run during the build +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# Only look in the sysroot (not in the host paths) for the rest +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +# Some other hacks +set(CMAKE_C_COMPILER_WORKS ON) +set(CMAKE_CXX_COMPILER_WORKS ON) + +add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS=1) \ No newline at end of file diff --git a/cmake/toolchains/x86_64-apple-clang.cmake b/cmake/toolchains/x86_64-apple-clang.cmake new file mode 100644 index 00000000000..35440991b94 --- /dev/null +++ b/cmake/toolchains/x86_64-apple-clang.cmake @@ -0,0 +1,3 @@ +set(APPLE ON) +set(CMAKE_CXX_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang++") +set(CMAKE_C_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang") \ No newline at end of file diff --git a/cmake/toolchains/x86_64-linux-clang.cmake b/cmake/toolchains/x86_64-linux-clang.cmake new file mode 100644 index 00000000000..7df84b7c037 --- /dev/null +++ b/cmake/toolchains/x86_64-linux-clang.cmake @@ -0,0 +1,2 @@ +set(CMAKE_C_COMPILER "clang") +set(CMAKE_CXX_COMPILER "clang++") \ No newline at end of file diff --git a/cmake/toolchains/x86_64-linux-gcc.cmake b/cmake/toolchains/x86_64-linux-gcc.cmake new file mode 100644 index 00000000000..9cd8af83f78 --- /dev/null +++ b/cmake/toolchains/x86_64-linux-gcc.cmake @@ -0,0 +1,5 @@ +set(CMAKE_C_COMPILER "gcc") +set(CMAKE_CXX_COMPILER "g++") +# TODO(Cody): git rid of this when Adrian's work goes in +add_compile_options(-Wno-uninitialized) +add_compile_options(-Wno-maybe-uninitialized) \ No newline at end of file diff --git a/cmake/toolchains/x86_64-linux-gcc10.cmake b/cmake/toolchains/x86_64-linux-gcc10.cmake new file mode 100644 index 00000000000..36fdcfacc85 --- /dev/null +++ b/cmake/toolchains/x86_64-linux-gcc10.cmake @@ -0,0 +1,5 @@ +set(CMAKE_C_COMPILER "gcc-10") +set(CMAKE_CXX_COMPILER "g++-10") +# TODO(Cody): git rid of this when Adrian's work goes in +add_compile_options(-Wno-uninitialized) +add_compile_options(-Wno-maybe-uninitialized) \ No newline at end of file diff --git a/format.sh b/format.sh new file mode 100755 index 00000000000..0b6ce3b9215 --- /dev/null +++ b/format.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +if [ "$1" == "staged" ]; then + echo Formatting staged files... + for FILE in $(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do + clang-format -i $FILE + sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak + git add $FILE + done +elif [ -n "$1" ]; then + for FILE in $(git diff-index --relative --name-only $1 | grep -e '\.\(cpp\|hpp\|tcc\)$'); do + clang-format -i $FILE + sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak + done +else + for FILE in $(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/boost); do + clang-format -i $FILE + sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak + done +fi \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000000..a694ab8909a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,32 @@ +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wno-deprecated -Wno-tautological-compare -Wfatal-errors) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-unguarded-availability-new -Wno-c99-extensions -fconstexpr-steps=100000000) + if(MEMORY_CHECKS) + message(STATUS "Compiling with memory checks.") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + endif() +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options(-Wno-deprecated-copy -fconstexpr-ops-limit=100000000) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +# I feel this should be limited to ecc, however it's currently used in headers that go across libraries, +# and there currently isn't an easy way to inherit the DDISABLE_SHENANIGANS parameter. +if(DISABLE_ASM) + message(STATUS "Using fallback non-assembly methods for field multiplications.") + add_definitions(-DDISABLE_SHENANIGANS=1) +else() + message(STATUS "Using optimized assembly for field arithmetic.") +endif() + +add_subdirectory(aztec3) + +if(BENCHMARKS) + add_subdirectory(benchmark) +endif() \ No newline at end of file diff --git a/src/aztec3/circuits/abis/.test.cpp b/src/aztec3/circuits/abis/.test.cpp index beefe7d42cd..3f72992f962 100644 --- a/src/aztec3/circuits/abis/.test.cpp +++ b/src/aztec3/circuits/abis/.test.cpp @@ -3,12 +3,12 @@ #include // #include #include "index.hpp" -#include +#include namespace aztec3::circuits::abis { -using TurboComposer = plonk::stdlib::types::turbo::Composer; -using CT = plonk::stdlib::types::CircuitTypes; +using Composer = plonk::stdlib::types::Composer; +using CT = plonk::stdlib::types::CircuitTypes; using NT = plonk::stdlib::types::NativeTypes; class abi_tests : public ::testing::Test {}; @@ -39,8 +39,8 @@ TEST(abi_tests, test_native_to_circuit_function_signature) info("function signature: ", native_function_signature); - TurboComposer turbo_composer; - FunctionSignature circuit_function_signature = native_function_signature.to_circuit_type(turbo_composer); + Composer composer; + FunctionSignature circuit_function_signature = native_function_signature.to_circuit_type(composer); info("function signature: ", circuit_function_signature); } @@ -70,8 +70,8 @@ TEST(abi_tests, test_native_to_circuit_call_context) info("call context: ", native_call_context); - TurboComposer turbo_composer; - CallContext circuit_call_context = native_call_context.to_circuit_type(turbo_composer); + Composer composer; + CallContext circuit_call_context = native_call_context.to_circuit_type(composer); info("call context: ", circuit_call_context); } @@ -109,8 +109,8 @@ TEST(abi_tests, test_native_to_circuit_call_context) // info("public_circuit_public_inputs: ", native_public_inputs); -// TurboComposer turbo_composer; -// PublicCircuitPublicInputs circuit_public_inputs = native_public_inputs.to_circuit_type(turbo_composer); +// Composer composer; +// PublicCircuitPublicInputs circuit_public_inputs = native_public_inputs.to_circuit_type(composer); // info("public_circuit_public_inputs: ", circuit_public_inputs); // } @@ -180,9 +180,9 @@ TEST(abi_tests, test_native_to_circuit_call_context) // info("call stack item: ", native_call_stack_item); -// TurboComposer turbo_composer; +// Composer composer; // CallStackItem circuit_call_stack_item = -// native_call_stack_item.to_circuit_type(turbo_composer); +// native_call_stack_item.to_circuit_type(composer); // info("call stack item: ", circuit_call_stack_item); // } diff --git a/src/aztec3/circuits/abis/call_context.hpp b/src/aztec3/circuits/abis/call_context.hpp index f6ac5031eeb..2fb2a3c9f73 100644 --- a/src/aztec3/circuits/abis/call_context.hpp +++ b/src/aztec3/circuits/abis/call_context.hpp @@ -1,11 +1,12 @@ #pragma once -#include +#include #include #include #include #include #include +#include namespace aztec3::circuits::abis { diff --git a/src/aztec3/circuits/abis/contract_deployment_data.hpp b/src/aztec3/circuits/abis/contract_deployment_data.hpp index 990bbac885b..852defd81aa 100644 --- a/src/aztec3/circuits/abis/contract_deployment_data.hpp +++ b/src/aztec3/circuits/abis/contract_deployment_data.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include #include diff --git a/src/aztec3/circuits/abis/function_signature.hpp b/src/aztec3/circuits/abis/function_signature.hpp index 069f9eda68a..08e2300c817 100644 --- a/src/aztec3/circuits/abis/function_signature.hpp +++ b/src/aztec3/circuits/abis/function_signature.hpp @@ -1,10 +1,11 @@ #pragma once -#include +#include #include #include #include #include #include +#include namespace aztec3::circuits::abis { diff --git a/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index b90eeb09e31..1ff8d1f24ad 100644 --- a/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/aztec3/circuits/abis/tx_context.hpp b/src/aztec3/circuits/abis/tx_context.hpp index 6a65bbd9206..cc8b3630dcd 100644 --- a/src/aztec3/circuits/abis/tx_context.hpp +++ b/src/aztec3/circuits/abis/tx_context.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace aztec3::circuits::abis { diff --git a/src/aztec3/circuits/apps/.test.cpp b/src/aztec3/circuits/apps/.test.cpp index 894a202c34f..cfeb5ef3d08 100644 --- a/src/aztec3/circuits/apps/.test.cpp +++ b/src/aztec3/circuits/apps/.test.cpp @@ -1,6 +1,6 @@ // #include -// #include +// #include // #include #include @@ -31,11 +31,11 @@ #include #include #include -#include +#include namespace { // Composer -using C = plonk::stdlib::types::turbo::Composer; +using C = plonk::stdlib::types::Composer; // Types using CT = plonk::stdlib::types::CircuitTypes; diff --git a/src/aztec3/circuits/apps/function_execution_context.hpp b/src/aztec3/circuits/apps/function_execution_context.hpp index 9ba270bfd5f..276eff1087a 100644 --- a/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/src/aztec3/circuits/apps/function_execution_context.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include @@ -30,7 +30,7 @@ using aztec3::circuits::abis::PrivateCircuitPublicInputs; using aztec3::circuits::apps::notes::NoteInterface; using aztec3::circuits::apps::opcodes::Opcodes; -using aztec3::circuits::types::array_push; +using plonk::stdlib::array_push; using plonk::stdlib::witness_t; using plonk::stdlib::types::CircuitTypes; diff --git a/src/aztec3/circuits/apps/notes/default_private_note/note.tpp b/src/aztec3/circuits/apps/notes/default_private_note/note.tpp index 15910a85b58..3c614eb9cdd 100644 --- a/src/aztec3/circuits/apps/notes/default_private_note/note.tpp +++ b/src/aztec3/circuits/apps/notes/default_private_note/note.tpp @@ -8,7 +8,7 @@ #include "../../state_vars/state_var_base.hpp" -#include +#include #include @@ -28,7 +28,7 @@ namespace aztec3::circuits::apps::notes { using aztec3::GeneratorIndex; -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::witness_t; using plonk::stdlib::types::CircuitTypes; diff --git a/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index 80ba1e87951..519bf02dc00 100644 --- a/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -11,7 +11,7 @@ namespace aztec3::circuits::apps::notes { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; using plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp b/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp index fac86d2e520..e40478c2faf 100644 --- a/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp +++ b/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -10,7 +10,7 @@ namespace aztec3::circuits::apps::notes { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; using plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp b/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp index d7dc68447dc..6d93efa868a 100644 --- a/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp +++ b/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp @@ -8,7 +8,7 @@ #include "../../state_vars/state_var_base.hpp" -#include +#include #include @@ -28,7 +28,7 @@ namespace aztec3::circuits::apps::notes { using aztec3::GeneratorIndex; -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::witness_t; using plonk::stdlib::types::CircuitTypes; diff --git a/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp b/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp index 5811654565c..884adffb96f 100644 --- a/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp +++ b/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -11,7 +11,7 @@ namespace aztec3::circuits::apps::notes { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; using plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp b/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp index 64c5be51c2d..89de5176b70 100644 --- a/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp +++ b/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -10,7 +10,7 @@ namespace aztec3::circuits::apps::notes { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; using plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/private_state.test.cpp b/src/aztec3/circuits/apps/private_state.test.cpp index 7d8859991ea..e54251ad79b 100644 --- a/src/aztec3/circuits/apps/private_state.test.cpp +++ b/src/aztec3/circuits/apps/private_state.test.cpp @@ -4,7 +4,7 @@ // #include // #include // // #include -// #include +// #include // // #include // // #include // // #include @@ -12,8 +12,8 @@ // namespace aztec3::circuits::apps { // namespace { -// using TurboComposer = plonk::stdlib::types::turbo::Composer; -// using CT = plonk::stdlib::types::CircuitTypes; +// using Composer = plonk::stdlib::types::Composer; +// using CT = plonk::stdlib::types::CircuitTypes; // using NT = plonk::stdlib::types::NativeTypes; // // using plonk::stdlib::pedersen; // } // namespace diff --git a/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp b/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp index 0f596cf4f69..f60a29bd020 100644 --- a/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp +++ b/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ using aztec3::circuits::apps::FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; using plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/state_vars/state_var_base.tpp b/src/aztec3/circuits/apps/state_vars/state_var_base.tpp index 14bd20dcc8e..d6db3ec3076 100644 --- a/src/aztec3/circuits/apps/state_vars/state_var_base.tpp +++ b/src/aztec3/circuits/apps/state_vars/state_var_base.tpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include @@ -15,7 +15,7 @@ using aztec3::circuits::apps::FunctionExecutionContext; namespace aztec3::circuits::apps::state_vars { -using crypto::pedersen::generator_index_t; +using crypto::generators::generator_index_t; using plonk::stdlib::types::CircuitTypes; template @@ -33,6 +33,6 @@ template typename CircuitTypes::grumpkin_point Sta return CT::commit({ start_slot }, { StorageSlotGeneratorIndex::BASE_SLOT }); } -// template class PrivateStateVar; +// template class PrivateStateVar; }; // namespace aztec3::circuits::apps::state_vars diff --git a/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp b/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp index ec2cc6520f0..3b7f290d210 100644 --- a/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp +++ b/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp @@ -9,7 +9,7 @@ #include #include // #include -// #include +// #include // #include namespace aztec3::circuits::apps::test_apps::escrow { @@ -63,12 +63,12 @@ TEST_F(escrow_tests, test_deposit) info("result: ", result); info("computed witness: ", composer.computed_witness); - info("witness: ", composer.witness); + // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.failed); - info("err: ", composer.err); - info("n: ", composer.n); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } TEST_F(escrow_tests, test_transfer) @@ -89,12 +89,12 @@ TEST_F(escrow_tests, test_transfer) transfer(exec_ctx, amount, to, asset_id, memo, reveal_msg_sender_to_recipient, fee); info("computed witness: ", composer.computed_witness); - info("witness: ", composer.witness); + // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.failed); - info("err: ", composer.err); - info("n: ", composer.n); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } TEST_F(escrow_tests, test_withdraw) @@ -114,12 +114,12 @@ TEST_F(escrow_tests, test_withdraw) withdraw(exec_ctx, amount, asset_id, memo, l1_withdrawal_address, fee); info("computed witness: ", composer.computed_witness); - info("witness: ", composer.witness); + // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.failed); - info("err: ", composer.err); - info("n: ", composer.n); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } } // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index be7748cee22..8f7542d9c15 100644 --- a/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -9,14 +9,14 @@ #include #include -#include +#include #include #include #include namespace aztec3::circuits::apps::test_apps::escrow { -using C = plonk::stdlib::types::turbo::Composer; +using C = plonk::stdlib::types::Composer; using CT = plonk::stdlib::types::CircuitTypes; using NT = plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp b/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp index c855ea4c5bb..4ce15538b60 100644 --- a/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp +++ b/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp @@ -56,12 +56,12 @@ TEST(private_to_private_function_call_tests, test_private_to_private_function_ca info("function_1_1_public_inputs: ", function_1_1_public_inputs); info("computed witness: ", fn1_composer.computed_witness); - info("witness: ", fn1_composer.witness); + // info("witness: ", fn1_composer.witness); // info("constant variables: ", fn1_composer.constant_variables); // info("variables: ", fn1_composer.variables); - info("failed?: ", fn1_composer.failed); - info("err: ", fn1_composer.err); - info("n: ", fn1_composer.n); + info("failed?: ", fn1_composer.failed()); + info("err: ", fn1_composer.err()); + info("n: ", fn1_composer.num_gates); } } // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index 612ec902ada..348ce4c3e47 100644 --- a/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -8,14 +8,14 @@ #include -#include +#include #include #include #include namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { -using C = plonk::stdlib::types::turbo::Composer; +using C = plonk::stdlib::types::Composer; using CT = plonk::stdlib::types::CircuitTypes; using NT = plonk::stdlib::types::NativeTypes; diff --git a/src/aztec3/circuits/kernel/private/.test.cpp b/src/aztec3/circuits/kernel/private/.test.cpp index 1a1db3165a4..2d53e4f98ff 100644 --- a/src/aztec3/circuits/kernel/private/.test.cpp +++ b/src/aztec3/circuits/kernel/private/.test.cpp @@ -1,5 +1,5 @@ // #include -// #include +// #include // #include // #include // #include @@ -247,15 +247,15 @@ TEST(private_kernel_tests, test_deposit) private_kernel_circuit(private_kernel_composer, private_inputs); info("computed witness: ", private_kernel_composer.computed_witness); - info("witness: ", private_kernel_composer.witness); + // info("witness: ", private_kernel_composer.witness); // info("constant variables: ", private_kernel_composer.constant_variables); // info("variables: ", private_kernel_composer.variables); // TODO: this fails intermittently, with: // bigfield multiply range check failed - info("failed?: ", private_kernel_composer.failed); - info("err: ", private_kernel_composer.err); - info("n: ", private_kernel_composer.n); + info("failed?: ", private_kernel_composer.failed()); + info("err: ", private_kernel_composer.err()); + info("n: ", private_kernel_composer.num_gates); } } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/src/aztec3/circuits/kernel/private/init.hpp b/src/aztec3/circuits/kernel/private/init.hpp index 0de9fc6ecfd..ddd4e89a5cf 100644 --- a/src/aztec3/circuits/kernel/private/init.hpp +++ b/src/aztec3/circuits/kernel/private/init.hpp @@ -7,7 +7,7 @@ #include -#include +#include #include #include #include @@ -15,8 +15,8 @@ namespace aztec3::circuits::kernel::private_kernel { // Turbo specific, at the moment: -using Composer = plonk::stdlib::types::turbo::Composer; -using plonk::stdlib::types::turbo::UnrolledProver; +using Composer = plonk::stdlib::types::Composer; +using plonk::stdlib::types::UnrolledProver; using Aggregator = aztec3::circuits::recursion::TurboAggregator; diff --git a/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index 20b89a90fee..26b8eb15b33 100644 --- a/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -1,6 +1,6 @@ #include "init.hpp" -#include +#include #include #include @@ -10,10 +10,10 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::private_kernel::PrivateInputs; using aztec3::circuits::abis::private_kernel::PublicInputs; -using aztec3::circuits::types::array_length; -using aztec3::circuits::types::array_pop; -using aztec3::circuits::types::is_array_empty; -using aztec3::circuits::types::push_array_to_array; +using plonk::stdlib::array_length; +using plonk::stdlib::array_pop; +using plonk::stdlib::is_array_empty; +using plonk::stdlib::push_array_to_array; // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // private_call.call_stack_item.public_inputs! diff --git a/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index a35698c76b8..4b02cc308d7 100644 --- a/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -12,7 +12,7 @@ namespace aztec3::circuits::mock { using aztec3::circuits::abis::private_kernel::PublicInputs; using NT = plonk::stdlib::types::NativeTypes; -using plonk::stdlib::pedersen; +using plonk::stdlib::pedersen_commitment; using plonk::stdlib::witness_t; using plonk::stdlib::types::CircuitTypes; @@ -36,7 +36,7 @@ template void mock_kernel_circuit(Composer& composer, Public public_inputs.set_public(); - plonk::stdlib::pedersen::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); + plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); } } // namespace aztec3::circuits::mock diff --git a/src/aztec3/circuits/recursion/aggregator.hpp b/src/aztec3/circuits/recursion/aggregator.hpp index cb4569afbc2..279fe0673a9 100644 --- a/src/aztec3/circuits/recursion/aggregator.hpp +++ b/src/aztec3/circuits/recursion/aggregator.hpp @@ -1,9 +1,9 @@ -#include +#include #include #include #include #include -#include +#include namespace aztec3::circuits::recursion { @@ -12,8 +12,8 @@ namespace aztec3::circuits::recursion { using plonk::stdlib::recursion::recursive_turbo_verifier_settings; // using plonk::stdlib::recursion::verification_key; using plonk::stdlib::recursion::verify_proof; -// using plonk::stdlib::types::turbo::bn254; -using plonk::stdlib::types::turbo::Composer; +// using plonk::stdlib::types::bn254; +using plonk::stdlib::types::Composer; using CT = plonk::stdlib::types::CircuitTypes; using NT = plonk::stdlib::types::NativeTypes; using transcript::Manifest; diff --git a/src/aztec3/circuits/recursion/play.test.cpp b/src/aztec3/circuits/recursion/play.test.cpp index 2ecf23cee4c..337b21da132 100644 --- a/src/aztec3/circuits/recursion/play.test.cpp +++ b/src/aztec3/circuits/recursion/play.test.cpp @@ -1,11 +1,11 @@ #include "index.hpp" #include // #include -#include +#include namespace aztec3::circuits::recursion { -using namespace plonk::stdlib::types::turbo; +using namespace plonk::stdlib::types; using plonk::stdlib::recursion::recursion_output; // namespace { @@ -36,8 +36,8 @@ TEST(play_tests, test_play_app_proof_gen) Composer app_composer; play_app_circuit(app_composer, 100, 200); - if (app_composer.failed) { - info("Play app circuit logic failed: ", app_composer.err); + if (app_composer.failed()) { + info("Play app circuit logic failed: ", app_composer.err()); } UnrolledProver app_prover = app_composer.create_unrolled_prover(); @@ -50,8 +50,8 @@ TEST(play_tests, test_play_recursive_proof_gen) Composer app_composer; play_app_circuit(app_composer, 1, 2); - if (app_composer.failed) { - info("Play app circuit logic failed: ", app_composer.err); + if (app_composer.failed()) { + info("Play app circuit logic failed: ", app_composer.err()); } UnrolledProver app_prover = app_composer.create_unrolled_prover(); @@ -63,8 +63,8 @@ TEST(play_tests, test_play_recursive_proof_gen) Composer recursive_composer; recursion_output recursion_output = play_recursive_circuit(recursive_composer, app_vk, app_proof); - if (recursive_composer.failed) { - info("Play recursive circuit logic failed: ", recursive_composer.err); + if (recursive_composer.failed()) { + info("Play recursive circuit logic failed: ", recursive_composer.err()); } } @@ -73,8 +73,8 @@ TEST(play_tests, test_play_recursive_2_proof_gen) Composer app_composer; play_app_circuit(app_composer, 1, 2); - if (app_composer.failed) { - info("Play app circuit logic failed: ", app_composer.err); + if (app_composer.failed()) { + info("Play app circuit logic failed: ", app_composer.err()); } UnrolledProver app_prover = app_composer.create_unrolled_prover(); @@ -86,8 +86,8 @@ TEST(play_tests, test_play_recursive_2_proof_gen) Composer dummy_circuit_composer; dummy_circuit(dummy_circuit_composer, 1, 2); - if (dummy_circuit_composer.failed) { - info("dummy_circuit logic failed: ", dummy_circuit_composer.err); + if (dummy_circuit_composer.failed()) { + info("dummy_circuit logic failed: ", dummy_circuit_composer.err()); } UnrolledProver dummy_circuit_prover = dummy_circuit_composer.create_unrolled_prover(); @@ -100,8 +100,8 @@ TEST(play_tests, test_play_recursive_2_proof_gen) recursion_output recursion_1_output = play_recursive_circuit_2(recursion_1_composer, app_vk, app_proof, dummy_circuit_vk, dummy_circuit_proof); - if (recursion_1_composer.failed) { - info("recursion_1 circuit logic failed: ", recursion_1_composer.err); + if (recursion_1_composer.failed()) { + info("recursion_1 circuit logic failed: ", recursion_1_composer.err()); } UnrolledProver recursion_1_prover = recursion_1_composer.create_unrolled_prover(); @@ -116,8 +116,8 @@ TEST(play_tests, test_play_recursive_2_proof_gen) // recursion_output recursion_2_output = play_recursive_circuit_2( // recursion_2_composer, app_vk, app_proof, recursion_1_vk, recursion_1_proof); - // if (recursion_2_composer.failed) { - // info("recursion_2 circuit logic failed: ", recursion_2_composer.err); + // if (recursion_2_composer.failed()) { + // info("recursion_2 circuit logic failed: ", recursion_2_composer.err()); // } // UnrolledProver recursion_2_prover = recursion_2_composer.create_unrolled_prover(); diff --git a/src/aztec3/circuits/recursion/play_app_circuit.hpp b/src/aztec3/circuits/recursion/play_app_circuit.hpp index b8108266da9..0c3446d6286 100644 --- a/src/aztec3/circuits/recursion/play_app_circuit.hpp +++ b/src/aztec3/circuits/recursion/play_app_circuit.hpp @@ -1,8 +1,8 @@ -#include +#include namespace aztec3::circuits::recursion { -using namespace plonk::stdlib::types::turbo; +using namespace plonk::stdlib::types; // using plonk::stdlib::recursion::recursion_output; void play_app_circuit(Composer& composer, barretenberg::fr const& a_in, barretenberg::fr const& b_in) diff --git a/src/aztec3/circuits/recursion/play_recursive_circuit.hpp b/src/aztec3/circuits/recursion/play_recursive_circuit.hpp index 6dfc80f88e1..fb56e903433 100644 --- a/src/aztec3/circuits/recursion/play_recursive_circuit.hpp +++ b/src/aztec3/circuits/recursion/play_recursive_circuit.hpp @@ -1,4 +1,4 @@ -// #include +// #include // #include // #include // #include @@ -6,7 +6,7 @@ namespace aztec3::circuits::recursion { using Aggregator = TurboAggregator; -using plonk::stdlib::types::turbo::Composer; +using plonk::stdlib::types::Composer; using CT = plonk::stdlib::types::CircuitTypes; using NT = plonk::stdlib::types::NativeTypes; @@ -43,27 +43,27 @@ CT::AggregationObject play_recursive_circuit_2(Composer& composer, std::shared_ptr app_vk_ct = CT::VK::from_witness(&composer, app_vk); std::shared_ptr prev_recursive_vk_ct = CT::VK::from_witness(&composer, prev_recursive_vk); - info("composer failed 1? ", composer.failed); + info("composer failed 1? ", composer.failed()); CT::AggregationObject aggregation_object = Aggregator::aggregate( &composer, prev_recursive_vk_ct, prev_recursive_proof, prev_recursive_vk->num_public_inputs); - info("composer failed 2? ", composer.failed); + info("composer failed 2? ", composer.failed()); info("\npublic inputs before: ", composer.public_inputs.size()); aggregation_object = Aggregator::aggregate(&composer, app_vk_ct, app_proof, app_vk->num_public_inputs, aggregation_object); info("\npublic inputs after: ", composer.public_inputs.size()); - info("composer failed 3? ", composer.failed); + info("composer failed 3? ", composer.failed()); aggregation_object.add_proof_outputs_as_public_inputs(); - info("composer failed 4? ", composer.failed); + info("composer failed 4? ", composer.failed()); info("\npublic inputs after after: ", composer.public_inputs.size()); - info("composer failed 5? ", composer.failed); + info("composer failed 5? ", composer.failed()); return aggregation_object; }; diff --git a/src/aztec3/circuits/types/address.hpp b/src/aztec3/circuits/types/address.hpp deleted file mode 100644 index 26f734b2d6d..00000000000 --- a/src/aztec3/circuits/types/address.hpp +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include "../../constants.hpp" - -namespace aztec3::circuits::types { - -using barretenberg::fr; -using numeric::uint256_t; -using plonk::stdlib::bool_t; -using plonk::stdlib::field_t; -using plonk::stdlib::group; -using plonk::stdlib::pedersen; -using plonk::stdlib::point; -using plonk::stdlib::witness_t; - -// Native type -class address { - public: - fr address_; - - address() noexcept { address_ = fr(); } - - address(address const& other) - : address_(other.address_){}; - - address(fr const& address) - : address_(address){}; - - address(uint256_t const& address) - : address_(address){}; - - address(int const& address) - : address_(fr(address)){}; - - operator fr() { return address_; } - - operator fr() const { return address_; } - - constexpr bool operator==(address const& other) const { return this->address_ == other.address_; } - - friend std::ostream& operator<<(std::ostream& os, address const& v) { return os << v.address_; } - - fr to_field() const { return address_; } -}; - -template void read(B& it, address& addr) -{ - using serialize::read; - fr address_field; - read(it, address_field); - addr = address_field; -} - -template void write(B& buf, address const& addr) -{ - using serialize::write; - write(buf, addr.address_); -} - -// Circuit type -template class address_t { - public: - field_t address_; - Composer* context_; - - address_t() = default; - - address_t(address_t const& other) - : address_(other.address_) - , context_(other.context_){}; - - address_t(field_t const& address) - : address_(address) - , context_(address.context){}; - - address_t(uint256_t const& address) - : address_(address) - , context_(nullptr){}; - - address_t(int const& address) - : address_(address) - , context_(nullptr){}; - - address_t(witness_t const& witness) - { - address_ = field_t(witness); - context_ = witness.context; - } - - address_t& operator=(const address_t& other) - { - address_ = other.address_; - context_ = other.context_; - return *this; - } - - bool_t operator==(const address_t& other) const { return this->to_field() == other.to_field(); } - - field_t to_field() const { return address_; } - - fr get_value() const { return address_.get_value(); }; - - void assert_equal(const address_t& rhs, std::string const& msg = "address_t::assert_equal") const - { - address_.assert_equal(rhs.address_, msg); - }; - - void assert_is_in_set(const std::vector& set, - std::string const& msg = "address_t::assert_is_in_set") const - { - std::vector> field_set; - for (const auto& e : set) { - field_set.push_back(e.address_); - } - address_.assert_is_in_set(field_set, msg); - } - - static address_t conditional_assign(const bool_t& predicate, const address_t& lhs, const address_t& rhs) - { - return field_t::conditional_assign(predicate, lhs.address_, rhs.address_); - }; - - static address_t derive_from_private_key(field_t const& private_key) - { - // TODO: Dummy logic, for now. Proper derivation undecided. - point public_key = group::template fixed_base_scalar_mul_g1<254>(private_key); - return address_t(public_key.x); - } - - static address_t derive_contract_address(address_t const& deployer_address, - field_t const& salt, - field_t const& vk_root, - field_t const& constructor_hash) - { - std::vector> preimage{ - deployer_address.to_field(), - salt, - vk_root, - constructor_hash, - }; - return address_ct(pedersen::compress(preimage, true, GeneratorIndex::CONTRACT_ADDRESS)); - } - - friend std::ostream& operator<<(std::ostream& os, address_t const& v) { return os << v.address_; } -}; - -} // namespace aztec3::circuits::types \ No newline at end of file diff --git a/src/aztec3/circuits/types/array.hpp b/src/aztec3/circuits/types/array.hpp deleted file mode 100644 index a1174d6f83e..00000000000 --- a/src/aztec3/circuits/types/array.hpp +++ /dev/null @@ -1,177 +0,0 @@ -#pragma once - -#include - -namespace aztec3::circuits::types { - -using plonk::stdlib::types::CircuitTypes; - -/** - * Gets the number of contiguous nonzero values of an array. - * Note: this assumes `0` always means 'not used', so be careful. If you actually want `0` to be counted, you'll need - * something else. - */ -// TODO: move to own file of helper functions. -template -typename CircuitTypes::fr array_length(std::array::fr, SIZE> const& arr) -{ - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::boolean boolean; - - fr length = 0; - boolean hit_zero = false; - for (const auto& e : arr) { - hit_zero |= e == 0; - const fr increment = !hit_zero; - length += increment; - } - return length; -}; - -/** - * Note: doesn't remove the last element from the array; only returns it! - * Note: this assumes `0` always means 'not used', so be careful. If you actually want `0` to be counted, you'll need - * something else. - * If it returns `0`, the array is considered 'empty'. - */ -template -typename CircuitTypes::fr array_pop(std::array::fr, SIZE> const& arr) -{ - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::boolean boolean; - - fr popped_value; - boolean already_popped = false; - for (size_t i = arr.size() - 1; i != (size_t)-1; i--) { - boolean is_non_zero = arr[i] != 0; - popped_value = fr::conditional_assign(!already_popped && is_non_zero, arr[i], popped_value); - - already_popped |= is_non_zero; - } - already_popped.assert_equal(true, "Cannot pop from an empty array"); - - return popped_value; -}; - -/** - * Note: this assumes `0` always means 'not used', so be careful. If you actually want `0` to be counted, you'll need - * something else. - */ -template -void array_push(std::array::fr, SIZE>& arr, - typename CircuitTypes::fr const& value) -{ - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::boolean boolean; - - boolean already_pushed = false; - for (size_t i = 0; i < arr.size(); ++i) { - boolean is_zero = arr[i] == 0; - arr[i] = fr::conditional_assign(!already_pushed && is_zero, value, arr[i]); - - already_pushed |= is_zero; - } - already_pushed.assert_equal(true, "Cannot push to a full array"); -}; - -template -inline size_t array_push(std::array::fr>, SIZE>& arr, - typename CircuitTypes::fr const& value) -{ - for (size_t i = 0; i < arr.size(); ++i) { - if (arr[i] == std::nullopt) { - arr[i] = value; - return i; - } - } - throw_or_abort("Cannot push to a full array"); -}; - -template -inline size_t array_push(std::array, SIZE>& arr, std::shared_ptr const& value) -{ - for (size_t i = 0; i < arr.size(); ++i) { - if (arr[i] == nullptr) { - arr[i] = value; - return i; - } - } - throw_or_abort("Cannot push to a full array"); -}; - -/** - * Note: this assumes `0` always means 'not used', so be careful. If you actually want `0` to be counted, you'll need - * something else. - */ -template -typename CircuitTypes::boolean is_array_empty( - std::array::fr, SIZE> const& arr) -{ - typedef CircuitTypes CT; - typedef typename CT::boolean boolean; - - boolean nonzero_found = false; - for (size_t i = arr.size() - 1; i != (size_t)-1; i--) { - boolean is_non_zero = arr[i] != 0; - nonzero_found |= is_non_zero; - } - return !nonzero_found; -}; - -/** - * Inserts the `source` array at the first zero-valued index of the `target` array. - * Fails if the `source` array is too large vs the remaining capacity of the `target` array. - */ -template -void push_array_to_array(std::array::fr, size_1> const& source, - std::array::fr, size_2>& target) -{ - typedef CircuitTypes CT; - typedef typename CT::fr fr; - typedef typename CT::boolean boolean; - - // TODO: inefficient to get length this way within this function. Probably best to inline the checks that we need - // into the below loops directly. - fr target_length = array_length(target); - fr source_length = array_length(source); - fr target_capacity = fr(target.size()); - const fr overflow_capacity = target_capacity + 1; - - // TODO: using safe_fr for an underflow check, do: - // remaining_target_capacity = target_capacity.subtract(target_length + source_length); - - ASSERT(target_capacity.get_value() + 1 > target_length.get_value() + source_length.get_value()); - - info("source: ", source); - info("target before: ", target); - - fr j_ct = 0; // circuit-type index for the inner loop - fr next_target_index = target_length; - for (size_t i = 0; i < source.size(); ++i) { - auto& s = source[i]; - - // Triangular loop: - for (size_t j = i; j < target.size() - source.size() + i + 1; ++j) { - auto& t = target[j]; - - boolean at_next_index = j_ct == next_target_index; - - t = fr::conditional_assign(at_next_index, s, t); - - j_ct++; - } - - next_target_index++; - - next_target_index.assert_not_equal(overflow_capacity, "Target array capacity exceeded"); - - j_ct = i + 1; - } - - info("target after: ", target); -} - -} // namespace aztec3::circuits::types \ No newline at end of file