-
Notifications
You must be signed in to change notification settings - Fork 316
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: mega zk features #9774
feat: mega zk features #9774
Changes from 32 commits
2c37dc4
7bbacc2
c78ed6e
fe93b4d
df7f731
0b3e50a
525ae12
4298d52
bf468eb
ab9b81e
aca70fa
b7584ba
6403477
bec76b9
8a1e95f
2504556
d18f0c2
937af2a
6824085
95d4160
6d35080
ac0afe5
b7b9fae
db32e48
69b913e
ed57e42
1775d41
e8c691a
2dc2170
3157236
6a32b27
84bf601
f2d4eb0
a94d29a
cef08d4
3fe9ed7
c24adea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" | ||
|
||
using namespace benchmark; | ||
using namespace bb; | ||
|
||
/** | ||
* @brief Benchmark: Construction of a Ultra Honk proof for a circuit determined by the provided circuit function | ||
*/ | ||
static void construct_proof_megahonk_zk(State& state, | ||
void (*test_circuit_function)(MegaCircuitBuilder&, size_t)) noexcept | ||
{ | ||
size_t num_iterations = 10; // 10x the circuit | ||
bb::mock_circuits::construct_proof_with_specified_num_iterations<MegaZKProver>( | ||
state, test_circuit_function, num_iterations); | ||
} | ||
|
||
/** | ||
* @brief Benchmark: Construction of a Ultra Plonk proof with 2**n gates | ||
*/ | ||
static void construct_proof_megahonk_power_of_2_zk(State& state) noexcept | ||
{ | ||
auto log2_of_gates = static_cast<size_t>(state.range(0)); | ||
bb::mock_circuits::construct_proof_with_specified_num_iterations<MegaZKProver>( | ||
state, &bb::mock_circuits::generate_basic_arithmetic_circuit<MegaCircuitBuilder>, log2_of_gates); | ||
} | ||
|
||
// Define benchmarks | ||
|
||
// This exists due to an issue where get_row was blowing up in time | ||
BENCHMARK_CAPTURE(construct_proof_megahonk_zk, sha256, &stdlib::generate_sha256_test_circuit<MegaCircuitBuilder>) | ||
->Unit(kMillisecond); | ||
BENCHMARK_CAPTURE(construct_proof_megahonk_zk, keccak, &stdlib::generate_keccak_test_circuit<MegaCircuitBuilder>) | ||
->Unit(kMillisecond); | ||
BENCHMARK_CAPTURE(construct_proof_megahonk_zk, | ||
ecdsa_verification, | ||
&stdlib::generate_ecdsa_verification_test_circuit<MegaCircuitBuilder>) | ||
->Unit(kMillisecond); | ||
BENCHMARK_CAPTURE(construct_proof_megahonk_zk, | ||
merkle_membership, | ||
&stdlib::generate_merkle_membership_test_circuit<MegaCircuitBuilder>) | ||
->Unit(kMillisecond); | ||
|
||
BENCHMARK(construct_proof_megahonk_power_of_2_zk) | ||
// 2**15 gates to 2**20 gates | ||
->DenseRange(15, 20) | ||
->Unit(kMillisecond); | ||
|
||
BENCHMARK_MAIN(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
#include "barretenberg/numeric/bitop/get_msb.hpp" | ||
#include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" | ||
#include "barretenberg/transcript/transcript.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/mega_zk_recursive_flavor.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved flavors from the header |
||
#include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp" | ||
#include <utility> | ||
|
||
namespace bb::stdlib::recursion::honk { | ||
|
@@ -130,6 +132,8 @@ template class OinkRecursiveVerifier_<bb::UltraRecursiveFlavor_<UltraCircuitBuil | |
template class OinkRecursiveVerifier_<bb::UltraRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class OinkRecursiveVerifier_<bb::MegaRecursiveFlavor_<UltraCircuitBuilder>>; | ||
template class OinkRecursiveVerifier_<bb::MegaRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class OinkRecursiveVerifier_<bb::MegaZKRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class OinkRecursiveVerifier_<bb::MegaZKRecursiveFlavor_<UltraCircuitBuilder>>; | ||
template class OinkRecursiveVerifier_<bb::UltraRecursiveFlavor_<CircuitSimulatorBN254>>; | ||
template class OinkRecursiveVerifier_<bb::MegaRecursiveFlavor_<CircuitSimulatorBN254>>; | ||
} // namespace bb::stdlib::recursion::honk |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,19 +87,42 @@ UltraRecursiveVerifier_<Flavor>::AggregationObject UltraRecursiveVerifier_<Flavo | |
// multivariate evaluations at u | ||
const size_t log_circuit_size = numeric::get_msb(static_cast<uint32_t>(key->circuit_size)); | ||
auto sumcheck = Sumcheck(log_circuit_size, transcript); | ||
|
||
auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = | ||
sumcheck.verify(verification_key->relation_parameters, verification_key->alphas, gate_challenges); | ||
|
||
// Execute Shplemini to produce a batch opening claim subsequently verified by a univariate PCS | ||
auto opening_claim = Shplemini::compute_batch_opening_claim(key->circuit_size, | ||
commitments.get_unshifted(), | ||
commitments.get_to_be_shifted(), | ||
claimed_evaluations.get_unshifted(), | ||
claimed_evaluations.get_shifted(), | ||
multivariate_challenge, | ||
Commitment::one(builder), | ||
transcript); | ||
// Receive commitments to Libra masking polynomials | ||
std::vector<Commitment> libra_commitments; | ||
if constexpr (Flavor::HasZK) { | ||
for (size_t idx = 0; idx < log_circuit_size; idx++) { | ||
Commitment libra_commitment = | ||
transcript->template receive_from_prover<Commitment>("Libra:commitment_" + std::to_string(idx)); | ||
libra_commitments.push_back(libra_commitment); | ||
}; | ||
} | ||
SumcheckOutput<Flavor> sumcheck_output; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: SumcheckOutput sumcheck_output = sumcheck.verify(... |
||
sumcheck_output = sumcheck.verify(verification_key->relation_parameters, verification_key->alphas, gate_challenges); | ||
BatchOpeningClaim<Curve> opening_claim; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if constexpr (!Flavor::HasZK) { | ||
// Execute Shplemini to produce a batch opening claim subsequently verified by a univariate PCS | ||
opening_claim = Shplemini::compute_batch_opening_claim(key->circuit_size, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This if - else can be avoided if translator concatenation polynomials remain the last arguments in the function signature and the libra.commitments and evaluations are always passed to shplemini. The for loop in Shplemini would simply create no claims if the two data structures are empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great suggestion, thanks! |
||
commitments.get_unshifted(), | ||
commitments.get_to_be_shifted(), | ||
sumcheck_output.claimed_evaluations.get_unshifted(), | ||
sumcheck_output.claimed_evaluations.get_shifted(), | ||
sumcheck_output.challenge, | ||
Commitment::one(builder), | ||
transcript); | ||
} else { | ||
opening_claim = Shplemini::compute_batch_opening_claim(key->circuit_size, | ||
commitments.get_unshifted(), | ||
commitments.get_to_be_shifted(), | ||
sumcheck_output.claimed_evaluations.get_unshifted(), | ||
sumcheck_output.claimed_evaluations.get_shifted(), | ||
sumcheck_output.challenge, | ||
Commitment::one(builder), | ||
transcript, | ||
{}, | ||
{}, | ||
RefVector(libra_commitments), | ||
sumcheck_output.claimed_libra_evaluations); | ||
} | ||
auto pairing_points = PCS::reduce_verify_batch_opening_claim(opening_claim, transcript); | ||
|
||
pairing_points[0] = pairing_points[0].normalize(); | ||
|
@@ -113,6 +136,8 @@ template class UltraRecursiveVerifier_<bb::UltraRecursiveFlavor_<UltraCircuitBui | |
template class UltraRecursiveVerifier_<bb::UltraRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class UltraRecursiveVerifier_<bb::MegaRecursiveFlavor_<UltraCircuitBuilder>>; | ||
template class UltraRecursiveVerifier_<bb::MegaRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class UltraRecursiveVerifier_<bb::MegaZKRecursiveFlavor_<MegaCircuitBuilder>>; | ||
template class UltraRecursiveVerifier_<bb::MegaZKRecursiveFlavor_<UltraCircuitBuilder>>; | ||
template class UltraRecursiveVerifier_<bb::UltraRecursiveFlavor_<CircuitSimulatorBN254>>; | ||
template class UltraRecursiveVerifier_<bb::MegaRecursiveFlavor_<CircuitSimulatorBN254>>; | ||
} // namespace bb::stdlib::recursion::honk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
#include "barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp" | ||
#include "barretenberg/circuit_checker/circuit_checker.hpp" | ||
#include "barretenberg/common/test.hpp" | ||
#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" | ||
#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" | ||
#include "barretenberg/stdlib/primitives/curves/bn254.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed redundant inclusions |
||
#include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp" | ||
#include "barretenberg/ultra_honk/ultra_prover.hpp" | ||
#include "barretenberg/ultra_honk/ultra_verifier.hpp" | ||
|
||
|
@@ -295,7 +292,9 @@ using Flavors = testing::Types<MegaRecursiveFlavor_<MegaCircuitBuilder>, | |
UltraRecursiveFlavor_<UltraCircuitBuilder>, | ||
UltraRecursiveFlavor_<MegaCircuitBuilder>, | ||
UltraRecursiveFlavor_<CircuitSimulatorBN254>, | ||
MegaRecursiveFlavor_<CircuitSimulatorBN254>>; | ||
MegaRecursiveFlavor_<CircuitSimulatorBN254>, | ||
MegaZKRecursiveFlavor_<MegaCircuitBuilder>, | ||
MegaZKRecursiveFlavor_<UltraCircuitBuilder>>; | ||
|
||
TYPED_TEST_SUITE(RecursiveVerifierTest, Flavors); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ class MegaFlavor { | |
|
||
// For instances of this flavour, used in folding, we need a unique sumcheck batching challenges for each | ||
// subrelation. This | ||
// is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the combiner) to much. | ||
// is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the combiner) too much. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>(); | ||
using RelationSeparator = std::array<FF, NUM_SUBRELATIONS - 1>; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that instead of duplicating the mega honk benchmark file you could just template the MegaHonk benchmark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried honestly, but it's not as nice as with the typed test suites, so prob we could keep two separate bench files for now (and maybe delete the one without zk, when we are done with zk)