Skip to content

Commit

Permalink
Merge branch 'master' into 12-09-chore_removing_noir_bug_workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jan 13, 2025
2 parents b1a3f64 + e494f6b commit ede6f10
Show file tree
Hide file tree
Showing 1,382 changed files with 28,998 additions and 107,299 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ jobs:
./bootstrap.sh image-e2e
- name: "Test"
timeout-minutes: 40
continue-on-error: true
run: |
./bootstrap.sh e2e-test uniswap_trade_on_l1_from_l2
./bootstrap.sh test-e2e uniswap_trade_on_l1_from_l2
rerun-check:
runs-on: ubuntu-20.04
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ jobs:
fail-fast: false
matrix:
config:
- test: reorg.test.ts
values: ci
runner_type: 16core-tester-x86-high-memory
timeout: 60
# - test: reorg.test.ts
# values: ci
# runner_type: 16core-tester-x86-high-memory
# timeout: 60
- test: 4epochs.test.ts
values: ci
runner_type: 16core-tester-x86
Expand Down
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3c488f4b272f460383341c51270b87bfe2b94468
db28cb9ffb710c286b54dbfcf57292ae3dffb03d
4 changes: 2 additions & 2 deletions Dockerfile.boxes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM aztecprotocol/ci:2.0
FROM aztecprotocol/ci:2.2
COPY /usr/src /usr/src
WORKDIR /usr/src/boxes
RUN ls /usr/src/boxes
RUN /usr/local/share/docker-init.sh &> /dev/null && ./bootstrap.sh test
RUN /usr/local/share/docker-init.sh &> /dev/null && ./bootstrap.sh test
12 changes: 12 additions & 0 deletions aztec-nargo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## `aztec-nargo`

The `aztec-nargo` utility is packaged with docker and does the following:
1. If the first argument to `aztec-nargo` is not `compile`, it just forwards args to `nargo` and exits.
1. If the first argument _is_ `compile`, it forwards args to `nargo` with some added options (like `--inliner-aggressiveness 0 --show-artifact-paths`)
3. Extracts all artifacts modified by `nargo`
4. Transpiles each artifact using the `avm-transpiler`
5. Generates verification keys for each artifact using `bb` (`barretenberg`'s binary)

Example usage: `aztec-nargo compile`

Note: uses versions of each tool from this repository (`nargo` version is from `../noir`).
2 changes: 1 addition & 1 deletion aztec-up/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the user's `PATH` variable in their shell startup script so they can be found.

- `aztec` - The infrastructure container.
- `aztec-cli` - A command-line tool for interacting with infrastructure.
- `aztec-nargo` - A build of `nargo` from `noir` that is guaranteed to be version-aligned. Provides compiler, lsp and more.
- `aztec-nargo` - A build of `nargo` from `noir` that is guaranteed to be version-aligned. Provides compiler, lsp and more. On `aztec-nargo compile <...>`, automatically transpiles artifacts using `avm-transpiler` and generates verification keys using `bb`.
- `aztec-sandbox` - A wrapper around docker-compose that launches services needed for sandbox testing.
- `aztec-up` - A tool to upgrade the aztec toolchain to the latest, or specific versions.
- `aztec-builder` - A useful tool for projects to generate ABIs and update their dependencies.
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/AztecProtocol/barretenberg
branch = master
commit = 560058aa5ec26a23436f09d89a8b80633fbee785
parent = 36b640aed54fd4da0f9899300bf7b0d05faf5b8d
commit = 37aa7c0fb0224521c00673584b0adc9be11640d8
parent = 231f017d14c3d261b28ab19dcbdf368c561d0cc7
method = merge
cmdver = 0.4.6
7 changes: 7 additions & 0 deletions barretenberg/cpp/pil/vm2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Compile with:

```
~/aztec-packages/bb-pilcom/target/release/bb_pil pil/vm2/execution.pil --name Avm2 -y -o src/barretenberg/vm2/generated && ./format.sh changed
```

while on the `barretenberg/cpp` directory.
21 changes: 21 additions & 0 deletions barretenberg/cpp/pil/vm2/addressing.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This is a virtual gadget, which is part of the execution trace.
namespace execution(256);

pol commit stack_pointer_val;
pol commit stack_pointer_tag;
pol commit sel_addressing_error; // true if any error type
pol commit addressing_error_kind; // TODO: might need to be selectors
pol commit addressing_error_idx; // operand index for error, if any

// whether each operand is an address for the given opcode.
// retrieved from the instruction spec.
pol commit sel_op1_is_address;
pol commit sel_op2_is_address;
pol commit sel_op3_is_address;
pol commit sel_op4_is_address;
// operands after relative resolution
pol commit op1_after_relative;
pol commit op2_after_relative;
pol commit op3_after_relative;
pol commit op4_after_relative;
// operands after indirect resolution are the resolved_operands rop1, ...
16 changes: 16 additions & 0 deletions barretenberg/cpp/pil/vm2/alu.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace alu(256);

pol commit sel_op_add;
pol commit ia;
pol commit ib;
pol commit ic;
pol commit op;
pol commit ia_addr;
pol commit ib_addr;
pol commit dst_addr;

#[SEL_ADD_BINARY]
sel_op_add * (1 - sel_op_add) = 0;

#[ALU_ADD]
ia + ib = ic;
55 changes: 55 additions & 0 deletions barretenberg/cpp/pil/vm2/execution.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
include "alu.pil";
include "addressing.pil";
include "precomputed.pil";

namespace execution(256);

pol commit sel; // subtrace selector

pol commit ex_opcode;
pol commit indirect;
// operands
pol commit op1;
pol commit op2;
pol commit op3;
pol commit op4;
// resolved operands
pol commit rop1;
pol commit rop2;
pol commit rop3;
pol commit rop4;

pol commit pc;
pol commit clk;
pol commit last;

// Selector constraints
sel * (1 - sel) = 0;
last * (1 - last) = 0;

// If the current row is an execution row, then either
// the next row is an execution row, or the current row is marked as the last row.
// sel => (sel' v last) = 1 iff
// ¬sel v (sel' v last) = 1 iff
// ¬(¬sel v (sel' v last)) = 0 iff
// sel ^ (¬sel' ^ ¬last) = 0 iff
// sel * (1 - sel') * (1 - last) = 0
#[TRACE_CONTINUITY_1]
sel * (1 - sel') * (1 - last) = 0;
// If the current row is not an execution row, then there are no more execution rows after that.
// (not enforced for the first row)
#[TRACE_CONTINUITY_2]
(1 - precomputed.first_row) * (1 - sel) * sel' = 0;
// If the current row is the last row, then the next row is not an execution row.
#[LAST_IS_LAST]
last * sel' = 0;

// These are needed to have a non-empty set of columns for each type.
pol public input;
#[LOOKUP_DUMMY_PRECOMPUTED]
sel {/*will be 1=OR*/ sel, clk, clk, clk} in
precomputed.sel_bitwise {precomputed.bitwise_op_id, precomputed.bitwise_input_a, precomputed.bitwise_input_b, precomputed.bitwise_output};
#[LOOKUP_DUMMY_DYNAMIC] // Just a self-lookup for now, for testing.
sel {op1, op2, op3, op4} in sel {op1, op2, op3, op4};
#[PERM_DUMMY_DYNAMIC] // Just a self-permutation for now, for testing.
sel {op1, op2, op3, op4} is sel {op1, op2, op3, op4};
17 changes: 17 additions & 0 deletions barretenberg/cpp/pil/vm2/precomputed.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// General/shared precomputed columns.
namespace precomputed(256);

// From 0 and incrementing up to the size of the circuit (2^21).
pol constant clk;

// 1 only at row 0.
pol constant first_row;

// AND/OR/XOR of all 8-bit numbers.
// The tables are "stacked". First AND, then OR, then XOR.
// Note: think if we can avoid the selector.
pol constant sel_bitwise; // 1 in the first 3 * 256 rows.
pol constant bitwise_op_id; // identifies if operation is AND/OR/XOR.
pol constant bitwise_input_a; // column of all 8-bit numbers.
pol constant bitwise_input_b; // column of all 8-bit numbers.
pol constant bitwise_output; // output = a AND/OR/XOR b.
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_subdirectory(barretenberg/transcript)
add_subdirectory(barretenberg/translator_vm)
add_subdirectory(barretenberg/ultra_honk)
add_subdirectory(barretenberg/vm)
add_subdirectory(barretenberg/vm2)
add_subdirectory(barretenberg/wasi)
add_subdirectory(barretenberg/world_state)

Expand Down Expand Up @@ -171,6 +172,7 @@ set(BARRETENBERG_TARGET_OBJECTS
if(NOT DISABLE_AZTEC_VM)
# enable AVM
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:vm_objects>)
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:vm2_objects>)
endif()

if(NOT WASM)
Expand Down
84 changes: 75 additions & 9 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "barretenberg/bb/file_io.hpp"
#include "barretenberg/client_ivc/client_ivc.hpp"
#include "barretenberg/common/benchmark.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/common/map.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/common/timer.hpp"
Expand All @@ -13,7 +14,6 @@
#include "barretenberg/dsl/acir_format/proof_surgeon.hpp"
#include "barretenberg/dsl/acir_proofs/acir_composer.hpp"
#include "barretenberg/dsl/acir_proofs/honk_contract.hpp"
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/honk/proof_system/types/proof.hpp"
#include "barretenberg/numeric/bitop/get_msb.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
Expand All @@ -24,15 +24,17 @@
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_keccak_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_rollup_flavor.hpp"
#include "barretenberg/vm/avm/trace/public_inputs.hpp"
#include <cstdint>

#ifndef DISABLE_AZTEC_VM
#include "barretenberg/vm/avm/generated/flavor.hpp"
#include "barretenberg/vm/avm/trace/common.hpp"
#include "barretenberg/vm/avm/trace/execution.hpp"
#include "barretenberg/vm/avm/trace/public_inputs.hpp"
#include "barretenberg/vm/aztec_constants.hpp"
#include "barretenberg/vm/stats.hpp"
#include "barretenberg/vm2/avm_api.hpp"
#include "barretenberg/vm2/common/aztec_types.hpp"
#include "barretenberg/vm2/common/constants.hpp"
#endif

using namespace bb;
Expand Down Expand Up @@ -671,6 +673,16 @@ void vk_as_fields(const std::string& vk_path, const std::string& output_path)
}

#ifndef DISABLE_AZTEC_VM
void print_avm_stats()
{
#ifdef AVM_TRACK_STATS
info("------- STATS -------");
const auto& stats = avm_trace::Stats::get();
const int levels = std::getenv("AVM_STATS_DEPTH") != nullptr ? std::stoi(std::getenv("AVM_STATS_DEPTH")) : 2;
info(stats.to_string(levels));
#endif
}

/**
* @brief Writes an avm proof and corresponding (incomplete) verification key to files.
*
Expand Down Expand Up @@ -726,12 +738,34 @@ void avm_prove(const std::filesystem::path& public_inputs_path,
write_file(vk_fields_path, { vk_json.begin(), vk_json.end() });
vinfo("vk as fields written to: ", vk_fields_path);

#ifdef AVM_TRACK_STATS
info("------- STATS -------");
const auto& stats = avm_trace::Stats::get();
const int levels = std::getenv("AVM_STATS_DEPTH") != nullptr ? std::stoi(std::getenv("AVM_STATS_DEPTH")) : 2;
info(stats.to_string(levels));
#endif
print_avm_stats();
}

void avm2_prove(const std::filesystem::path& inputs_path, const std::filesystem::path& output_path)
{
avm2::AvmAPI avm;
auto inputs = avm2::AvmAPI::ProvingInputs::from(read_file(inputs_path));

// This is bigger than CIRCUIT_SUBGROUP_SIZE because of BB inefficiencies.
init_bn254_crs(avm2::CIRCUIT_SUBGROUP_SIZE * 2);
auto [proof, vk] = avm.prove(inputs);

// NOTE: As opposed to Avm1 and other proof systems, the public inputs are NOT part of the proof.
write_file(output_path / "proof", to_buffer(proof));
write_file(output_path / "vk", vk);

print_avm_stats();
}

void avm2_check_circuit(const std::filesystem::path& inputs_path)
{
avm2::AvmAPI avm;
auto inputs = avm2::AvmAPI::ProvingInputs::from(read_file(inputs_path));

bool res = avm.check_circuit(inputs);
info("circuit check: ", res ? "success" : "failure");

print_avm_stats();
}

/**
Expand Down Expand Up @@ -783,8 +817,28 @@ bool avm_verify(const std::filesystem::path& proof_path, const std::filesystem::

const bool verified = AVM_TRACK_TIME_V("verify/all", avm_trace::Execution::verify(vk, proof));
vinfo("verified: ", verified);

print_avm_stats();
return verified;
}

// NOTE: The proof should NOT include the public inputs.
bool avm2_verify(const std::filesystem::path& proof_path,
const std::filesystem::path& public_inputs_path,
const std::filesystem::path& vk_path)
{
const auto proof = many_from_buffer<fr>(read_file(proof_path));
std::vector<uint8_t> vk_bytes = read_file(vk_path);
auto public_inputs = avm2::PublicInputs::from(read_file(public_inputs_path));

init_bn254_crs(1);
avm2::AvmAPI avm;
bool res = avm.verify(proof, public_inputs, vk_bytes);
info("verification: ", res ? "success" : "failure");

print_avm_stats();
return res;
}
#endif

/**
Expand Down Expand Up @@ -1382,6 +1436,18 @@ int main(int argc, char* argv[])
std::string output_path = get_option(args, "-o", "./target");
write_recursion_inputs_honk<UltraRollupFlavor>(bytecode_path, witness_path, output_path, recursive);
#ifndef DISABLE_AZTEC_VM
} else if (command == "avm2_prove") {
std::filesystem::path inputs_path = get_option(args, "--avm-inputs", "./target/avm_inputs.bin");
// This outputs both files: proof and vk, under the given directory.
std::filesystem::path output_path = get_option(args, "-o", "./proofs");
avm2_prove(inputs_path, output_path);
} else if (command == "avm2_check_circuit") {
std::filesystem::path inputs_path = get_option(args, "--avm-inputs", "./target/avm_inputs.bin");
avm2_check_circuit(inputs_path);
} else if (command == "avm2_verify") {
std::filesystem::path public_inputs_path =
get_option(args, "--avm-public-inputs", "./target/avm_public_inputs.bin");
return avm2_verify(proof_path, public_inputs_path, vk_path) ? 0 : 1;
} else if (command == "avm_prove") {
std::filesystem::path avm_public_inputs_path =
get_option(args, "--avm-public-inputs", "./target/avm_public_inputs.bin");
Expand Down
Loading

0 comments on commit ede6f10

Please sign in to comment.