Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gate_data.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Luke], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9#include <cstdint>
10
11namespace bb {
12
13// 3-wire addition gate: a*a_scaling + b*b_scaling + c*c_scaling + const_scaling = 0
14template <typename FF> struct add_triple_ {
15 uint32_t a;
16 uint32_t b;
17 uint32_t c;
22};
23
24// 4-wire addition gate: a*a_scaling + b*b_scaling + c*c_scaling + d*d_scaling + const_scaling = 0
25template <typename FF> struct add_quad_ {
26 uint32_t a;
27 uint32_t b;
28 uint32_t c;
29 uint32_t d;
35};
36
37// 4-wire mul-add gate: a*b*mul_scaling + a*a_scaling + b*b_scaling + c*c_scaling + d*d_scaling + const_scaling = 0
38template <typename FF> struct mul_quad_ {
39 uint32_t a;
40 uint32_t b;
41 uint32_t c;
42 uint32_t d;
49};
50
51// Arithmetic gate with standard selector naming: q_m*a*b + q_l*a + q_r*b + q_o*c + q_c = 0
52template <typename FF> struct arithmetic_triple_ {
53 uint32_t a;
54 uint32_t b;
55 uint32_t c;
61
62 friend bool operator==(arithmetic_triple_<FF> const& lhs, arithmetic_triple_<FF> const& rhs) = default;
63};
64
66
67// Goblin ECCVM operation: stores op type, point coordinates (split into limbs), and scalar
69 uint32_t op;
70 uint32_t x_lo;
71 uint32_t x_hi;
72 uint32_t y_lo;
73 uint32_t y_hi;
74 uint32_t z_1;
75 uint32_t z_2;
77};
78
79// Embedded curve point addition/subtraction: (x1, y1) ± (x2, y2) = (x3, y3)
81 uint32_t x1;
82 uint32_t y1;
83 uint32_t x2;
84 uint32_t y2;
85 uint32_t x3;
86 uint32_t y3;
87 bool is_addition; // else, subtraction
88};
89
90// Embedded curve point doubling: 2 * (x1, y1) = (x3, y3)
91template <typename FF> struct ecc_dbl_gate_ {
92 uint32_t x1;
93 uint32_t y1;
94 uint32_t x3;
95 uint32_t y3;
96};
97
98// Databus lookup gate: reads value at index from calldata/returndata
99template <typename FF> struct databus_lookup_gate_ {
100 uint32_t index;
101 uint32_t value;
102};
103
104// External gate data for poseidon2 external round
105template <typename FF> struct poseidon2_external_gate_ {
106 uint32_t a;
107 uint32_t b;
108 uint32_t c;
109 uint32_t d;
110 size_t round_idx;
111};
112
113// Initial linear layer gate for Poseidon2. Wires hold the raw permutation input; the next row
114// holds M_E * input and is consumed by the first external-round gate.
115template <typename FF> struct poseidon2_initial_external_gate_ {
116 uint32_t a;
117 uint32_t b;
118 uint32_t c;
119 uint32_t d;
120};
121
122// Internal gate data for poseidon2 internal round
123template <typename FF> struct poseidon2_internal_gate_ {
124 uint32_t a;
125 uint32_t b;
126 uint32_t c;
127 uint32_t d;
128 size_t round_idx;
129};
130
131// K=4 compressed internal-round gate: processes FOUR consecutive internal rounds per row.
132// Wires: a = state[0] at round 4i+0, b = state[0] at round 4i+1,
133// c = state[0] at round 4i+2, d = state[0] at round 4i+3.
134// (s_1, s_2, s_3) at row start are reconstructed inside the relation via a 3x3 Vandermonde solve.
135//
136// Round constants on the row (see Poseidon2QuadInternalRelationImpl):
137// q_l, q_r, q_o, q_4 = c_{4i}, c_{4i+1}, c_{4i+2}, c_{4i+3} // this quad's 4 S-box constants
138// q_m, q_c, q_5 = c_{4(i+1)}, c_{4(i+1)+1}, c_{4(i+1)+2} // next quad's first 3 constants
139// // (unused on terminal row)
140template <typename FF> struct poseidon2_quad_internal_gate_ {
141 uint32_t a; // state[0] at round 4i+0
142 uint32_t b; // state[0] at round 4i+1
143 uint32_t c; // state[0] at round 4i+2
144 uint32_t d; // state[0] at round 4i+3
145 size_t round_idx_start; // absolute round_constants index of round 4i (this quad's 1st round)
146 size_t next_pair_start; // absolute round_constants index of round 4(i+1) (next quad's 1st round);
147 // ignored when is_terminal = true
148 bool is_terminal; // true on the last compressed row (successor is standard-encoded)
149};
150
151// Entry transition gate: standard-encoded state (s_0, s_1, s_2, s_3) at round `round_idx_start`
152// whose successor is the first K=4 compressed row. The relation forces the successor's
153// w_r_shift, w_o_shift, w_4_shift to state[0] at rounds start+1, start+2, start+3 respectively.
154//
155// Round constants on the row:
156// q_l, q_r, q_o = c_{start}, c_{start+1}, c_{start+2} (first 3 internal round constants)
157// q_4, q_m, q_c, q_5 = 0 (unused)
158template <typename FF> struct poseidon2_transition_entry_gate_ {
159 uint32_t a; // s_0
160 uint32_t b; // s_1
161 uint32_t c; // s_2
162 uint32_t d; // s_3
163 size_t round_idx_start; // absolute round_constants index of the first internal round
164};
165} // namespace bb
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
friend bool operator==(arithmetic_triple_< FF > const &lhs, arithmetic_triple_< FF > const &rhs)=default
uint32_t d
uint32_t a
uint32_t c
uint32_t b
size_t round_idx_start