Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
oink_verifier.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
17
18namespace bb {
19
23template <typename Flavor> void OinkVerifier<Flavor>::verify()
24{
25 receive_vk_hash_and_public_inputs();
26 if constexpr (Flavor::HasZK) {
27 verifier_instance->gemini_masking_commitment =
28 transcript->template receive_from_prover<Commitment>("Gemini:masking_poly_comm");
29 }
30 receive_wire_commitments();
31 receive_lookup_counts_and_w4_commitments();
32 receive_logderiv_commitments();
33 complete_grand_product_round();
34
35 verifier_instance->alpha = transcript->template get_challenge<FF>("alpha");
36}
37
42{
43 auto vk = verifier_instance->get_vk();
44
45 FF vk_hash = vk->hash_with_origin_tagging(*transcript);
46 transcript->add_to_hash_buffer("vk_hash", vk_hash);
47 vinfo("vk hash in Oink verifier: ", vk_hash);
48
49 // For recursive flavors, assert that the VK hash matches the expected hash provided in the VK
50 if constexpr (IsRecursiveFlavor<Flavor>) {
51 const bool is_write_vk_mode = vk_hash.get_context()->is_write_vk_mode();
52 const bool vk_hash_consistency = verifier_instance->vk_and_hash->hash.get_value() == vk_hash.get_value();
53 if (!vk_hash_consistency && !is_write_vk_mode) {
54 info("Recursive Ultra Verifier: VK Hash Mismatch");
55 }
56 verifier_instance->vk_and_hash->hash.assert_equal(vk_hash);
57
58 // Assert that the provided num_public_inputs matches VK's value (in-circuit constraint)
59 vk->num_public_inputs.assert_equal(FF(num_public_inputs), "OinkVerifier: num_public_inputs mismatch with VK");
60 } else {
61 BB_ASSERT_EQ(verifier_instance->vk_and_hash->hash, vk_hash, "Native Ultra Verifier: VK Hash Mismatch");
62 // Assert that the provided num_public_inputs matches VK's value
63 BB_ASSERT_EQ(num_public_inputs,
64 static_cast<size_t>(vk->num_public_inputs),
65 "OinkVerifier: num_public_inputs mismatch with VK");
66 };
67
68 std::vector<FF> public_inputs;
69 for (size_t i = 0; i < num_public_inputs; ++i) {
70 auto public_input_i = transcript->template receive_from_prover<FF>("public_input_" + std::to_string(i));
71 public_inputs.emplace_back(public_input_i);
72 }
73 verifier_instance->public_inputs = std::move(public_inputs);
74}
75
80template <typename Flavor> void OinkVerifier<Flavor>::receive_wire_commitments()
81{
82 // Get commitments to first three wire polynomials
83 verifier_instance->witness_commitments.w_l = transcript->template receive_from_prover<Commitment>(comm_labels.w_l);
84 verifier_instance->witness_commitments.w_r = transcript->template receive_from_prover<Commitment>(comm_labels.w_r);
85 verifier_instance->witness_commitments.w_o = transcript->template receive_from_prover<Commitment>(comm_labels.w_o);
86
87 if constexpr (IsMegaFlavor<Flavor>) {
88 // Receive ECC op wire commitments
89 for (auto [commitment, label] :
90 zip_view(verifier_instance->witness_commitments.get_ecc_op_wires(), comm_labels.get_ecc_op_wires())) {
91 commitment = transcript->template receive_from_prover<Commitment>(label);
92 }
93
94 // Receive DataBus related polynomial commitments
95 for (auto [commitment, label] : zip_view(verifier_instance->witness_commitments.get_databus_entities(),
96 comm_labels.get_databus_entities())) {
97 commitment = transcript->template receive_from_prover<Commitment>(label);
98 }
99 }
100}
101
107{
108 // Get eta challenge and compute powers (eta, eta², eta³)
109 verifier_instance->relation_parameters.compute_eta_powers(transcript->template get_challenge<FF>("eta"));
110
111 // Get commitments to lookup argument polynomials and fourth wire
112 verifier_instance->witness_commitments.lookup_read_counts =
113 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_read_counts);
114 verifier_instance->witness_commitments.lookup_read_tags =
115 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_read_tags);
116 verifier_instance->witness_commitments.w_4 = transcript->template receive_from_prover<Commitment>(comm_labels.w_4);
117}
118
123{
124 auto [beta, gamma] = transcript->template get_challenges<FF>(std::array<std::string, 2>{ "beta", "gamma" });
125 verifier_instance->relation_parameters.compute_beta_powers(beta);
126 verifier_instance->relation_parameters.gamma = gamma;
127
128 verifier_instance->witness_commitments.lookup_inverses =
129 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_inverses);
130
131 if constexpr (IsMegaFlavor<Flavor>) {
132 for (auto [commitment, label] : zip_view(verifier_instance->witness_commitments.get_databus_inverses(),
133 comm_labels.get_databus_inverses())) {
134 commitment = transcript->template receive_from_prover<Commitment>(label);
135 }
136 }
137}
138
143{
144 auto vk = verifier_instance->get_vk();
145
146 verifier_instance->relation_parameters.public_input_delta =
147 compute_public_input_delta<Flavor>(verifier_instance->public_inputs,
148 verifier_instance->relation_parameters.beta,
149 verifier_instance->relation_parameters.gamma,
150 vk->pub_inputs_offset);
151
152 verifier_instance->witness_commitments.z_perm =
153 transcript->template receive_from_prover<Commitment>(comm_labels.z_perm);
154}
155
156// Native flavor instantiations
157template class OinkVerifier<UltraFlavor>;
158template class OinkVerifier<UltraZKFlavor>;
160#ifdef STARKNET_GARAGA_FLAVORS
163#endif
165template class OinkVerifier<MegaFlavor>;
166template class OinkVerifier<MegaZKFlavor>;
167
168// Recursive flavor instantiations
178
179} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
static constexpr bool HasZK
Verifier counterpart to OinkProver: receives witness commitments, computes relation parameters,...
void receive_wire_commitments()
Receive wire commitments (w_l, w_r, w_o). For Mega, also receive ECC op wire and DataBus commitments....
void receive_logderiv_commitments()
Receive beta/gamma challenges and log-derivative inverse commitments (plus databus inverses for Mega)...
typename Flavor::FF FF
void verify()
Receive witness commitments, compute relation parameters, and prepare for Sumcheck.
void receive_vk_hash_and_public_inputs()
Hash the verification key, assert consistency, and receive public inputs from the transcript.
void receive_lookup_counts_and_w4_commitments()
Get sorted witness-table accumulator and fourth wire commitments.
void complete_grand_product_round()
Compute public_input_delta for the permutation argument and receive z_perm commitment.
#define info(...)
Definition log.hpp:93
#define vinfo(...)
Definition log.hpp:94
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)