5
5
6
6
namespace nil {
7
7
namespace blueprint {
8
+ std::string lookup_library_call = R"(
9
+ {
10
+ uint256 lookup_offset = table_offset + quotient_offset + uint256(uint8(blob[z_offset + basic_marshalling.get_length(blob, z_offset - 0x8) *0x20 + 0xf])) * 0x20;
11
+ uint256[4] memory lookup_argument;
12
+ (lookup_argument, tr_state.current_challenge) = modular_lookup_argument_$TEST_NAME$.verify(
13
+ blob[special_selectors_offset: table_offset + quotient_offset],
14
+ blob[lookup_offset:lookup_offset + sorted_columns * 0x20],
15
+ basic_marshalling.get_uint256_be(blob, 0x81),
16
+ state.l0,
17
+ tr_state.current_challenge
18
+ );
19
+ state.F[3] = lookup_argument[0];
20
+ state.F[4] = lookup_argument[1];
21
+ state.F[5] = lookup_argument[2];
22
+ state.F[6] = lookup_argument[3];
23
+ }
24
+ )" ;
25
+
8
26
std::string modular_verifier_template = R"(
9
27
// SPDX-License-Identifier: Apache-2.0.
10
28
//---------------------------------------------------------------------------//
@@ -58,8 +76,8 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
58
76
59
77
function initialize(
60
78
// address permutation_argument_address,
61
- // address lookup_argument_address,
62
- // address gate_argument_address,
79
+ address lookup_argument_address,
80
+ address gate_argument_address,
63
81
address commitment_contract_address
64
82
) public{
65
83
console.log("Initialize");
@@ -68,30 +86,37 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
68
86
transcript.update_transcript_b32(tr_state, vk1);
69
87
transcript.update_transcript_b32(tr_state, vk2);
70
88
71
- // _gate_argument_address = gate_argument_address;
72
89
// _permutation_argument_address = permutation_argument_address;
73
- // _lookup_argument_address = lookup_argument_address;
90
+ _lookup_argument_address = lookup_argument_address;
91
+ _gate_argument_address = gate_argument_address;
74
92
_commitment_contract_address = commitment_contract_address;
75
93
76
94
ICommitmentScheme commitment_scheme = ICommitmentScheme(commitment_contract_address);
77
95
tr_state.current_challenge = commitment_scheme.initialize(tr_state.current_challenge);
78
96
transcript_state = tr_state.current_challenge;
79
97
}
80
98
99
+ struct verifier_state{
100
+ uint256 xi;
101
+ uint256 Z_at_xi;
102
+ uint256 l0;
103
+ uint256[f_parts] F;
104
+ }
105
+
81
106
function verify(
82
107
bytes calldata blob
83
108
) public view{
109
+ verifier_state memory state;
84
110
uint256 gas = gasleft();
85
111
uint256 xi = basic_marshalling.get_uint256_be(blob, $EVAL_PROOF_OFFSET$);
86
- uint256 Z_at_xi = addmod(field.pow_small(xi, rows_amount, modulus), modulus-1, modulus);
87
- uint256 l0 = mulmod(
88
- Z_at_xi,
112
+ state. Z_at_xi = addmod(field.pow_small(xi, rows_amount, modulus), modulus-1, modulus);
113
+ state. l0 = mulmod(
114
+ state. Z_at_xi,
89
115
field.inverse_static(mulmod(addmod(xi, modulus - 1, modulus), rows_amount, modulus), modulus),
90
116
modulus
91
117
);
92
- uint256[f_parts] memory F;
93
118
94
- console.log("l0 = ", l0);
119
+ console.log("l0 = ", state. l0);
95
120
96
121
//0. Check proof size
97
122
// No direct public input
@@ -110,11 +135,11 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
110
135
blob[$Z_OFFSET$:$TABLE_Z_OFFSET$+$QUOTIENT_OFFSET$],
111
136
transcript.get_field_challenge(tr_state, modulus),
112
137
transcript.get_field_challenge(tr_state, modulus),
113
- l0
138
+ state. l0
114
139
);
115
- F[0] = permutation_argument[0];
116
- F[1] = permutation_argument[1];
117
- F[2] = permutation_argument[2];
140
+ state. F[0] = permutation_argument[0];
141
+ state. F[1] = permutation_argument[1];
142
+ state. F[2] = permutation_argument[2];
118
143
}
119
144
120
145
$LOOKUP_LIBRARY_CALL$
@@ -124,7 +149,8 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
124
149
125
150
{
126
151
//6. Gate argument
127
- F[7] = modular_gate_argument_$TEST_NAME$.verify(blob[table_offset:table_end_offset], transcript.get_field_challenge(tr_state, modulus));
152
+ IGateArgument modular_gate_argument = IGateArgument(_gate_argument_address);
153
+ state.F[7] = modular_gate_argument.verify(blob[table_offset:table_end_offset], transcript.get_field_challenge(tr_state, modulus));
128
154
}
129
155
130
156
// No public input gate
@@ -133,7 +159,7 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
133
159
{
134
160
//7. Push quotient to transcript
135
161
for( uint8 i = 0; i < f_parts;){
136
- F_consolidated = addmod(F_consolidated, mulmod(F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
162
+ F_consolidated = addmod(F_consolidated, mulmod(state. F[i],transcript.get_field_challenge(tr_state, modulus), modulus), modulus);
137
163
unchecked{i++;}
138
164
}
139
165
uint256 points_num = basic_marshalling.get_length(blob, $EVAL_PROOF_OFFSET$ + 0x20);
@@ -168,21 +194,21 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
168
194
mulmod(basic_marshalling.get_uint256_be(blob, table_offset + quotient_offset + i *0x20), factor, modulus),
169
195
modulus
170
196
);
171
- factor = mulmod(factor, Z_at_xi + 1, modulus);
197
+ factor = mulmod(factor, state. Z_at_xi + 1, modulus);
172
198
unchecked{i++;}
173
199
}
174
200
console.log("T_consolidated = ", T_consolidated);
175
- if( F_consolidated == mulmod(T_consolidated, Z_at_xi, modulus) ) console.log("SUCCESS!");
201
+ if( F_consolidated == mulmod(T_consolidated, state. Z_at_xi, modulus) ) console.log("SUCCESS!");
176
202
}
177
203
178
- console.log("F[0] = ", F[0]);
179
- console.log("F[1] = ", F[1]);
180
- console.log("F[2] = ", F[2]);
181
- console.log("F[3] = ", F[3]);
182
- console.log("F[4] = ", F[4]);
183
- console.log("F[5] = ", F[5]);
184
- console.log("F[6] = ", F[6]);
185
- console.log("F[7] = ", F[7]);
204
+ console.log("F[0] = ", state. F[0]);
205
+ console.log("F[1] = ", state. F[1]);
206
+ console.log("F[2] = ", state. F[2]);
207
+ console.log("F[3] = ", state. F[3]);
208
+ console.log("F[4] = ", state. F[4]);
209
+ console.log("F[5] = ", state. F[5]);
210
+ console.log("F[6] = ", state. F[6]);
211
+ console.log("F[7] = ", state. F[7]);
186
212
console.log("F_consolidated = ", F_consolidated);
187
213
console.log("Gas for verification:", gas-gasleft());
188
214
}
0 commit comments