barretenberg
Loading...
Searching...
No Matches
verify.hpp
1#pragma once
2#include "./mock/mock_circuit.hpp"
3#include "barretenberg/ecc/curves/bn254/fq12.hpp"
4#include "barretenberg/ecc/curves/bn254/pairing.hpp"
5#include "barretenberg/stdlib/recursion/aggregation_state/aggregation_state.hpp"
6#include "barretenberg/stdlib/recursion/verifier/verifier.hpp"
7
8namespace join_split_example {
9namespace proofs {
10
11template <typename Composer> struct verify_result {
13 : logic_verified(false)
14 , verified(false)
15 {}
16
17 bool logic_verified;
18 std::string err;
19 std::vector<fr> public_inputs;
21
22 std::vector<uint8_t> proof_data;
23 bool verified;
24 std::shared_ptr<plonk::verification_key> verification_key;
25 size_t number_of_gates;
26};
27
28template <typename Composer>
29inline bool pairing_check(plonk::stdlib::recursion::aggregation_state<plonk::stdlib::bn254<Composer>> aggregation_state,
30 std::shared_ptr<barretenberg::srs::factories::VerifierCrs> const& srs)
31{
33 P[0].x = barretenberg::fq(aggregation_state.P0.x.get_value().lo);
34 P[0].y = barretenberg::fq(aggregation_state.P0.y.get_value().lo);
35 P[1].x = barretenberg::fq(aggregation_state.P1.x.get_value().lo);
36 P[1].y = barretenberg::fq(aggregation_state.P1.y.get_value().lo);
37 barretenberg::fq12 inner_proof_result =
38 barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P, srs->get_precomputed_g2_lines(), 2);
39 return inner_proof_result == barretenberg::fq12::one();
40}
41
42template <typename Builder, typename Tx, typename CircuitData, typename F>
43auto verify_logic_internal(Builder& builder, Tx& tx, CircuitData const& cd, char const* name, F const& build_circuit)
44{
45 info(name, ": Building circuit...");
46 Timer timer;
47 auto result = build_circuit(builder, tx, cd);
48 info(name, ": Circuit built in ", timer.toString(), "s");
49
50 if (builder.failed()) {
51 info(name, ": Circuit logic failed: " + builder.err());
52 result.err = builder.err();
53 return result;
54 }
55
56 if (!cd.srs) {
57 info(name, ": Srs not provided.");
58 return result;
59 }
60
61 if (!pairing_check(result.aggregation_state, cd.srs->get_verifier_crs())) {
62 info(name, ": Native pairing check failed.");
63 return result;
64 }
65
66 result.public_inputs = builder.get_public_inputs();
67 result.logic_verified = true;
68 result.number_of_gates = builder.get_num_gates();
69
70 return result;
71}
72
73} // namespace proofs
74} // namespace join_split_example
Get the execution between a block of code.
Definition: timer.hpp:12
std::string toString() const
Return the number of seconds elapsed since the start of the timer as a string.
Definition: timer.hpp:80
Definition: field12.hpp:5
Definition: affine_element.hpp:11
Definition: ultra_circuit_builder.hpp:31
size_t get_num_gates() const override
Get the final number of gates in a circuit, which consists of the sum of: 1) Current number number of...
Definition: ultra_circuit_builder.hpp:888
Definition: bn254.hpp:10