Skip to content

Commit

Permalink
Use latest bb (ultraplonk), fix minor issues (#305)
Browse files Browse the repository at this point in the history
[SQUASHED] Update bb, remove stdlib/types/types.hpp and couple of other fixes.

remove any `stdlib::types`.

update bb to point to temp aztec3.

remove `USE_TURBO`.

Include array package.

Bump wasm memory to use 30 initial pages.

fix abi TS tests.

Fix circuit js test.

remove stdlib/types from init in public kernel circuit.

update abi snapshots.

update bb.

Increase merkle tree test timeout by 2 sec.

Compute empty subtree roots in runtime (doing so in compile time creates issue of empty runtime generator tables)

fix.

Use lookup-pedersen for hashing nullifier leaves.

Fix a merkle tree test.

Bump up merkle tree test timeout by 1 more sec.

TRY large timeout for merkle tests.

Change composer in  `mockedKeys.json` to ultra.

chore: updated contract json keys

increase e2e test timeouts.

e2e timeout increase (again).

revert test filter in merkle tree ts.

Fix build post rebase.

Use lookup pedersen hash in native types for merkle hashing.

update empty L2 block hash hard-coded value.

Fix pk native circuit wasm.

remove old code.

remove comments.

remove more logs.
  • Loading branch information
suyash67 committed Apr 26, 2023
1 parent 7c389d5 commit 621981c
Show file tree
Hide file tree
Showing 58 changed files with 300 additions and 275 deletions.
10 changes: 1 addition & 9 deletions circuits/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ option(DISABLE_TBB "Intel Thread Building Blocks" ON)
option(COVERAGE "Enable collecting coverage from tests" OFF)
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)

# NOTE: investigate issue:
# https://github.com/AztecProtocol/aztec3-circuits/issues/236
option(USE_TURBO "Enable the use of TurboPlonk in barretenberg." OFF)
if(USE_TURBO)
message(STATUS "Building barretenberg for TurboPlonk Composer.")
add_definitions(-DUSE_TURBO)
else()
message(STATUS "Building barretenberg for UltraPlonk Composer.")
endif()
message(STATUS "Building barretenberg for UltraPlonk Composer.")

if(ENABLE_ASAN)
add_compile_options(-fsanitize=address)
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/barretenberg
Submodule barretenberg updated 112 files
4 changes: 2 additions & 2 deletions circuits/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ echo "# When running cmake directly, remember to use: --build --preset $PRESET"
echo "#################################"

# Build native.
cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert -DUSE_TURBO=true
cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert
cmake --build --preset $PRESET ${@/#/--target }

# Install the webassembly toolchain.
Expand All @@ -77,5 +77,5 @@ if ! [ -d "./barretenberg/cpp/src/wasi-sdk-$WASI_VERSION.0" ] ; then
fi

# Build WASM.
cmake --preset wasm -DUSE_TURBO=true
cmake --preset wasm
cmake --build --preset wasm
2 changes: 1 addition & 1 deletion circuits/cpp/cmake/barretenberg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ExternalProject_Add(Barretenberg
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} --preset ${CMAKE_BBERG_PRESET} -DSERIALIZE_CANARY=${SERIALIZE_CANARY} -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DUSE_TURBO=${USE_TURBO}
CONFIGURE_COMMAND ${CMAKE_COMMAND} --preset ${CMAKE_BBERG_PRESET} -DSERIALIZE_CANARY=${SERIALIZE_CANARY} -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
BUILD_COMMAND ${CMAKE_COMMAND} --build --preset ${CMAKE_BBERG_PRESET} ${BBERG_TARGETS}
# byproducts needed by ninja generator (not needed by make)
BUILD_BYPRODUCTS ${BBERG_BUILD_DIR}/lib/libbarretenberg.a ${BBERG_BUILD_DIR}/lib/libenv.a)
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/dockerfiles/Dockerfile.arm64-linux-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
FROM aztecprotocol/crosstool-ng-arm64:latest
WORKDIR /usr/src/circuits/cpp
COPY . .
RUN cmake --toolchain ./cmake/toolchains/aarch64-linux.cmake --preset gcc -DUSE_TURBO=true && cmake --build --preset gcc
RUN cmake --toolchain ./cmake/toolchains/aarch64-linux.cmake --preset gcc && cmake --build --preset gcc
RUN cd build && for test in ./bin/*_tests; do qemu-aarch64 $test; done
ENTRYPOINT /bin/bash
2 changes: 1 addition & 1 deletion circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /usr/src/circuits/cpp/barretenberg/cpp/src
RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv -
WORKDIR /usr/src/circuits/cpp
COPY . .
RUN cmake --preset wasm -DUSE_TURBO=true && cmake --build --preset wasm
RUN cmake --preset wasm && cmake --build --preset wasm

FROM alpine:3.17
COPY --from=builder /usr/src/circuits/cpp/build-wasm/bin/aztec3-circuits.wasm /usr/src/circuits/cpp/build-wasm/bin/aztec3-circuits.wasm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-s
WORKDIR /usr/src/circuits/cpp
COPY . .

RUN cmake --preset wasm -DUSE_TURBO=true && cmake --build --preset wasm
RUN cmake --preset wasm && cmake --build --preset wasm

FROM ubuntu:kinetic
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y xz-utils curl
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/dockerfiles/Dockerfile.x86_64-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WORKDIR /usr/src/circuits/cpp

COPY . .
# Build the entire project, as we want to check everything builds under clang
RUN cmake --preset default -DUSE_TURBO=true && cmake --build --preset default
RUN cmake --preset default && cmake --build --preset default

FROM alpine:3.17
RUN apk update && apk add openmp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apk update \
WORKDIR /usr/src/circuits/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 -DUSE_TURBO=true && cmake --build --preset default
RUN cmake --preset default -DCMAKE_BUILD_TYPE=RelWithAssert -DCI=ON && cmake --build --preset default

FROM alpine:3.17
RUN apk update && apk add curl openmp bash
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/dockerfiles/Dockerfile.x86_64-linux-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apk update \
WORKDIR /usr/src/circuits/cpp
COPY . .
# Build the entire project, as we want to check everything builds under gcc.
RUN cmake --preset gcc -DCI=ON -DUSE_TURBO=true && cmake --build --preset gcc
RUN cmake --preset gcc -DCI=ON && cmake --build --preset gcc

FROM alpine:3.17
RUN apk update && apk add libstdc++ libgomp
Expand Down
10 changes: 7 additions & 3 deletions circuits/cpp/src/aztec3/circuits/abis/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
#include <barretenberg/common/test.hpp>
#include <barretenberg/common/serialize.hpp>
#include "index.hpp"
#include <barretenberg/stdlib/types/types.hpp>

#include "previous_kernel_data.hpp"
#include "private_kernel/private_inputs.hpp"

namespace aztec3::circuits::abis {
namespace {
// Composer
using Composer = plonk::UltraComposer;

using Composer = plonk::stdlib::types::Composer;
// Types
using CT = aztec3::utils::types::CircuitTypes<Composer>;
using NT = aztec3::utils::types::NativeTypes;
} // namespace

namespace aztec3::circuits::abis {

class abi_tests : public ::testing::Test {};

Expand Down
8 changes: 2 additions & 6 deletions circuits/cpp/src/aztec3/circuits/apps/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>
#include <barretenberg/stdlib/types/types.hpp>

namespace {
// Composer
using C = plonk::stdlib::types::Composer;
using C = plonk::UltraComposer;

// Types
using CT = aztec3::utils::types::CircuitTypes<C>;
Expand Down Expand Up @@ -65,7 +64,7 @@ using aztec3::circuits::apps::notes::DefaultPrivateNote;

using aztec3::circuits::apps::notes::DefaultSingletonPrivateNote;

//********
// State variables
// Get rid of ugle `Composer` template arg from our state var types:
template <typename T> struct SpecialisedTypes {
typedef MappingStateVar<C, T> mapping;
Expand All @@ -79,9 +78,6 @@ template <typename Note> using UTXO = typename SpecialisedTypes<Note>::utxo;
template <typename Note> using UTXOSet = typename SpecialisedTypes<Note>::utxo_set;

using Field = FieldStateVar<C>;

//********

} // namespace

namespace aztec3::circuits::apps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
#include <aztec3/circuits/apps/oracle_wrapper.hpp>
#include <aztec3/oracle/oracle.hpp>

#include <barretenberg/stdlib/types/types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>

namespace aztec3::circuits::apps::test_apps::basic_contract_deployment {

using C = plonk::stdlib::types::Composer;
// Composer
using C = plonk::UltraComposer;

// Native and circuit types
using CT = aztec3::utils::types::CircuitTypes<C>;
using NT = aztec3::utils::types::NativeTypes;

// Database types
using DB = oracle::FakeDB;
using oracle::NativeOracle;
using OracleWrapper = apps::OracleWrapperInterface<C>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
#include <aztec3/circuits/apps/oracle_wrapper.hpp>
#include <aztec3/oracle/oracle.hpp>

#include <barretenberg/stdlib/types/types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>

namespace aztec3::circuits::apps::test_apps::escrow {

using C = plonk::stdlib::types::Composer;
// Composer
using C = plonk::UltraComposer;

// Native and circuit types
using CT = aztec3::utils::types::CircuitTypes<C>;
using NT = aztec3::utils::types::NativeTypes;

// Database types
using DB = oracle::FakeDB;
using oracle::NativeOracle;
using OracleWrapper = apps::OracleWrapperInterface<C>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@

#include <aztec3/oracle/oracle.hpp>

#include <barretenberg/stdlib/types/types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>

namespace aztec3::circuits::apps::test_apps::private_to_private_function_call {

using C = plonk::stdlib::types::Composer;
// Composer
using C = plonk::UltraComposer;

// Native and circuit types
using CT = aztec3::utils::types::CircuitTypes<C>;
using NT = aztec3::utils::types::NativeTypes;

// Database types
using DB = oracle::FakeDB;
using oracle::NativeOracle;
using OracleWrapper = OracleWrapperInterface<C>;
Expand Down
30 changes: 23 additions & 7 deletions circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,24 @@ using private_function = std::function<OptionalPrivateCircuitPublicInputs<NT>(
constexpr size_t MAX_FUNCTION_LEAVES = 2 << (aztec3::FUNCTION_TREE_HEIGHT - 1);
const NT::fr EMPTY_FUNCTION_LEAF = FunctionLeafPreimage<NT>{}.hash(); // hash of empty/0 preimage
const NT::fr EMPTY_CONTRACT_LEAF = NewContractData<NT>{}.hash(); // hash of empty/0 preimage
const auto& EMPTY_FUNCTION_SIBLINGS = compute_empty_sibling_path<NT, aztec3::FUNCTION_TREE_HEIGHT>(EMPTY_FUNCTION_LEAF);
const auto& EMPTY_CONTRACT_SIBLINGS = compute_empty_sibling_path<NT, aztec3::CONTRACT_TREE_HEIGHT>(EMPTY_CONTRACT_LEAF);

const auto& get_empty_function_siblings()
{
static auto EMPTY_FUNCTION_SIBLINGS = []() {
const auto result = compute_empty_sibling_path<NT, aztec3::FUNCTION_TREE_HEIGHT>(EMPTY_FUNCTION_LEAF);
return result;
}();
return EMPTY_FUNCTION_SIBLINGS;
}

const auto& get_empty_contract_siblings()
{
static auto EMPTY_CONTRACT_SIBLINGS = []() {
const auto result = compute_empty_sibling_path<NT, aztec3::CONTRACT_TREE_HEIGHT>(EMPTY_CONTRACT_LEAF);
return result;
}();
return EMPTY_CONTRACT_SIBLINGS;
}

} // namespace

Expand Down Expand Up @@ -252,14 +268,14 @@ PrivateInputs<NT> do_private_call_get_kernel_inputs(bool const is_constructor,
private_circuit_vk_hash,
acir_hash,
function_leaf_index,
EMPTY_FUNCTION_SIBLINGS);
get_empty_function_siblings());

// update contract_tree_root with real value
contract_tree_root = contract_tree_root_from_siblings<NT>(function_tree_root,
contract_address,
portal_contract_address,
contract_leaf_index,
EMPTY_CONTRACT_SIBLINGS);
get_empty_contract_siblings());
}

//***************************************************************************
Expand All @@ -285,7 +301,7 @@ PrivateInputs<NT> do_private_call_get_kernel_inputs(bool const is_constructor,
// TODO this should likely be handled as part of the DB/Oracle/Context infrastructure
private_circuit_public_inputs.historic_contract_tree_root = contract_tree_root;

Prover private_circuit_prover = private_circuit_composer.create_prover();
auto private_circuit_prover = private_circuit_composer.create_prover();
NT::Proof private_circuit_proof = private_circuit_prover.construct_proof();
// info("\nproof: ", private_circuit_proof.proof_data);

Expand Down Expand Up @@ -368,11 +384,11 @@ PrivateInputs<NT> do_private_call_get_kernel_inputs(bool const is_constructor,

.function_leaf_membership_witness = {
.leaf_index = function_leaf_index,
.sibling_path = EMPTY_FUNCTION_SIBLINGS,
.sibling_path = get_empty_function_siblings(),
},
.contract_leaf_membership_witness = {
.leaf_index = contract_leaf_index,
.sibling_path = EMPTY_CONTRACT_SIBLINGS,
.sibling_path = get_empty_contract_siblings(),
},

.portal_contract_address = portal_contract_address,
Expand Down
6 changes: 2 additions & 4 deletions circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "barretenberg/plonk/composer/turbo_composer.hpp"

namespace {
using Composer = plonk::UltraComposer;
using NT = aztec3::utils::types::NativeTypes;
using DummyComposer = aztec3::utils::DummyComposer;
using aztec3::circuits::abis::CombinedAccumulatedData;
Expand All @@ -35,9 +36,6 @@ using aztec3::circuits::kernel::private_kernel::private_kernel_circuit;
using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel;
using aztec3::circuits::mock::mock_kernel_circuit;

using plonk::TurboComposer;
using namespace plonk::stdlib::types;

} // namespace

#define WASM_EXPORT __attribute__((visibility("default")))
Expand Down Expand Up @@ -179,7 +177,7 @@ WASM_EXPORT size_t private_kernel__prove(uint8_t const* signed_tx_request_buf,
};

Composer private_kernel_composer = Composer(crs_factory);
plonk::stdlib::types::Prover private_kernel_prover = private_kernel_composer.create_prover();
auto private_kernel_prover = private_kernel_composer.create_prover();

KernelCircuitPublicInputs<NT> public_inputs;
public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs);
Expand Down
5 changes: 1 addition & 4 deletions circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

#include <aztec3/circuits/abis/private_kernel/private_inputs.hpp>

#include <barretenberg/stdlib/types/types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>

namespace aztec3::circuits::kernel::private_kernel {

// Turbo specific, at the moment:
using Composer = plonk::stdlib::types::Composer;
using plonk::stdlib::types::Prover;
using Composer = plonk::UltraComposer;

using Aggregator = aztec3::circuits::recursion::Aggregator;

Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PreviousKernelData<NT> dummy_previous_kernel(bool real_vk_proof = false)
Composer mock_kernel_composer = Composer(crs_factory);
auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs);

plonk::stdlib::types::Prover mock_kernel_prover = mock_kernel_composer.create_prover();
auto mock_kernel_prover = mock_kernel_composer.create_prover();
NT::Proof mock_kernel_proof =
real_vk_proof ? mock_kernel_prover.construct_proof() : NT::Proof{ .proof_data = std::vector<uint8_t>(64, 0) };

Expand Down
5 changes: 1 addition & 4 deletions circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "barretenberg/srs/reference_string/env_reference_string.hpp"

#include "barretenberg/common/serialize.hpp"
#include "barretenberg/plonk/composer/turbo_composer.hpp"

namespace {
using Composer = plonk::UltraComposer;
using NT = aztec3::utils::types::NativeTypes;
using DummyComposer = aztec3::utils::DummyComposer;
using aztec3::circuits::abis::KernelCircuitPublicInputs;
Expand All @@ -23,9 +23,6 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputsNoPreviousKernel;
using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_no_previous_kernel;
using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_private_previous_kernel;
using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_public_previous_kernel;

using plonk::TurboComposer;
using namespace plonk::stdlib::types;
} // namespace

#define WASM_EXPORT __attribute__((visibility("default")))
Expand Down
5 changes: 1 addition & 4 deletions circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@

#include <aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp>

#include <barretenberg/stdlib/types/types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/native_types.hpp>
#include <aztec3/utils/dummy_composer.hpp>

namespace aztec3::circuits::kernel::public_kernel {

// Turbo specific, at the moment:
using Composer = plonk::stdlib::types::Composer;
using plonk::stdlib::types::Prover;
using Composer = plonk::UltraComposer;

using Aggregator = aztec3::circuits::recursion::Aggregator;

Expand Down
Loading

0 comments on commit 621981c

Please sign in to comment.