Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hypernova_prover.test.cpp
Go to the documentation of this file.
3#include "gtest/gtest.h"
4
5using namespace bb;
6
7// TODO(https://github.com/AztecProtocol/barretenberg/issues/1553): improve testing
8class HypernovaFoldingProverTests : public ::testing::Test {
9 protected:
11
12 public:
17
18 enum class TamperingMode : uint8_t { None, Accumulator };
19
20 static std::shared_ptr<ProverInstance> generate_new_instance(size_t log_num_gates = 4)
21 {
23
27
29
30 return instance;
31 }
32
34 {
35 auto ck = CommitmentKey(accumulator.dyadic_size);
36
37 auto unshifted_polynomial = Polynomial(accumulator.non_shifted_polynomial);
38 auto shifted_polynomial = Polynomial(accumulator.shifted_polynomial);
39 unshifted_polynomial.increase_virtual_size(1 << static_cast<uint>(accumulator.challenge.size()));
40 shifted_polynomial.increase_virtual_size(1 << static_cast<uint>(accumulator.challenge.size()));
41 if (unshifted_polynomial.evaluate_mle(accumulator.challenge) != accumulator.non_shifted_evaluation) {
42 info("Mismatch between batched unshifted evaluation and evaluation of the batched unshifted polynomial.");
43 return false;
44 }
45 if (shifted_polynomial.evaluate_mle(accumulator.challenge, true) != accumulator.shifted_evaluation) {
46 info("Mismatch between batched shifted evaluation and evaluation of the batched shifted polynomial.");
47 return false;
48 }
49 if (ck.commit(accumulator.non_shifted_polynomial) != accumulator.non_shifted_commitment) {
50 info("Mismatch between the commitment to the batched unshifted polynomial and the batched unshifted "
51 "commitment.");
52 return false;
53 }
54 if (ck.commit(accumulator.shifted_polynomial) != accumulator.shifted_commitment) {
55 info("Mismatch between the commitment to the batched shifted polynomial and the batched shifted "
56 "commitment.");
57 return false;
58 }
59
60 return true;
61 }
62
63 static void tampering(HypernovaFoldingProver::Accumulator& accumulator, const TamperingMode& mode)
64 {
65 switch (mode) {
67 break;
69 // Tamper with the accumulator by changing the unshifted polynomial
70 // Note that changing the challenge would not produce an invalid accumulator as the validity of the
71 // evaluations for an accumulator is checked by the Sumcheck performed to turn an instance into an
72 // accumulators
74 break;
75 }
76 };
77
79 {
80 // Generate accumulator
81 auto instance = generate_new_instance();
82 auto transcript = std::make_shared<Transcript>();
83
84 HypernovaFoldingProver prover(transcript);
85 auto accumulator = prover.instance_to_accumulator(instance);
86 tampering(accumulator, mode);
87
88 // Folding
89 auto incoming_instance = generate_new_instance(5);
90
91 auto folding_transcript = std::make_shared<Transcript>();
92 HypernovaFoldingProver folding_prover(folding_transcript);
93 auto [_, folded_accumulator] = folding_prover.fold(accumulator, incoming_instance);
94
95 return folded_accumulator;
96 }
97};
98
99TEST_F(HypernovaFoldingProverTests, InstanceToAccumulator)
100{
101 auto instance = generate_new_instance();
102 auto transcript = std::make_shared<Transcript>();
103
104 HypernovaFoldingProver prover(transcript);
105 auto accumulator = prover.instance_to_accumulator(instance);
106
107 EXPECT_TRUE(validate_accumulator(accumulator));
108}
109
111{
112 auto folded_accumulator = test_folding(TamperingMode::None);
113 EXPECT_TRUE(validate_accumulator(folded_accumulator));
114}
115
117{
118 auto folded_accumulator = test_folding(TamperingMode::Accumulator);
119 EXPECT_FALSE(validate_accumulator(folded_accumulator));
120}
static bool validate_accumulator(HypernovaFoldingProver::Accumulator &accumulator)
static std::shared_ptr< ProverInstance > generate_new_instance(size_t log_num_gates=4)
static void tampering(HypernovaFoldingProver::Accumulator &accumulator, const TamperingMode &mode)
HypernovaFoldingProver::Flavor::CommitmentKey CommitmentKey
static HypernovaFoldingProver::Accumulator test_folding(const TamperingMode &mode)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
std::pair< HonkProof, Accumulator > fold(const Accumulator &accumulator, const std::shared_ptr< ProverInstance > &instance)
Fold an instance into an accumulator. Folding happens in place.
ProverInstance_< Flavor > ProverInstance
Accumulator instance_to_accumulator(const std::shared_ptr< ProverInstance > &instance)
Turn an instance into an accumulator by running Sumcheck.
bb::CommitmentKey< Curve > CommitmentKey
MegaCircuitBuilder CircuitBuilder
static void add_arithmetic_gates_with_public_inputs(Builder &builder, const size_t num_gates=4)
Add a specified number of arithmetic gates (with public inputs) to the provided circuit.
static void add_lookup_gates(Builder &builder, size_t num_iterations=1)
Add lookup gates using the uint32 XOR lookup table (table size 4096)
static void add_arithmetic_gates(Builder &builder, const size_t num_gates=4)
Add a specified number of arithmetic gates to the provided circuit.
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
void info(Args... args)
Definition log.hpp:74
AluTraceBuilder builder
Definition alu.test.cpp:123
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
Definition ipa.test.cpp:188
CommitmentKey< Curve > ck
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept