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
benesjan authored Jan 8, 2025
2 parents 65a86c8 + cd5a615 commit 5e1a124
Show file tree
Hide file tree
Showing 325 changed files with 7,959 additions and 4,522 deletions.
4 changes: 2 additions & 2 deletions .github/ensure-builder/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ runs:
ec2_subnet_id: subnet-4cfabd25
ec2_security_group_id: sg-0ccd4e5df0dcca0c9
ec2_key_name: "build-instance"
ec2_instance_tags: '[{"Key": "Keep-Alive", "Value": "true"},{"Key": "Builder", "Value": "true"}]'
ec2_instance_tags: '[{"Key": "Builder", "Value": "true"}]'
# This disambiguates from 'tester'
- name: Set BUILDER_SPOT_IP and BUILDER_SPOT_KEY
shell: bash
Expand Down Expand Up @@ -100,4 +100,4 @@ runs:
- name: Report Exit Code
shell: bash
if: steps.test.outputs.exit_code != '155' || inputs.spot_strategy == 'None'
run: exit ${{ steps.test.outputs.exit_code }}
run: exit ${{ steps.test.outputs.exit_code }}
4 changes: 2 additions & 2 deletions .github/ensure-tester/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ runs:
ec2_subnet_id: subnet-4cfabd25
ec2_security_group_id: sg-0ccd4e5df0dcca0c9
ec2_key_name: "build-instance"
ec2_instance_tags: '[{"Key": "Keep-Alive", "Value": "true"}]'
ec2_instance_tags: '[]'

- name: Ensure Tester Cleanup
uses: gacts/run-and-post-run@v1
Expand Down Expand Up @@ -107,4 +107,4 @@ runs:
- name: Report Exit Code
shell: bash
if: steps.test.outputs.exit_code != '155' || inputs.spot_strategy == 'None'
run: exit ${{ steps.test.outputs.exit_code }}
run: exit ${{ steps.test.outputs.exit_code }}
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ jobs:

protocol-circuits-gates-report:
needs: [ci-rest, configure]
if: needs.configure.outputs.non-docs == 'true' && needs.configure.outputs.non-bb == 'true'
if: github.ref_name == 'master' || (needs.configure.outputs.non-docs == 'true' && needs.configure.outputs.non-bb == 'true')
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand All @@ -582,7 +582,7 @@ jobs:
scripts/copy_from_builder ./noir-projects/gates_report.json protocol_circuits_report.json
- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@84ada11295b9a1e1da7325af4e45e2db9f775175
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
continue-on-error: true
timeout-minutes: 1
with:
Expand All @@ -600,7 +600,7 @@ jobs:

public-functions-size-report:
needs: [ci-rest, configure]
if: needs.configure.outputs.non-docs == 'true'
if: github.ref_name == 'master' || needs.configure.outputs.non-docs == 'true'
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand All @@ -620,7 +620,7 @@ jobs:
scripts/copy_from_builder noir-projects/public_functions_report.json public_functions_report.json
- name: Compare public functions bytecode size reports
id: public_functions_sizes_diff
uses: noir-lang/noir-gates-diff@84ada11295b9a1e1da7325af4e45e2db9f775175
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
continue-on-error: true
timeout-minutes: 1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-aztec-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
timeout-minutes: 80
run: |
sudo shutdown -P 80
./bootstrap.sh image-aztec
./bootstrap.sh image-aztec --check-arch
docker tag aztecprotocol/aztec:${{ env.GIT_COMMIT }} aztecprotocol/aztec:${{ env.GIT_COMMIT }}-arm64
docker push aztecprotocol/aztec:${{ env.GIT_COMMIT }}-arm64
build-nargo-x86:
Expand Down
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ docs-with-cache:
FROM +bootstrap
ENV CI=1
ENV USE_CACHE=1
LET artifact=docs-ci-deploy-$(./boxes/bootstrap.sh hash)
LET artifact=docs-ci-deploy-$(./docs/bootstrap.sh hash)
IF ci3/test_should_run $artifact
WAIT
BUILD --pass-args ./docs/+deploy-preview
Expand Down
33 changes: 0 additions & 33 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = e50b5c03a005fc294414b3b9c103bb17e42598fa
parent = 9eaa10983b26616876099896accb0e3093ae8d20
commit = bfda2c9914f49f917bae7d62f27555e7ff3e6b4f
parent = b73f7f9442f9a51e82925dea3c32bc64173d81e5
method = merge
cmdver = 0.4.6
16 changes: 9 additions & 7 deletions barretenberg/acir_tests/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ function prepare_tests {
# TODO(https://github.com/AztecProtocol/barretenberg/issues/1108): problem regardless the proof system used
rm -rf acir_tests/regression_5045

# Regenerate verify_honk_proof and verify_rollup_honk_proof recursive input.
echo "Regenerating verify_honk_proof and verify_rollup_honk_proof recursive inputs."
COMPILE=2 ./run_test.sh assert_statement
local bb=$(realpath ../cpp/build/bin/bb)
(cd ./acir_tests/assert_statement && \
$bb write_recursion_inputs_ultra_honk -b ./target/program.json -o ../../../../noir/noir-repo/test_programs/execution_success/verify_honk_proof --recursive && \
$bb write_recursion_inputs_rollup_honk -b ./target/program.json -o ../../../../noir/noir-repo/test_programs/execution_success/verify_rollup_honk_proof --recursive && \
cp -R ../../../../noir/noir-repo/test_programs/execution_success/verify_honk_proof .. && cp -R ../../../../noir/noir-repo/test_programs/execution_success/verify_rollup_honk_proof ..)

# COMPILE=2 only compiles the test.
denoise "parallel --joblog joblog.txt --line-buffered 'COMPILE=2 ./run_test.sh \$(basename {})' ::: ./acir_tests/*"

Expand All @@ -29,13 +38,6 @@ function build_tests {

prepare_tests


# TODO: This actually breaks things, but shouldn't. We want to do it here and not maintain manually.
# Regenerate verify_honk_proof recursive input.
# local bb=$(realpath ../cpp/build/bin/bb)
# (cd ./acir_tests/assert_statement && \
# $bb write_recursion_inputs_honk -b ./target/program.json -o ../verify_honk_proof --recursive)

# Update yarn.lock so it can be committed.
# Be lenient about bb.js hash changing, even if we try to minimize the occurrences.
denoise "cd browser-test-app && yarn add --dev @aztec/bb.js@../../ts && yarn"
Expand Down
51 changes: 0 additions & 51 deletions barretenberg/acir_tests/regenerate_verify_honk_proof_inputs.sh

This file was deleted.

12 changes: 6 additions & 6 deletions barretenberg/cpp/pil/avm/constants_gen.pil
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace constants(256);
pol MAX_NULLIFIERS_PER_CALL = 16;
pol MAX_ENQUEUED_CALLS_PER_CALL = 16;
pol MAX_L2_TO_L1_MSGS_PER_CALL = 2;
pol MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 64;
pol MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 63;
pol MAX_PUBLIC_DATA_READS_PER_CALL = 64;
pol MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 16;
pol MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 16;
Expand Down Expand Up @@ -38,9 +38,9 @@ namespace constants(256);
pol START_NULLIFIER_NON_EXISTS_OFFSET = 32;
pol START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = 48;
pol START_SSTORE_WRITE_OFFSET = 64;
pol START_SLOAD_WRITE_OFFSET = 128;
pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 192;
pol START_EMIT_NULLIFIER_WRITE_OFFSET = 208;
pol START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 224;
pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 226;
pol START_SLOAD_WRITE_OFFSET = 127;
pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 191;
pol START_EMIT_NULLIFIER_WRITE_OFFSET = 207;
pol START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 223;
pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 225;

4 changes: 4 additions & 0 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ if(SMT)
add_subdirectory(barretenberg/smt_verification)
endif()

if(SMT AND ACIR_FORMAL_PROOFS)
add_subdirectory(barretenberg/acir_formal_proofs)
endif()

add_subdirectory(barretenberg/benchmark)

include(GNUInstallDirs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
barretenberg_module(acir_formal_proofs dsl circuit_checker smt_verification common)
47 changes: 47 additions & 0 deletions barretenberg/cpp/src/barretenberg/acir_formal_proofs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Formal Verification of ACIR Instructions

This module provides formal verification capabilities for ACIR (Arithmetic Circuit Intermediate Representation) instructions generated from Noir SSA code.

## Overview

The verifier uses SMT (Satisfiability Modulo Theories) solving to formally verify the correctness of ACIR instructions. It supports verification of:

- Arithmetic operations (add, subtract, multiply, divide)
- Bitwise operations (AND, OR, XOR, NOT)
- Shifts (left shift, right shift)
- Comparisons (equality, less than, greater than)
- Field arithmetic

## Tests

⚠️ **WARNING**: Do not run these tests on a local machine without sufficient memory (>32GB RAM). The tests can consume large amounts of memory and CPU resources. Some tests like integer division can run for multiple days. It is recommended to run these tests in a controlled environment with adequate resources.

### Results

| Opcode | Lhs type/size | Rhs type/size | Time/seconds | Memory/GB | Success | SMT Term Type | Reason |
| ----------- | ------------- | ------------- | ------------ | --------- | ------- | ---------------- | -------------------------- |
| Binary::Add | Field | Field | 0.024 | - | ✓ | TermType::FFTerm | |
| Binary::Add | Unsigned_127 | Unsigned_127 | 2.8 | - | ✓ | TermType::BVTerm | |
| Binary::And | Unsigned_32 | Unsigned_32 | 6.7 | - | ✓ | TermType::BVTerm | |
| Binary::And | Unsigned_127 | Unsigned_127 | 7.5 | - | ✗ | TermType::BVTerm | Probably bug in smt solver |
| Binary::Div | Field | Field | 0.024 | - | ✓ | TermType::FFTerm | |
| Binary::Div | Unsigned_126 | Unsigned_126 | 402.7 | 3.5 | ✗ | TermType::BVTerm | Analysis in progress |
| Binary::Div | Signed_126 | Signed_126 | >17 days | 5.1 | ✗ | TermType::ITerm | Test takes too long |
| Binary::Eq | Field | Field | 19.2 | - | ✓ | TermType::FFTerm | |
| Binary::Eq | Unsigned_127 | Unsigned_127 | 22.8 | - | ✓ | TermType::BVTerm | |
| Binary::Lt | Unsigned_127 | Unsigned_127 | 56.7 | - | ✓ | TermType::BVTerm | |
| Binary::Mod | Unsigned_127 | Unsigned_127 | - | 3.2 | ✗ | TermType::BVTerm | Analysis in progress |
| Binary::Mul | Field | Field | 0.024 | - | ✓ | TermType::FFTerm | |
| Binary::Mul | Unsigned_127 | Unsigned_127 | 10.0 | - | ✓ | TermType::BVTerm | |
| Binary::Or | Unsigned_32 | Unsigned_32 | 18.0 | - | ✓ | TermType::BVTerm | |
| Binary::Or | Unsigned_127 | Unsigned_127 | 7.5 | - | ✗ | TermType::BVTerm | Probably bug in smt solver |
| Binary::Shl | Unsigned_64 | Unsigned_8 | 42331.61 | 63.2 | ✓ | TermType::BVTerm | |
| Binary::Shl | Unsigned_32 | Unsigned_8 | 4574.0 | 30 | ✓ | TermType::BVTerm | |
| Binary::Shr | Unsigned_64 | Unsigned_8 | 3927.88 | 10 | ✓ | TermType::BVTerm | |
| Binary::Sub | Unsigned_127 | Unsigned_127 | 3.3 | - | ✓ | TermType::BVTerm | |
| Binary::Xor | Unsigned_32 | Unsigned_32 | 14.7 | - | ✓ | TermType::BVTerm | |
| Binary::Xor | Unsigned_127 | Unsigned_127 | 7.5 | - | ✗ | TermType::BVTerm | Probably bug in smt solver |
| Not | Unsigned_127 | - | 0.2 | - | ✓ | TermType::BVTerm | |


Each test attempts to find counterexamples that violate the expected behavior. A passing test indicates the operation is correctly implemented, while a failing test reveals potential issues.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "acir_loader.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp"
#include "barretenberg/smt_verification/circuit/ultra_circuit.hpp"
#include "barretenberg/smt_verification/terms/term.hpp"
#include "msgpack/v3/sbuffer_decl.hpp"
#include <fstream>
#include <string>
#include <vector>

std::vector<uint8_t> readFile(std::string filename)
{
std::ifstream file(filename, std::ios::binary);
file.unsetf(std::ios::skipws);

std::streampos fileSize;

file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);

std::vector<uint8_t> vec;

vec.insert(vec.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>());
file.close();
return vec;
}

AcirToSmtLoader::AcirToSmtLoader(std::string filename)
{
this->acir_program_buf = readFile(filename);
this->instruction_name = filename;
this->constraint_system = acir_format::program_buf_to_acir_format(this->acir_program_buf, false).at(0);
this->circuit_buf = this->get_circuit_builder().export_circuit();
}

bb::UltraCircuitBuilder AcirToSmtLoader::get_circuit_builder()
{
bb::UltraCircuitBuilder builder = acir_format::create_circuit(this->constraint_system, false);
builder.set_variable_name(0, "a");
builder.set_variable_name(1, "b");
builder.set_variable_name(2, "c");
return builder;
}

smt_solver::Solver AcirToSmtLoader::get_smt_solver()
{
smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(this->circuit_buf);
// In circuits generated by the shift left (shl) opcode, there is a variable with bit length 197.
// This is likely because the shl operation internally calls truncate opcode to handle overflow
return smt_solver::Solver(circuit_info.modulus, smt_circuit::default_solver_config, 16, 240);
}

smt_circuit::UltraCircuit AcirToSmtLoader::get_bitvec_smt_circuit(smt_solver::Solver* solver)
{
smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(this->circuit_buf);
return smt_circuit::UltraCircuit(circuit_info, solver, smt_terms::TermType::BVTerm);
}

smt_circuit::UltraCircuit AcirToSmtLoader::get_field_smt_circuit(smt_solver::Solver* solver)
{
smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(this->circuit_buf);
return smt_circuit::UltraCircuit(circuit_info, solver, smt_terms::TermType::FFTerm);
}

smt_circuit::UltraCircuit AcirToSmtLoader::get_integer_smt_circuit(smt_solver::Solver* solver)
{
smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(this->circuit_buf);
return smt_circuit::UltraCircuit(circuit_info, solver, smt_terms::TermType::ITerm);
}
Loading

0 comments on commit 5e1a124

Please sign in to comment.