Skip to content

Commit

Permalink
Merge pull request #1682 from AztecProtocol/v2.1-testnet
Browse files Browse the repository at this point in the history
V2.1 testnet
  • Loading branch information
PhilWindle authored Nov 3, 2022
2 parents 483a1a5 + 40476bb commit 8966847
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 47 deletions.
7 changes: 4 additions & 3 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ fi
# Build native.
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DTOOLCHAIN=$TOOLCHAIN ..
cmake --build . --parallel
make -j$(nproc) $@
cd ..

# Install the webassembly toolchain.
rm -rf ./src/wasi-sdk-12.0
WASI_VERSION=12
rm -rf ./src/wasi-sdk-*
cd ./src
curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-$OS.tar.gz | tar zxfv -
curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_VERSION/wasi-sdk-$WASI_VERSION.0-$OS.tar.gz | tar zxfv -
cd ..

# Build WASM.
Expand Down
4 changes: 3 additions & 1 deletion src/aztec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ if(BENCHMARKS)
endif()

if(WASM)
add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS=1)

# 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
Expand Down Expand Up @@ -72,7 +74,7 @@ if(WASM)
target_link_options(
barretenberg.wasm
PRIVATE
-nostartfiles -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=8388608
-nostartfiles -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
)

endif()
2 changes: 1 addition & 1 deletion src/aztec/common/mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline void aligned_free(void* mem)
#if defined(__linux__) || defined(__wasm__)
inline void* protected_aligned_alloc(size_t alignment, size_t size)
{
size += alignment - (size % alignment);
size += (size % alignment);
void* t = 0;
t = aligned_alloc(alignment, size);
if (t == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/aztec/crypto/pedersen/generator_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace {

// The number of unique base points with default main index with precomputed ladders
#ifdef __wasm__
constexpr size_t num_default_generators = 64;
constexpr size_t num_default_generators = 32;
#else
constexpr size_t num_default_generators = 2048;
#endif

constexpr size_t hash_indices_generator_offset = 2048;
constexpr size_t num_hash_indices = 32;
constexpr size_t num_hash_indices = 16;
constexpr size_t num_generators_per_hash_index = 8;
constexpr size_t num_indexed_generators = num_hash_indices * num_generators_per_hash_index;
constexpr size_t size_of_generator_data_array = hash_indices_generator_offset + num_indexed_generators;
Expand Down
11 changes: 7 additions & 4 deletions src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#include "c_bind.hpp"
#include "./scalar_multiplication.hpp"
#include "pippenger.hpp"
#include <common/mem.hpp>
#include <srs/io.hpp>

using namespace barretenberg;

#define WASM_EXPORT __attribute__((visibility("default")))

extern "C" {

WASM_EXPORT void* bbmalloc(size_t size)
{
return aligned_alloc(64, size);
auto ptr = aligned_alloc(64, size);
return ptr;
}

WASM_EXPORT void bbfree(void* ptr)
{
aligned_free(ptr);
}

WASM_EXPORT void* new_pippenger(uint8_t* points, size_t num_points)
WASM_EXPORT void* new_pippenger(g1::affine_element* points, size_t num_points)
{
return new scalar_multiplication::Pippenger(points, num_points);
auto ptr = new scalar_multiplication::Pippenger(points, num_points);
return ptr;
}

WASM_EXPORT void delete_pippenger(void* pippenger)
Expand Down
20 changes: 0 additions & 20 deletions src/aztec/ecc/curves/bn254/scalar_multiplication/c_bind.hpp

This file was deleted.

10 changes: 10 additions & 0 deletions src/aztec/ecc/curves/bn254/scalar_multiplication/pippenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
namespace barretenberg {
namespace scalar_multiplication {

Pippenger::Pippenger(g1::affine_element* points, size_t num_points)
: monomials_(points)
, num_points_(num_points)
{
monomials_[0] = barretenberg::g1::affine_one;
io::byteswap(&monomials_[1], (num_points - 1) * 64);

scalar_multiplication::generate_pippenger_point_table(monomials_, monomials_, num_points);
}

Pippenger::Pippenger(uint8_t const* points, size_t num_points)
: num_points_(num_points)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ template <typename T> inline T* point_table_alloc(size_t num_points)

class Pippenger {
public:
/**
* Expects points to be buffer of size as per point_table_size().
* It expects the crs to start at points[1], and it fills in affine_one at points[0].
* The crs undergoes a byteswap, and then the point table is generated.
*/
Pippenger(g1::affine_element* points, size_t num_points);

Pippenger(uint8_t const* points, size_t num_points);

Pippenger(std::string const& path, size_t num_points);
Expand Down
4 changes: 2 additions & 2 deletions src/aztec/ecc/groups/element_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ constexpr void element<Fq, Fr, T>::self_mixed_add_or_sub(const affine_element<Fq
return;
}
} else {
const bool edge_case_trigger = x.is_msb_set() | other.x.is_msb_set();
const bool edge_case_trigger = x.is_msb_set() || other.x.is_msb_set();
if (edge_case_trigger) {
if (x.is_msb_set()) {
conditional_negate_affine(other, *(affine_element<Fq, Fr, T>*)this, predicate);
Expand Down Expand Up @@ -246,7 +246,7 @@ constexpr element<Fq, Fr, T> element<Fq, Fr, T>::operator+=(const affine_element
return *this;
}
} else {
const bool edge_case_trigger = x.is_msb_set() | other.x.is_msb_set();
const bool edge_case_trigger = x.is_msb_set() || other.x.is_msb_set();
if (edge_case_trigger) {
if (x.is_msb_set()) {
*this = { other.x, other.y, Fq::one() };
Expand Down
10 changes: 10 additions & 0 deletions src/aztec/rollup/proofs/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ void account_circuit(Composer& composer, account_tx const& tx)

void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs_factory, bool mock)
{
if (proving_key) {
return;
}

// Junk data required just to create proving key.
account_tx tx;
tx.account_public_key = grumpkin::g1::affine_one;
Expand All @@ -195,9 +199,15 @@ void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs

void init_proving_key(std::shared_ptr<waffle::ProverReferenceString> const& crs, waffle::proving_key_data&& pk_data)
{
release_key();
proving_key = std::make_shared<waffle::proving_key>(std::move(pk_data), crs);
}

void release_key()
{
proving_key.reset();
}

void init_verification_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs_factory)
{
if (!proving_key) {
Expand Down
2 changes: 2 additions & 0 deletions src/aztec/rollup/proofs/account/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs

void init_proving_key(std::shared_ptr<waffle::ProverReferenceString> const& crs, waffle::proving_key_data&& pk_data);

void release_key();

void init_verification_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs_factory);

void init_verification_key(std::shared_ptr<waffle::VerifierMemReferenceString> const& crs,
Expand Down
1 change: 0 additions & 1 deletion src/aztec/rollup/proofs/account/account_tx.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "account.hpp"
#include <common/streams.hpp>
#include <crypto/schnorr/schnorr.hpp>
#include <ecc/curves/bn254/scalar_multiplication/c_bind.hpp>
#include <fstream>
#include <gtest/gtest.h>
#include <plonk/reference_string/pippenger_reference_string.hpp>
Expand Down
5 changes: 5 additions & 0 deletions src/aztec/rollup/proofs/account/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ WASM_EXPORT void account__init_proving_key(bool mock)
init_proving_key(crs_factory, mock);
}

WASM_EXPORT void account__release_key()
{
release_key();
}

WASM_EXPORT void account__init_proving_key_from_buffer(uint8_t const* pk_buf)
{
std::shared_ptr<waffle::ProverReferenceString> crs;
Expand Down
10 changes: 2 additions & 8 deletions src/aztec/rollup/proofs/compute_circuit_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ circuit_data get_circuit_data(std::string const& name,
auto pk_stream = std::ifstream(pk_path);
waffle::proving_key_data pk_data;
read_mmap(pk_stream, pk_dir, pk_data);
if (pk_data.composer_type == 0) {
data.proving_key =
std::make_shared<waffle::proving_key>(std::move(pk_data), srs->get_prover_crs(pk_data.n + 1));

} else {
data.proving_key =
std::make_shared<waffle::proving_key>(std::move(pk_data), srs->get_prover_crs(pk_data.n));
}
data.proving_key =
std::make_shared<waffle::proving_key>(std::move(pk_data), srs->get_prover_crs(pk_data.n + 1));
data.num_gates = pk_data.n;
info(name, ": Circuit size 2^n: ", data.num_gates);
} else if (compute) {
Expand Down
5 changes: 5 additions & 0 deletions src/aztec/rollup/proofs/join_split/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ WASM_EXPORT void join_split__init_proving_key_from_buffer(uint8_t const* pk_buf)
init_proving_key(crs, std::move(pk_data));
}

WASM_EXPORT void join_split__release_key()
{
release_key();
}

WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output)
{
// Computing the size of the serialized key is non trivial. We know it's ~331mb.
Expand Down
10 changes: 10 additions & 0 deletions src/aztec/rollup/proofs/join_split/join_split.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ static std::shared_ptr<waffle::verification_key> verification_key;

void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs_factory, bool mock)
{
if (proving_key) {
return;
}

// Junk data required just to create proving key.
join_split_tx tx = noop_tx();

Expand All @@ -34,9 +38,15 @@ void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs

void init_proving_key(std::shared_ptr<waffle::ProverReferenceString> const& crs, waffle::proving_key_data&& pk_data)
{
release_key();
proving_key = std::make_shared<waffle::proving_key>(std::move(pk_data), crs);
}

void release_key()
{
proving_key.reset();
}

void init_verification_key(std::unique_ptr<waffle::ReferenceStringFactory>&& crs_factory)
{
if (!proving_key) {
Expand Down
2 changes: 2 additions & 0 deletions src/aztec/rollup/proofs/join_split/join_split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void init_proving_key(std::shared_ptr<waffle::ReferenceStringFactory> const& crs

void init_proving_key(std::shared_ptr<waffle::ProverReferenceString> const& crs, waffle::proving_key_data&& pk_data);

void release_key();

void init_verification_key(std::unique_ptr<waffle::ReferenceStringFactory>&& crs_factory);

void init_verification_key(std::shared_ptr<waffle::VerifierMemReferenceString> const& crs,
Expand Down
12 changes: 12 additions & 0 deletions src/aztec/rollup/proofs/join_split/join_split.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../notes/native/index.hpp"
#include <common/streams.hpp>
#include <common/test.hpp>
#include <plonk/proof_system/proving_key/serialize.hpp>
#include <stdlib/merkle_tree/index.hpp>

namespace rollup {
Expand Down Expand Up @@ -2472,6 +2473,17 @@ TEST_F(join_split_tests, test_send_two_virtual_notes_full_proof)
EXPECT_TRUE(verify_proof(proof));
}

// *************************************************************************************************************
// Miscellaneous
// *************************************************************************************************************

TEST_F(join_split_tests, serialzed_proving_key_size)
{
uint8_t* ptr;
auto len = join_split__get_new_proving_key_data(&ptr);
EXPECT_LE(len, 170 * 1024 * 1024);
}

} // namespace join_split
} // namespace proofs
} // namespace rollup
1 change: 0 additions & 1 deletion src/aztec/rollup/proofs/join_split/join_split_tx.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <common/streams.hpp>
#include <crypto/schnorr/schnorr.hpp>
#include <ecc/curves/bn254/scalar_multiplication/c_bind.hpp>
#include <numeric/random/engine.hpp>
#include <plonk/reference_string/pippenger_reference_string.hpp>
#include <srs/io.hpp>
Expand Down
22 changes: 21 additions & 1 deletion src/aztec/stdlib/primitives/bit_array/bit_array.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,24 @@ TEST(stdlib_bit_array, test_byte_array_conversion)

EXPECT_EQ(result, expected);
}
} // namespace test_stdlib_bit_array

TEST(stdlib_bit_array, test_uint32_vector_constructor)
{
waffle::StandardComposer composer = waffle::StandardComposer();

uint32_t a_expected = engine.get_random_uint32();
uint32_t b_expected = engine.get_random_uint32();

uint32 a = witness_t(&composer, a_expected);
uint32 b = witness_t(&composer, b_expected);

std::vector<uint32> inputs = { a, b };
bit_array test_bit_array = bit_array(inputs);

std::vector<uint32> result = test_bit_array.to_uint32_vector();

bit_array test_bit_array_2 = bit_array(result);

static_cast<byte_array>(test_bit_array_2).get_value();
}
} // namespace test_stdlib_bit_array
6 changes: 3 additions & 3 deletions src/aztec/stdlib/primitives/uint/uint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ template <typename Composer, typename Native> bool_t<Composer> uint<Composer, Na
* lo_bit + 2 high bit of (A_pivot - 4 A_{pivot - 1}) = A_pivot - 4 A_{pivot - 1} == 0
*/
context->create_big_add_gate_with_bit_extraction(gate);
bool_t<Composer> result;
bool_t<Composer> result(context);
result.witness_index = gate.a;
result.witness_bool = (lo_bit == 1) ? true : false;
return result;
Expand All @@ -364,7 +364,7 @@ template <typename Composer, typename Native> bool_t<Composer> uint<Composer, Na
* bit extraction gate is trusted to correctly extract 6 * (high bit c - 4d).
*/
context->create_big_add_gate_with_bit_extraction(gate);
bool_t<Composer> result;
bool_t<Composer> result(context);
result.witness_index = gate.b;
result.witness_bool = (hi_bit == 1) ? true : false;
return result;
Expand All @@ -376,4 +376,4 @@ INSTANTIATE_STDLIB_TYPE_VA(uint, uint32_t);
INSTANTIATE_STDLIB_TYPE_VA(uint, uint64_t);

} // namespace stdlib
} // namespace plonk
} // namespace plonk
1 change: 1 addition & 0 deletions src/aztec/stdlib/primitives/uint/uint.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ TEST(stdlib_uint, test_at)
bool_ct result = c.at(i);
bool expected = (((c_val >> i) & 1UL) == 1UL) ? true : false;
EXPECT_EQ(result.get_value(), expected);
EXPECT_EQ(result.get_context(), c.get_context());
}
};

Expand Down

0 comments on commit 8966847

Please sign in to comment.