Skip to content

Commit

Permalink
Merge branch 'master' into 04-05-feat_avm_enable_contract_testing_wit…
Browse files Browse the repository at this point in the history
…h_bb_binary
  • Loading branch information
fcarreiro authored Apr 9, 2024
2 parents bbd1741 + 1d18a5e commit 0f7eb1a
Show file tree
Hide file tree
Showing 317 changed files with 5,179 additions and 4,123 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
# there's a lot of x86 tasks - let's split out the build step
build-x86:
if: github.actor == 'ludamad' || github.actor == 'charlielye'
runs-on: ubuntu-latest
outputs:
e2e_list: ${{ steps.e2e_list.outputs.list }}
Expand Down Expand Up @@ -45,6 +46,7 @@ jobs:
# all the end-to-end integration tests for aztec
e2e-arm:
runs-on: ubuntu-latest
if: github.actor == 'ludamad' || github.actor == 'charlielye'
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
strategy:
Expand Down Expand Up @@ -82,6 +84,7 @@ jobs:
e2e-x86:
needs: build-x86
runs-on: ubuntu-latest
if: github.actor == 'ludamad' || github.actor == 'charlielye'
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
strategy:
Expand Down Expand Up @@ -122,6 +125,7 @@ jobs:
# barretenberg (prover) native tests
bb-native-tests:
runs-on: ubuntu-latest
if: github.actor == 'ludamad' || github.actor == 'charlielye'
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
strategy:
Expand Down Expand Up @@ -158,6 +162,7 @@ jobs:
# We don't depend on 'build' as we use a different runner and will build components on the fist step that uses them.
bench:
runs-on: ubuntu-latest
if: github.actor == 'ludamad' || github.actor == 'charlielye'
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
# cancel if reran on same PR if exists, otherwise if on same commit
Expand Down
10 changes: 5 additions & 5 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
".": "0.32.1",
"yarn-project/cli": "0.32.1",
"yarn-project/aztec": "0.32.1",
"barretenberg": "0.32.1",
"barretenberg/ts": "0.32.1"
".": "0.33.0",
"yarn-project/cli": "0.33.0",
"yarn-project/aztec": "0.33.0",
"barretenberg": "0.33.0",
"barretenberg/ts": "0.33.0"
}
97 changes: 97 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ fn handle_getter_instruction(
"avmOpcodeVersion" => AvmOpcode::VERSION,
"avmOpcodeBlockNumber" => AvmOpcode::BLOCKNUMBER,
"avmOpcodeTimestamp" => AvmOpcode::TIMESTAMP,
"avmOpcodeL1GasLeft" => AvmOpcode::L1GASLEFT,
"avmOpcodeL2GasLeft" => AvmOpcode::L2GASLEFT,
"avmOpcodeDaGasLeft" => AvmOpcode::DAGASLEFT,
// "callStackDepth" => AvmOpcode::CallStackDepth,
_ => panic!(
"Transpiler doesn't know how to process ForeignCall function {:?}",
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 = e306a486cd0948214ab8b056ff753fe47ba2feb9
parent = be6f8432c9beaf8c6ee30e65fd5354576870eeff
commit = 30ec33720e7374dd4ebbd4d938bdd1a04a204611
parent = a9a349db3902970a2b484b5e1509931423ac5775
method = merge
cmdver = 0.4.6
23 changes: 23 additions & 0 deletions barretenberg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## [0.33.0](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.32.1...barretenberg-v0.33.0) (2024-04-09)


### ⚠ BREAKING CHANGES

* **acir:** Add predicate to call opcode ([#5616](https://github.com/AztecProtocol/aztec-packages/issues/5616))

### Features

* **acir:** Add predicate to call opcode ([#5616](https://github.com/AztecProtocol/aztec-packages/issues/5616)) ([e8cec0a](https://github.com/AztecProtocol/aztec-packages/commit/e8cec0a81da29a1b4df8bc6c70b04e37902f7609))
* Avm logup ([#5577](https://github.com/AztecProtocol/aztec-packages/issues/5577)) ([7e4e9b9](https://github.com/AztecProtocol/aztec-packages/commit/7e4e9b9830c3beb6396ccd3110dda09d3f4e2d59))
* **avm:** Contract instance opcode ([#5487](https://github.com/AztecProtocol/aztec-packages/issues/5487)) ([ceacba6](https://github.com/AztecProtocol/aztec-packages/commit/ceacba6cbb6d070ec3e5e42673b9ab11dab79566))
* **avm:** Indirect memory for set opcode ([#5546](https://github.com/AztecProtocol/aztec-packages/issues/5546)) ([e0e7200](https://github.com/AztecProtocol/aztec-packages/commit/e0e7200819d30170d3d84d42540015d24d7cb1e8)), closes [#5542](https://github.com/AztecProtocol/aztec-packages/issues/5542)
* DataBus notion with calldata/return data ([#5504](https://github.com/AztecProtocol/aztec-packages/issues/5504)) ([95a1d8a](https://github.com/AztecProtocol/aztec-packages/commit/95a1d8ac45e0db8ec21ba1cb2e3f47bb68909b71))
* Optimise relations ([#5552](https://github.com/AztecProtocol/aztec-packages/issues/5552)) ([a581e80](https://github.com/AztecProtocol/aztec-packages/commit/a581e80dedfd0398d4f8a831b4e0031e8460dff7))
* Optimize auxiliary relations slightly ([#5517](https://github.com/AztecProtocol/aztec-packages/issues/5517)) ([30be431](https://github.com/AztecProtocol/aztec-packages/commit/30be43186980672a271fc568344f0341055c7b57))


### Miscellaneous

* ECCVM flavor depends on builder ([#5323](https://github.com/AztecProtocol/aztec-packages/issues/5323)) ([a594683](https://github.com/AztecProtocol/aztec-packages/commit/a5946836eb52f8d836a05de31725d1e0f741a6db))
* Get rid of ECCVM composer ([#5562](https://github.com/AztecProtocol/aztec-packages/issues/5562)) ([43ed901](https://github.com/AztecProtocol/aztec-packages/commit/43ed901838dc2f8d59c665bd667ceec81d31bbdc))

## [0.32.1](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.32.0...barretenberg-v0.32.1) (2024-04-02)


Expand Down
2 changes: 1 addition & 1 deletion barretenberg/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 FATAL_ERROR)
project(
Barretenberg
DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover"
VERSION 0.32.1 # x-release-please-version
VERSION 0.33.0 # x-release-please-version
LANGUAGES CXX C
)
# Insert version into `bb` config file
Expand Down
17 changes: 13 additions & 4 deletions barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ProverInstance(Circuit&)(t)",
"ProtogalaxyProver::fold_instances(t)",
"Decider::construct_proof(t)",
"ECCVMComposer::create_prover(t)",
"ECCVMProver(CircuitBuilder&)(t)",
"ECCVMProver::construct_proof(t)",
"GoblinTranslatorProver::construct_proof(t)",
"Goblin::merge(t)"
Expand All @@ -31,7 +31,10 @@
print(
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>8}")
for key in to_keep:
time_ms = bench[key]/1e6
if key not in bench:
time_ms = 0
else:
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

# Validate that kept times account for most of the total measured time.
Expand All @@ -45,7 +48,10 @@
print(
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>7}")
for key in ['commit(t)', 'compute_combiner(t)', 'compute_perturbator(t)', 'compute_univariate(t)']:
time_ms = bench[key]/1e6
if key not in bench:
time_ms = 0
else:
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

print('\nBreakdown of ProtogalaxyProver::fold_instances:')
Expand All @@ -57,7 +63,10 @@
]
max_label_length = max(len(label) for label in protogalaxy_round_labels)
for key in protogalaxy_round_labels:
time_ms = bench[key]/1e6
if key not in bench:
time_ms = 0
else:
time_ms = bench[key]/1e6
total_time_ms = bench["ProtogalaxyProver::fold_instances(t)"]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}")

Expand Down
61 changes: 61 additions & 0 deletions barretenberg/cpp/scripts/analyze_protogalaxy_bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import json
from pathlib import Path

PREFIX = Path("build-op-count-time")
PROTOGALAXY_BENCH_JSON = Path("protogalaxy_bench.json")
BENCHMARK = "fold_k<GoblinUltraFlavor, 3>/16"

# Single out an independent set of functions accounting for most of BENCHMARK's real_time
to_keep = [
"ProtogalaxyProver::fold_instances(t)",
]
with open(PREFIX/PROTOGALAXY_BENCH_JSON, "r") as read_file:
read_result = json.load(read_file)
for _bench in read_result["benchmarks"]:
print(_bench)
if _bench["name"] == BENCHMARK:
bench = _bench
bench_components = dict(filter(lambda x: x[0] in to_keep, bench.items()))

# For each kept time, get the proportion over all kept times.
sum_of_kept_times_ms = sum(float(time)
for _, time in bench_components.items())/1e6
max_label_length = max(len(label) for label in to_keep)
column = {"function": "function", "ms": "ms", "%": "% sum"}
print(
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>8}")
for key in to_keep:
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

# Validate that kept times account for most of the total measured time.
total_time_ms = bench["real_time"]
totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}'
totals = totals.format(
sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms)
print(totals)

print("\nMajor contributors:")
print(
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>7}")
for key in ['commit(t)', 'compute_combiner(t)', 'compute_perturbator(t)', 'compute_univariate(t)']:
if key not in bench:
time_ms = 0
else:
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

print('\nBreakdown of ProtogalaxyProver::fold_instances:')
protogalaxy_round_labels = [
"ProtoGalaxyProver_::preparation_round(t)",
"ProtoGalaxyProver_::perturbator_round(t)",
"ProtoGalaxyProver_::combiner_quotient_round(t)",
"ProtoGalaxyProver_::accumulator_update_round(t)"
]
max_label_length = max(len(label) for label in protogalaxy_round_labels)
for key in protogalaxy_round_labels:
time_ms = bench[key]/1e6
total_time_ms = bench["ProtogalaxyProver::fold_instances(t)"]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}")


25 changes: 25 additions & 0 deletions barretenberg/cpp/scripts/benchmark_protogalaxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -eu

TARGET="protogalaxy_bench"
FILTER="/16$"
BUILD_DIR=build-op-count-time

# Move above script dir.
cd $(dirname $0)/..

# Measure the benchmarks with ops time counting
./scripts/benchmark_remote.sh protogalaxy_bench\
"./protogalaxy_bench --benchmark_filter=$FILTER\
--benchmark_out=$TARGET.json\
--benchmark_out_format=json"\
op-count-time\
build-op-count-time

# Retrieve output from benching instance
cd $BUILD_DIR
scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/$TARGET.json .

# Analyze the results
cd ../
python3 ./scripts/analyze_protogalaxy_bench.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <benchmark/benchmark.h>

#include "barretenberg/eccvm/eccvm_circuit_builder.hpp"
#include "barretenberg/eccvm/eccvm_composer.hpp"
#include "barretenberg/eccvm/eccvm_prover.hpp"
#include "barretenberg/eccvm/eccvm_verifier.hpp"

using namespace benchmark;
using namespace bb;

using Flavor = ECCVMFlavor;
using Builder = ECCVMCircuitBuilder;
using Composer = ECCVMComposer;

namespace {

Expand Down Expand Up @@ -49,8 +49,7 @@ void eccvm_generate_prover(State& state) noexcept
size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
for (auto _ : state) {
Builder builder = generate_trace(target_num_gates);
Composer composer;
auto prover = composer.create_prover(builder);
ECCVMProver prover(builder);
};
}

Expand All @@ -60,8 +59,7 @@ void eccvm_prove(State& state) noexcept

size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
Builder builder = generate_trace(target_num_gates);
Composer composer;
auto prover = composer.create_prover(builder);
ECCVMProver prover(builder);
for (auto _ : state) {
auto proof = prover.construct_proof();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <benchmark/benchmark.h>

#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
Expand All @@ -11,11 +12,11 @@ using namespace benchmark;
namespace bb {

// Fold one instance into an accumulator.
template <typename Flavor> void fold_one(State& state) noexcept
template <typename Flavor, size_t k> void fold_k(State& state) noexcept
{
using ProverInstance = ProverInstance_<Flavor>;
using Instance = ProverInstance;
using Instances = ProverInstances_<Flavor, 2>;
using Instances = ProverInstances_<Flavor, k + 1>;
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>;
using Builder = typename Flavor::CircuitBuilder;

Expand All @@ -28,19 +29,29 @@ template <typename Flavor> void fold_one(State& state) noexcept
MockCircuits::construct_arithmetic_circuit(builder, log2_num_gates);
return std::make_shared<ProverInstance>(builder);
};
std::vector<std::shared_ptr<Instance>> instances;
// TODO(https://github.com/AztecProtocol/barretenberg/issues/938): Parallelize this loop
for (size_t i = 0; i < k + 1; ++i) {
instances.emplace_back(construct_instance());
}

std::shared_ptr<Instance> instance_1 = construct_instance();
std::shared_ptr<Instance> instance_2 = construct_instance();

ProtoGalaxyProver folding_prover({ instance_1, instance_2 });
ProtoGalaxyProver folding_prover(instances);

for (auto _ : state) {
BB_REPORT_OP_COUNT_IN_BENCH(state);
auto proof = folding_prover.fold_instances();
}
}

BENCHMARK(fold_one<UltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_one<GoblinUltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_k<UltraFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_k<GoblinUltraFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);

BENCHMARK(fold_k<UltraFlavor, 2>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_k<GoblinUltraFlavor, 2>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);

BENCHMARK(fold_k<UltraFlavor, 3>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_k<GoblinUltraFlavor, 3>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);

} // namespace bb

BENCHMARK_MAIN();
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_<Prover
return std::make_shared<ProverInstance>(builder);
};

// TODO(https://github.com/AztecProtocol/barretenberg/issues/938): Parallelize this loop, also extend to more than
// k=1
std::shared_ptr<ProverInstance> prover_instance_1 = construct_instance();
std::shared_ptr<ProverInstance> prover_instance_2 = construct_instance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
VerifierCommitmentKey(size_t num_points, const std::shared_ptr<bb::srs::factories::CrsFactory<Curve>>& crs_factory)
: pippenger_runtime_state(num_points)
, srs(crs_factory->get_verifier_crs(num_points))

{}

VerifierCommitmentKey(size_t num_points)
: pippenger_runtime_state(num_points)
{
srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
srs = srs::get_crs_factory<Curve>()->get_verifier_crs(num_points);
}

bb::scalar_multiplication::pippenger_runtime_state<Curve> pippenger_runtime_state;
std::shared_ptr<bb::srs::factories::VerifierCrs<Curve>> srs;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ struct Opcode {
uint32_t id;
std::vector<Program::Witness> inputs;
std::vector<Program::Witness> outputs;
std::optional<Program::Expression> predicate;

friend bool operator==(const Call&, const Call&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -7491,6 +7492,9 @@ inline bool operator==(const Opcode::Call& lhs, const Opcode::Call& rhs)
if (!(lhs.outputs == rhs.outputs)) {
return false;
}
if (!(lhs.predicate == rhs.predicate)) {
return false;
}
return true;
}

Expand Down Expand Up @@ -7520,6 +7524,7 @@ void serde::Serializable<Program::Opcode::Call>::serialize(const Program::Opcode
serde::Serializable<decltype(obj.id)>::serialize(obj.id, serializer);
serde::Serializable<decltype(obj.inputs)>::serialize(obj.inputs, serializer);
serde::Serializable<decltype(obj.outputs)>::serialize(obj.outputs, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
}

template <>
Expand All @@ -7530,6 +7535,7 @@ Program::Opcode::Call serde::Deserializable<Program::Opcode::Call>::deserialize(
obj.id = serde::Deserializable<decltype(obj.id)>::deserialize(deserializer);
obj.inputs = serde::Deserializable<decltype(obj.inputs)>::deserialize(deserializer);
obj.outputs = serde::Deserializable<decltype(obj.outputs)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
return obj;
}

Expand Down
Loading

0 comments on commit 0f7eb1a

Please sign in to comment.