Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Working UltraPlonk for Noir #299

Merged
merged 53 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9b1010e
Make dsl composer agnostic.
suyash67 Mar 14, 2023
30157c6
change SYSTEM_COMPOSER under stdlib::types to ultra composer type
vezenovm Mar 14, 2023
106130c
Merge branch 'master' into sb/composer-agnostic-dsl
vezenovm Mar 14, 2023
19af898
move to ultra w/ a few cmake changes to bb.wasm executable, merged in…
vezenovm Mar 15, 2023
c8848be
use ultra logic constraints
vezenovm Mar 15, 2023
eb7cfb1
in process of debugging, move to using ultra logic constraints
vezenovm Mar 16, 2023
eaff98c
Merge branch 'master' into mv/move-to-ultra
vezenovm Mar 22, 2023
8a9337c
add get_total_circuit_size method
vezenovm Mar 22, 2023
b932e99
acir format tests showing failures with range constraints of differen…
vezenovm Mar 24, 2023
fa0801a
remove unnecessary comment
vezenovm Mar 24, 2023
355f10d
(fix) Temporarily add a redundant add-gate for variables that need ra…
suyash67 Mar 24, 2023
32e775b
Merge remote-tracking branch 'origin/master' into mv/move-to-ultra
phated Mar 27, 2023
391aa92
rename functions
phated Mar 27, 2023
077053c
Implement get_solidity_verifier function
phated Mar 27, 2023
4ac8949
Fix no longer available properties
phated Mar 27, 2023
2cca246
remove constraint system
phated Mar 27, 2023
8f23dc7
logic gate changes using plookup
Mar 27, 2023
649a2b8
Merge branch 'mv/move-to-ultra' into mv/ultra-range-dbg
Mar 27, 2023
62a7757
logic gate debugging
Mar 27, 2023
5472c56
test for logic gates passing
Mar 27, 2023
ee6973b
last debug things XOR and AND returnign correct results, XOR still fa…
vezenovm Mar 28, 2023
f031dd2
cleanup
phated Mar 28, 2023
8a25d81
pedersen_plookup
phated Mar 29, 2023
8f4a8aa
plookup funcs
phated Mar 29, 2023
c51815f
add to header
phated Mar 29, 2023
a289368
fixed error in pedersen hash when RHS is a circuit constant
zac-williamson Mar 29, 2023
5bc8ee4
Merge branch 'mv/ultra-range-dbg' of github.com:AztecProtocol/barrete…
zac-williamson Mar 29, 2023
343174a
added ACIR test for XOR gate
zac-williamson Mar 29, 2023
1258995
temp disable wasm-opt
phated Mar 29, 2023
016ba39
Making everything compile with any composer & add a cmake flag to swi…
phated Mar 29, 2023
c0cf208
enable wasm-opt for asyncify but disable optimizations
phated Mar 29, 2023
75fe80c
remove using in header
phated Mar 29, 2023
840360c
fixed work queue bug with wasm
zac-williamson Mar 29, 2023
952e2af
added bitwise logic operations into stdlib
zac-williamson Mar 29, 2023
592514e
updated acir_format to use new stdlib logic class
zac-williamson Mar 29, 2023
138bc73
Merge branch 'mv/ultra-range-dbg' of github.com:AztecProtocol/barrete…
zac-williamson Mar 29, 2023
8f335a5
reenable tests
phated Mar 29, 2023
3bdd82a
linting fixes
phated Mar 29, 2023
72f0a8e
disable binaryen with comment
phated Mar 29, 2023
c60a65d
write instead of read
phated Mar 30, 2023
d254d94
remove random
phated Mar 30, 2023
5772a97
WIP
phated Mar 30, 2023
e40f842
cleanup the debug logging
phated Mar 30, 2023
db5c8dd
restore the randomness
phated Mar 30, 2023
71674a5
only add a zero/one test instead of replacing
phated Mar 30, 2023
3882450
remove unused change
phated Mar 30, 2023
dd7fd0a
changes to make solgen work correctly in bindings
phated Mar 31, 2023
0ab3760
fix join_split_tests.test_deposit_construct_proof
vezenovm Mar 31, 2023
6119f1e
working serialized proving key size and circuit change test for ultra…
vezenovm Apr 3, 2023
b347580
USE_TURBO for join_split
phated Apr 3, 2023
96819b2
Empty-Commit
kevaundray Apr 3, 2023
0ace234
Don't default one function; tweak comments.
codygunton Apr 3, 2023
7b35952
Empty-Commit
kevaundray Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ cmake --build --preset wasm --target ecc_tests
wasmtime --dir=.. ./bin/ecc_tests
```

To add gtest filter parameters in a wasm context:

```
wasmtime --dir=.. ./bin/ecc_tests run --gtest_filter=filtertext
```

### Fuzzing build

For detailed instructions look in cpp/docs/Fuzzing.md
Expand Down Expand Up @@ -160,11 +166,13 @@ cmake --build --preset coverage
```

Then run tests (on the mainframe always use taskset and nice to limit your influence on the server. Profiling instrumentation is very heavy):

```
taskset 0xffffff nice -n10 make test
```

And generate report:

```
make create_full_coverage_report
```
Expand All @@ -174,4 +182,5 @@ The report will land in the build directory in the all_test_coverage_report dire
Alternatively you can build separate test binaries, e.g. honk_tests or numeric_tests and run **make test** just for them or even just for a single test. Then the report will just show coverage for those binaries.

### VS Code configuration

A default configuration for VS Code is provided by the file [`barretenberg.code-workspace`](barretenberg.code-workspace). These settings can be overridden by placing configuration files in `.vscode/`.
8 changes: 8 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ 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)
option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON)
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()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
message(STATUS "Compiling for ARM.")
Expand Down
32 changes: 19 additions & 13 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
)

# With binaryen installed, it seems its wasm backend optimiser gets invoked automatically.
Expand All @@ -105,18 +105,24 @@ if(WASM)
-nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576
)

find_program(WASM_OPT wasm-opt)
# TODO(blaine): Figure out how to Asyncify the wasm output.
# Binaryen's Asyncify transform produces wasm that has too many local variables to run in a WebAssembly
# instance. This likely would be "solved" by enabling the optimizations to reduce the number of locals,
# but using any optimization level results in a wasm file that takes an unusable amount of time to solve the
# most simple prood.

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

add_custom_command(
TARGET barretenberg.wasm
POST_BUILD
COMMAND wasm-opt "$<TARGET_FILE:barretenberg.wasm>" -O2 --asyncify -o "$<TARGET_FILE:barretenberg.wasm>"
VERBATIM
)
# if(NOT WASM_OPT)
# message(FATAL_ERROR "wasm-opt executable not found. Please install binaryen.")
# endif()

# add_custom_command(
# TARGET barretenberg.wasm
# POST_BUILD
# COMMAND wasm-opt "$<TARGET_FILE:barretenberg.wasm>" -O0 --asyncify -o "$<TARGET_FILE:barretenberg.wasm>"
# VERBATIM
# )

if(INSTALL_BARRETENBERG)
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -151,7 +157,7 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
)
else()
# For use when compiling dependent cpp projects
Expand Down Expand Up @@ -183,7 +189,7 @@ else()
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
$<TARGET_OBJECTS:env_objects>
)

Expand Down
26 changes: 26 additions & 0 deletions cpp/src/barretenberg/crypto/pedersen/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "c_bind.hpp"
#include "pedersen.hpp"
#include "pedersen_lookup.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/common/timer.hpp"
#include "barretenberg/common/mem.hpp"
Expand All @@ -21,6 +22,14 @@ WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* r
barretenberg::fr::serialize_to_buffer(r, result);
}

WASM_EXPORT void pedersen_plookup_compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result)
{
auto lhs = barretenberg::fr::serialize_from_buffer(left);
auto rhs = barretenberg::fr::serialize_from_buffer(right);
auto r = crypto::pedersen::lookup::compress_native({ lhs, rhs });
barretenberg::fr::serialize_to_buffer(r, result);
}

WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
Expand All @@ -29,6 +38,14 @@ WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* outpu
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen_plookup_compress(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
auto r = crypto::pedersen::lookup::compress_native(to_compress);
barretenberg::fr::serialize_to_buffer(r, output);
}

WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index)
{
std::vector<grumpkin::fq> to_compress;
Expand All @@ -46,6 +63,15 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output)
write(output, pedersen_hash);
}

WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output)
{
std::vector<grumpkin::fq> to_compress;
read(inputs_buffer, to_compress);
grumpkin::g1::affine_element pedersen_hash = crypto::pedersen::lookup::commit_native(to_compress);

write(output, pedersen_hash);
}

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r)
{
std::vector<uint8_t> to_compress(data, data + length);
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/barretenberg/crypto/pedersen/c_bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ extern "C" {
WASM_EXPORT void pedersen__init();

WASM_EXPORT void pedersen__compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result);
WASM_EXPORT void pedersen_plookup_compress_fields(uint8_t const* left, uint8_t const* right, uint8_t* result);

WASM_EXPORT void pedersen__compress(uint8_t const* inputs_buffer, uint8_t* output);
WASM_EXPORT void pedersen_plookup_compress(uint8_t const* inputs_buffer, uint8_t* output);

WASM_EXPORT void pedersen__compress_with_hash_index(uint8_t const* inputs_buffer, uint8_t* output, uint32_t hash_index);

WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output);
WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output);

WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r);

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(acir_format)
add_subdirectory(turbo_proofs)
add_subdirectory(acir_proofs)
36 changes: 19 additions & 17 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "acir_format.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

void read_witness(TurboComposer& composer, std::vector<barretenberg::fr> witness)
void read_witness(Composer& composer, std::vector<barretenberg::fr> witness)
{
composer.variables[0] = 0;
for (size_t i = 0; i < witness.size(); ++i) {
composer.variables[i + 1] = witness[i];
}
}

void create_circuit(TurboComposer& composer, const acir_format& constraint_system)
void create_circuit(Composer& composer, const acir_format& constraint_system)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
Expand Down Expand Up @@ -41,7 +43,7 @@ void create_circuit(TurboComposer& composer, const acir_format& constraint_syste

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -85,14 +87,14 @@ void create_circuit(TurboComposer& composer, const acir_format& constraint_syste
}
}

TurboComposer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory)
Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

TurboComposer composer(std::move(crs_factory));
Composer composer(std::move(crs_factory));

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand All @@ -119,7 +121,7 @@ TurboComposer create_circuit(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -165,15 +167,15 @@ TurboComposer create_circuit(const acir_format& constraint_system,
return composer;
}

TurboComposer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory)
Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

TurboComposer composer(std::move(crs_factory));
Composer composer(std::move(crs_factory));

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand Down Expand Up @@ -203,7 +205,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -248,13 +250,13 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

return composer;
}
TurboComposer create_circuit_with_witness(const acir_format& constraint_system, std::vector<fr> witness)
Composer create_circuit_with_witness(const acir_format& constraint_system, std::vector<fr> witness)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

auto composer = TurboComposer();
auto composer = Composer();

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand Down Expand Up @@ -284,7 +286,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -329,7 +331,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

return composer;
}
void create_circuit_with_witness(TurboComposer& composer, const acir_format& constraint_system, std::vector<fr> witness)
void create_circuit_with_witness(Composer& composer, const acir_format& constraint_system, std::vector<fr> witness)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
Expand Down Expand Up @@ -363,7 +365,7 @@ void create_circuit_with_witness(TurboComposer& composer, const acir_format& con

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down
20 changes: 11 additions & 9 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "merkle_membership_constraint.hpp"
#include "pedersen.hpp"
#include "hash_to_field.hpp"
#include "barretenberg/stdlib/types/types.hpp"

namespace acir_format {

Expand All @@ -35,20 +36,21 @@ struct acir_format {
friend bool operator==(acir_format const& lhs, acir_format const& rhs) = default;
};

void read_witness(TurboComposer& composer, std::vector<barretenberg::fr> witness);
void read_witness(plonk::stdlib::types::Composer& composer, std::vector<barretenberg::fr> witness);

void create_circuit(TurboComposer& composer, const acir_format& constraint_system);
void create_circuit(plonk::stdlib::types::Composer& composer, const acir_format& constraint_system);

TurboComposer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory);
plonk::stdlib::types::Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory);

TurboComposer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory);
plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory);

TurboComposer create_circuit_with_witness(const acir_format& constraint_system, std::vector<fr> witness);
plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness);

void create_circuit_with_witness(TurboComposer& composer,
void create_circuit_with_witness(plonk::stdlib::types::Composer& composer,
const acir_format& constraint_system,
std::vector<fr> witness);

Expand Down
Loading