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

Zw/eccvm v3 #642

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ jobs:
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 3 join_split_example_proofs_join_split_tests --gtest_filter=-*full_proof*
- *save_logs

bb-bin-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_test_script ./scripts/bin-test.sh barretenberg-x86_64-linux-clang-assert
# bb-bin-tests:
# docker:
# - image: aztecprotocol/alpine-build-image
# resource_class: small
# steps:
# - *checkout
# - *setup_env
# - run:
# name: "Test"
# command: cond_spot_run_test_script ./scripts/bin-test.sh barretenberg-x86_64-linux-clang-assert

benchmark-aggregator:
docker:
Expand Down Expand Up @@ -439,7 +439,7 @@ workflows:
- stdlib-recursion-turbo-tests: *bb_test
- stdlib-recursion-ultra-tests: *bb_test
- join-split-tests: *bb_test
- bb-bin-tests: *bb_test
# - bb-bin-tests: *bb_test
- benchmark-aggregator:
requires:
- barretenberg-tests
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"0.3.3","ts":"0.3.3"}
{".":"0.3.4","ts":"0.3.4"}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.3.4](https://github.com/AztecProtocol/barretenberg/compare/barretenberg-v0.3.3...barretenberg-v0.3.4) (2023-07-25)


### Features

* Add Goblin Ultra Circuit builder ([#587](https://github.com/AztecProtocol/barretenberg/issues/587)) ([2d38c25](https://github.com/AztecProtocol/barretenberg/commit/2d38c252de8b867955da661181e51f1a5f28cbc6))
* Modify bb.js to be compatible with next.js ([#544](https://github.com/AztecProtocol/barretenberg/issues/544)) ([d384089](https://github.com/AztecProtocol/barretenberg/commit/d384089f60d1a6d5baeb0d3459556a310b790366))
* Support public inputs in Ultra Honk ([#581](https://github.com/AztecProtocol/barretenberg/issues/581)) ([9cd0a06](https://github.com/AztecProtocol/barretenberg/commit/9cd0a064b8258bf4f72dd9e1c5e8f85b074d1bbc))

## [0.3.3](https://github.com/AztecProtocol/barretenberg/compare/barretenberg-v0.3.2...barretenberg-v0.3.3) (2023-07-17)


Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Barretenberg, an optimized elliptic curve library for the bn128 curve, and PLONK SNARK prover

Barretenberg aims to be a stand-alone and well-specified library, but please see https://github.com/AztecProtocol/aztec-packages/edit/master/circuits/cpp/barretenberg for the authoritative source of this code.
The separate repository https://github.com/AztecProtocol/barretenberg is available if working on barretenberg independently of Aztec, however it is encouraged to develop in the context of Aztec to see if it will cause issues for Aztec end-to-end tests.
As the spec solidifies, this should be less of an issue. Aztec and Barretenberg are currently under heavy development.

**This code is highly experimental, use at your own risk!**

### Dependencies
Expand Down Expand Up @@ -201,8 +205,12 @@ Alternatively you can build separate test binaries, e.g. honk_tests or numeric_t

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/`.

### Integration tests with Aztec Circuits
### Integration tests with Aztec in Monorepo

CI will automatically run integration tests against Aztec. The tests in `circuits/cpp` folder use the embedded barretenberg, and can be used to integration test it.

### Integration tests with Aztec in Barretenberg Standalone Repo

CI will automatically run integration tests against Aztec's circuits which live [here](https://github.com/AztecProtocol/aztec-packages/tree/master/circuits). To change which Aztec branch or commit for CI to test against, modify [`.aztec-packages-commit`](./cpp/.aztec-packages-commit).

When working on a PR, you may want to point this file to a adifferent Aztec branch or commit, but then it should probably be pointed back to master before merging.
When working on a PR, you may want to point this file to a different Aztec branch or commit, but then it should probably be pointed back to master before merging.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.3 x-release-please-version
v0.3.4 x-release-please-version
2 changes: 1 addition & 1 deletion barretenberg-wasm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ in
stdenv.mkDerivation
{
pname = "barretenberg.wasm";
version = "0.3.3"; # x-release-please-version
version = "0.3.4"; # x-release-please-version

src = ./cpp;

Expand Down
2 changes: 1 addition & 1 deletion barretenberg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ in
buildEnv.mkDerivation
{
pname = "libbarretenberg";
version = "0.3.3"; # x-release-please-version
version = "0.3.4"; # x-release-please-version

src = ./cpp;

Expand Down
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.24)
project(
Barretenberg
DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover"
VERSION 0.3.3 # x-release-please-version
VERSION 0.3.4 # x-release-please-version
LANGUAGES CXX C
)

Expand Down
1 change: 0 additions & 1 deletion cpp/bin-test/target/main.json

This file was deleted.

Binary file removed cpp/bin-test/target/witness.tr
Binary file not shown.
6 changes: 2 additions & 4 deletions cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ rm -rf ./build-wasm
# Install formatting git hook.
HOOKS_DIR=$(git rev-parse --git-path hooks)
# The pre-commit script will live in a barretenberg-specific hooks directory
# That may be just in the top level of this repository,
# or may be in a .git/modules/barretenberg subdirectory when this is actually a submodule
# Either way, running `git rev-parse --show-toplevel` from the hooks directory gives the path to barretenberg
echo "cd \$(git rev-parse --show-toplevel)/cpp && ./format.sh staged" > $HOOKS_DIR/pre-commit
# Find it based on the current working directory.
echo "cd $(pwd)/cpp && ./format.sh staged" > $HOOKS_DIR/pre-commit
chmod +x $HOOKS_DIR/pre-commit

# Determine system.
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/barretenberg/common/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
__extension__ using uint128_t = unsigned __int128;
#endif

template <typename T>
concept IntegralOrEnum = std::integral<T> || std::is_enum_v<T>;
template <typename T> concept IntegralOrEnum = std::integral<T> || std::is_enum_v<T>;

namespace serialize {
// Forward declare derived msgpack methods
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/barretenberg/common/streams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ template <std::integral T, typename A> inline std::ostream& operator<<(std::ostr
}

template <typename T, typename A>
requires(!std::integral<T>)
inline std::ostream& operator<<(std::ostream& os, std::vector<T, A> const& arr)
requires(!std::integral<T>) inline std::ostream& operator<<(std::ostream& os, std::vector<T, A> const& arr)
{
os << "[\n";
for (auto element : arr) {
Expand Down
75 changes: 53 additions & 22 deletions cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "acir_format.hpp"
#include "barretenberg/common/container.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/dsl/acir_format/blake2s_constraint.hpp"
#include "barretenberg/dsl/acir_format/block_constraint.hpp"
#include "barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp"
Expand Down Expand Up @@ -208,29 +209,48 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci
arg.value.value);
}

void handle_memory(Circuit::MemoryBlock const& mem_block, bool is_ram, acir_format& af)
BlockConstraint handle_memory_init(Circuit::Opcode::MemoryInit const& mem_init)
{
BlockConstraint block{ .init = {}, .trace = {}, .type = BlockType::ROM };
std::vector<poly_triple> init;
std::vector<MemOp> trace;
auto len = mem_block.len;

auto len = mem_init.init.size();
for (size_t i = 0; i < len; ++i) {
init.push_back(serialize_arithmetic_gate(mem_block.trace[i].value));
}
for (size_t i = len; i < mem_block.trace.size(); ++i) {
auto index = serialize_arithmetic_gate(mem_block.trace[i].index);
auto value = serialize_arithmetic_gate(mem_block.trace[i].value);
auto op = mem_block.trace[i].operation;
if (!(op.mul_terms.empty() && op.linear_combinations.empty())) {
throw_or_abort("Expected constant.");
}
bool access_type(uint256_t(op.q_c));
trace.push_back(MemOp{
.access_type = static_cast<uint8_t>(access_type),
.index = index,
.value = value,
block.init.push_back(poly_triple{
.a = mem_init.init[i].value,
.b = 0,
.c = 0,
.q_m = 0,
.q_l = 1,
.q_r = 0,
.q_o = 0,
.q_c = 0,
});
}
af.block_constraints.push_back(BlockConstraint{ .init = init, .trace = trace, .type = (BlockType)is_ram });
return block;
}

bool is_rom(Circuit::MemOp const& mem_op)
{
return mem_op.operation.mul_terms.size() == 0 && mem_op.operation.linear_combinations.size() == 0 &&
uint256_t(mem_op.operation.q_c) == 0;
}

void handle_memory_op(Circuit::Opcode::MemoryOp const& mem_op, BlockConstraint& block)
{
uint8_t access_type = 1;
if (is_rom(mem_op.op)) {
access_type = 0;
}
if (block.type == BlockType::ROM && access_type == 1) {
block.type = BlockType::RAM;
}

MemOp acir_mem_op = MemOp{ .access_type = access_type,
.index = serialize_arithmetic_gate(mem_op.op.index),
.value = serialize_arithmetic_gate(mem_op.op.value) };
block.trace.push_back(acir_mem_op);
}

acir_format circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
Expand All @@ -241,7 +261,7 @@ acir_format circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
af.varnum = circuit.current_witness_index + 1;
af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }),
map(circuit.return_values.value, [](auto e) { return e.value; }) });

std::map<uint32_t, BlockConstraint> block_id_to_block_constraint;
for (auto gate : circuit.opcodes) {
std::visit(
[&](auto&& arg) {
Expand All @@ -250,14 +270,25 @@ acir_format circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
handle_arithmetic(arg, af);
} else if constexpr (std::is_same_v<T, Circuit::Opcode::BlackBoxFuncCall>) {
handle_blackbox_func_call(arg, af);
} else if constexpr (std::is_same_v<T, Circuit::Opcode::RAM>) {
handle_memory(arg.value, true, af);
} else if constexpr (std::is_same_v<T, Circuit::Opcode::ROM>) {
handle_memory(arg.value, false, af);
} else if constexpr (std::is_same_v<T, Circuit::Opcode::MemoryInit>) {
auto block = handle_memory_init(arg);
uint32_t block_id = arg.block_id.value;
block_id_to_block_constraint[block_id] = block;
} else if constexpr (std::is_same_v<T, Circuit::Opcode::MemoryOp>) {
auto block = block_id_to_block_constraint.find(arg.block_id.value);
if (block == block_id_to_block_constraint.end()) {
throw_or_abort("unitialized MemoryOp");
}
handle_memory_op(arg, block->second);
}
},
gate.value);
}
for (const auto& [block_id, block] : block_id_to_block_constraint) {
if (!block.trace.empty()) {
af.block_constraints.push_back(block);
}
}
return af;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "block_constraint.hpp"
#include "acir_format.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "block_constraint.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ecdsa_secp256k1.hpp"
#include "acir_format.hpp"
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "ecdsa_secp256k1.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ecdsa_secp256r1.hpp"
#include "acir_format.hpp"
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "ecdsa_secp256r1.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "recursion_constraint.hpp"
#include "acir_format.hpp"
#include "barretenberg/plonk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "recursion_constraint.hpp"

#include <gtest/gtest.h>
#include <vector>
Expand Down
Loading