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(bool emit_alpha)
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 if (emit_alpha) {
36 verifier_instance->alpha = transcript->template get_challenge<FF>("alpha");
37 }
38}
39
44{
45 auto vk = verifier_instance->get_vk();
46
47 FF vk_hash = vk->hash_with_origin_tagging(*transcript);
48 transcript->add_to_hash_buffer("vk_hash", vk_hash);
49 vinfo("vk hash in Oink verifier: ", vk_hash);
50
51 // For recursive flavors, assert that the VK hash matches the expected hash provided in the VK
52 if constexpr (IsRecursiveFlavor<Flavor>) {
53 const bool is_write_vk_mode = vk_hash.get_context()->is_write_vk_mode();
54 const bool vk_hash_consistency = verifier_instance->vk_and_hash->hash.get_value() == vk_hash.get_value();
55 if (!vk_hash_consistency && !is_write_vk_mode) {
56 info("Recursive Ultra Verifier: VK Hash Mismatch");
57 }
58 verifier_instance->vk_and_hash->hash.assert_equal(vk_hash);
59
60 // Assert that the provided num_public_inputs matches VK's value (in-circuit constraint)
61 vk->num_public_inputs.assert_equal(FF(num_public_inputs), "OinkVerifier: num_public_inputs mismatch with VK");
62 } else {
63 BB_ASSERT_EQ(verifier_instance->vk_and_hash->hash, vk_hash, "Native Ultra Verifier: VK Hash Mismatch");
64 // Assert that the provided num_public_inputs matches VK's value
65 BB_ASSERT_EQ(num_public_inputs,
66 static_cast<size_t>(vk->num_public_inputs),
67 "OinkVerifier: num_public_inputs mismatch with VK");
68 };
69
70 std::vector<FF> public_inputs;
71 for (size_t i = 0; i < num_public_inputs; ++i) {
72 auto public_input_i = transcript->template receive_from_prover<FF>("public_input_" + std::to_string(i));
73 public_inputs.emplace_back(public_input_i);
74 }
75 verifier_instance->public_inputs = std::move(public_inputs);
76}
77
82template <typename Flavor> void OinkVerifier<Flavor>::receive_wire_commitments()
83{
84 // Get commitments to first three wire polynomials
85 verifier_instance->witness_commitments.w_l = transcript->template receive_from_prover<Commitment>(comm_labels.w_l);
86 verifier_instance->witness_commitments.w_r = transcript->template receive_from_prover<Commitment>(comm_labels.w_r);
87 verifier_instance->witness_commitments.w_o = transcript->template receive_from_prover<Commitment>(comm_labels.w_o);
88
89 if constexpr (IsMegaFlavor<Flavor>) {
90 // Receive ECC op wire commitments
91 for (auto [commitment, label] :
92 zip_view(verifier_instance->witness_commitments.get_ecc_op_wires(), comm_labels.get_ecc_op_wires())) {
93 commitment = transcript->template receive_from_prover<Commitment>(label);
94 }
95
96 // Receive DataBus related polynomial commitments
97 for (auto [commitment, label] : zip_view(verifier_instance->witness_commitments.get_databus_entities(),
98 comm_labels.get_databus_entities())) {
99 commitment = transcript->template receive_from_prover<Commitment>(label);
100 }
101 }
102}
103
109{
110 // Get eta challenge and compute powers (eta, eta², eta³)
111 verifier_instance->relation_parameters.compute_eta_powers(transcript->template get_challenge<FF>("eta"));
112
113 // Get commitments to lookup argument polynomials and fourth wire
114 verifier_instance->witness_commitments.lookup_read_counts =
115 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_read_counts);
116 verifier_instance->witness_commitments.lookup_read_tags =
117 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_read_tags);
118 verifier_instance->witness_commitments.w_4 = transcript->template receive_from_prover<Commitment>(comm_labels.w_4);
119}
120
125{
126 auto [beta, gamma] = transcript->template get_challenges<FF>(std::array<std::string, 2>{ "beta", "gamma" });
127 verifier_instance->relation_parameters.compute_beta_powers(beta);
128 verifier_instance->relation_parameters.gamma = gamma;
129
130 verifier_instance->witness_commitments.lookup_inverses =
131 transcript->template receive_from_prover<Commitment>(comm_labels.lookup_inverses);
132
133 if constexpr (IsMegaFlavor<Flavor>) {
134 for (auto [commitment, label] : zip_view(verifier_instance->witness_commitments.get_databus_inverses(),
135 comm_labels.get_databus_inverses())) {
136 commitment = transcript->template receive_from_prover<Commitment>(label);
137 }
138 }
139}
140
145{
146 auto vk = verifier_instance->get_vk();
147
148 verifier_instance->relation_parameters.public_input_delta =
149 compute_public_input_delta<Flavor>(verifier_instance->public_inputs,
150 verifier_instance->relation_parameters.beta,
151 verifier_instance->relation_parameters.gamma,
152 vk->pub_inputs_offset);
153
154 verifier_instance->witness_commitments.z_perm =
155 transcript->template receive_from_prover<Commitment>(comm_labels.z_perm);
156}
157
158// Native flavor instantiations
159template class OinkVerifier<UltraFlavor>;
160template class OinkVerifier<UltraZKFlavor>;
162#ifdef STARKNET_GARAGA_FLAVORS
165#endif
167template class OinkVerifier<MegaFlavor>;
168template class OinkVerifier<MegaZKFlavor>;
169
170// Recursive flavor instantiations
180
181} // 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 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.
void verify(bool emit_alpha=true)
Receive witness commitments, compute relation parameters, and prepare for Sumcheck.
#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)