@@ -27,7 +27,8 @@ use zkevm_circuits::{
27
27
28
28
use crate :: {
29
29
util:: { assert_equal, capacity, get_indices} ,
30
- CHAIN_ID_LEN , LOG_DEGREE ,
30
+ CHAIN_ID_LEN , CHUNK_DATA_HASH_INDEX , LOG_DEGREE , POST_STATE_ROOT_INDEX , PREV_STATE_ROOT_INDEX ,
31
+ WITHDRAW_ROOT_INDEX ,
31
32
} ;
32
33
33
34
/// Input the hash input bytes,
@@ -50,18 +51,18 @@ pub(crate) fn assign_batch_hashes<F: Field>(
50
51
let num_rows = 1 << LOG_DEGREE ;
51
52
52
53
let timer = start_timer ! ( || ( "multi keccak" ) . to_string( ) ) ;
53
- // wenqing: preimages consists of the following parts
54
+ // preimages consists of the following parts
54
55
// (1) batchPiHash preimage =
55
56
// (chain_id ||
56
57
// chunk[0].prev_state_root ||
57
58
// chunk[k-1].post_state_root ||
58
59
// chunk[k-1].withdraw_root ||
59
60
// batch_data_hash)
60
- // (2) batchDataHash preimage =
61
+ // (2) batchDataHash preimage =
61
62
// (chunk[0].dataHash || ... || chunk[k-1].dataHash)
62
63
// (3) chunk[i].piHash preimage =
63
64
// (chain id ||
64
- // chunk[i].prevStateRoot || chunk[i].postStateRoot ||
65
+ // chunk[i].prevStateRoot || chunk[i].postStateRoot ||
65
66
// chunk[i].withdrawRoot || chunk[i].datahash)
66
67
// each part of the preimage is mapped to image by Keccak256
67
68
let witness = multi_keccak ( preimages, challenges, capacity ( num_rows) ) ?;
@@ -98,12 +99,12 @@ pub(crate) fn assign_batch_hashes<F: Field>(
98
99
let row = config. set_row ( & mut region, offset, keccak_row) ?;
99
100
100
101
if cur_preimage_index. is_some ( ) && * cur_preimage_index. unwrap ( ) == offset {
101
- // wenqing: 7-th column is Keccak input in Keccak circuit
102
+ // 7-th column is Keccak input in Keccak circuit
102
103
current_hash_input_cells. push ( row[ 6 ] . clone ( ) ) ;
103
104
cur_preimage_index = preimage_indices_iter. next ( ) ;
104
105
}
105
106
if cur_digest_index. is_some ( ) && * cur_digest_index. unwrap ( ) == offset {
106
- // wenqing: last column is Keccak output in Keccak circuit
107
+ // last column is Keccak output in Keccak circuit
107
108
current_hash_output_cells. push ( row. last ( ) . unwrap ( ) . clone ( ) ) ;
108
109
cur_digest_index = digest_indices_iter. next ( ) ;
109
110
}
@@ -142,14 +143,14 @@ pub(crate) fn assign_batch_hashes<F: Field>(
142
143
for i in 0 ..4 {
143
144
for j in 0 ..8 {
144
145
// sanity check
145
- // wenqing: 96 + CHAIN_ID_LEN is the byte position for batch_data_hash
146
+ // CHUNK_DATA_HASH_INDEX is the byte position for batch_data_hash
146
147
assert_equal (
147
- & hash_input_cells[ 0 ] [ i * 8 + j + 96 + CHAIN_ID_LEN ] ,
148
+ & hash_input_cells[ 0 ] [ i * 8 + j + CHUNK_DATA_HASH_INDEX ] ,
148
149
& hash_output_cells[ 1 ] [ ( 3 - i) * 8 + j] ,
149
150
) ;
150
151
region. constrain_equal (
151
152
// preimage and digest has different endianness
152
- hash_input_cells[ 0 ] [ i * 8 + j + 96 + CHAIN_ID_LEN ] . cell ( ) ,
153
+ hash_input_cells[ 0 ] [ i * 8 + j + CHUNK_DATA_HASH_INDEX ] . cell ( ) ,
153
154
hash_output_cells[ 1 ] [ ( 3 - i) * 8 + j] . cell ( ) ,
154
155
) ?;
155
156
}
@@ -172,39 +173,39 @@ pub(crate) fn assign_batch_hashes<F: Field>(
172
173
// chunk[i].postStateRoot ||
173
174
// chunk[i].withdrawRoot ||
174
175
// chunk[i].datahash)
175
- // wenqing: CHAIN_ID_LEN,
176
- // CHAIN_ID_LEN+32,
177
- // CHAIN_ID_LEN+64 used below are byte positions for
178
- // prev_state_root, post_state_root, withdraw_root
176
+ //
177
+ // PREV_STATE_ROOT_INDEX, POST_STATE_ROOT_INDEX, WITHDRAW_ROOT_INDEX
178
+ // used below are byte positions for
179
+ // prev_state_root, post_state_root, withdraw_root
179
180
for i in 0 ..32 {
180
181
// 2.2.1 chunk[0].prev_state_root
181
182
// sanity check
182
183
assert_equal (
183
- & hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN ] ,
184
- & hash_input_cells[ 2 ] [ i + CHAIN_ID_LEN ] ,
184
+ & hash_input_cells[ 0 ] [ i + PREV_STATE_ROOT_INDEX ] ,
185
+ & hash_input_cells[ 2 ] [ i + PREV_STATE_ROOT_INDEX ] ,
185
186
) ;
186
187
region. constrain_equal (
187
- hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN ] . cell ( ) ,
188
- hash_input_cells[ 2 ] [ i + CHAIN_ID_LEN ] . cell ( ) ,
188
+ hash_input_cells[ 0 ] [ i + PREV_STATE_ROOT_INDEX ] . cell ( ) ,
189
+ hash_input_cells[ 2 ] [ i + PREV_STATE_ROOT_INDEX ] . cell ( ) ,
189
190
) ?;
190
191
// 2.2.2 chunk[k-1].post_state_root
191
192
// sanity check
192
193
assert_equal (
193
- & hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN + 32 ] ,
194
- & hash_input_cells[ hash_num - 1 ] [ i + CHAIN_ID_LEN + 32 ] ,
194
+ & hash_input_cells[ 0 ] [ i + POST_STATE_ROOT_INDEX ] ,
195
+ & hash_input_cells[ hash_num - 1 ] [ i + POST_STATE_ROOT_INDEX ] ,
195
196
) ;
196
197
region. constrain_equal (
197
- hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN + 32 ] . cell ( ) ,
198
- hash_input_cells[ hash_num - 1 ] [ i + CHAIN_ID_LEN + 32 ] . cell ( ) ,
198
+ hash_input_cells[ 0 ] [ i + POST_STATE_ROOT_INDEX ] . cell ( ) ,
199
+ hash_input_cells[ hash_num - 1 ] [ i + POST_STATE_ROOT_INDEX ] . cell ( ) ,
199
200
) ?;
200
201
// 2.2.3 chunk[k-1].withdraw_root
201
202
assert_equal (
202
- & hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN + 64 ] ,
203
- & hash_input_cells[ hash_num - 1 ] [ i + CHAIN_ID_LEN + 64 ] ,
203
+ & hash_input_cells[ 0 ] [ i + WITHDRAW_ROOT_INDEX ] ,
204
+ & hash_input_cells[ hash_num - 1 ] [ i + WITHDRAW_ROOT_INDEX ] ,
204
205
) ;
205
206
region. constrain_equal (
206
- hash_input_cells[ 0 ] [ i + CHAIN_ID_LEN + 64 ] . cell ( ) ,
207
- hash_input_cells[ hash_num - 1 ] [ i + CHAIN_ID_LEN + 64 ] . cell ( ) ,
207
+ hash_input_cells[ 0 ] [ i + WITHDRAW_ROOT_INDEX ] . cell ( ) ,
208
+ hash_input_cells[ hash_num - 1 ] [ i + WITHDRAW_ROOT_INDEX ] . cell ( ) ,
208
209
) ?;
209
210
}
210
211
@@ -222,10 +223,10 @@ pub(crate) fn assign_batch_hashes<F: Field>(
222
223
for ( i, chunk) in hash_input_cells[ 1 ] . chunks ( 32 ) . enumerate ( ) . take ( num_chunks) {
223
224
for ( j, cell) in chunk. iter ( ) . enumerate ( ) {
224
225
// sanity check
225
- assert_equal ( cell, & hash_input_cells[ 2 + i] [ j + CHAIN_ID_LEN + 96 ] ) ;
226
+ assert_equal ( cell, & hash_input_cells[ 2 + i] [ j + CHUNK_DATA_HASH_INDEX ] ) ;
226
227
region. constrain_equal (
227
228
cell. cell ( ) ,
228
- hash_input_cells[ 2 + i] [ j + CHAIN_ID_LEN + 96 ] . cell ( ) ,
229
+ hash_input_cells[ 2 + i] [ j + CHUNK_DATA_HASH_INDEX ] . cell ( ) ,
229
230
) ?;
230
231
}
231
232
}
@@ -235,14 +236,14 @@ pub(crate) fn assign_batch_hashes<F: Field>(
235
236
for j in 0 ..32 {
236
237
// sanity check
237
238
assert_equal (
238
- & hash_input_cells[ i + 3 ] [ CHAIN_ID_LEN + j] ,
239
- & hash_input_cells[ i + 2 ] [ CHAIN_ID_LEN + 32 + j] ,
239
+ & hash_input_cells[ i + 3 ] [ PREV_STATE_ROOT_INDEX + j] ,
240
+ & hash_input_cells[ i + 2 ] [ POST_STATE_ROOT_INDEX + j] ,
240
241
) ;
241
242
region. constrain_equal (
242
243
// chunk[i+1].prevStateRoot
243
- hash_input_cells[ i + 3 ] [ CHAIN_ID_LEN + j] . cell ( ) ,
244
+ hash_input_cells[ i + 3 ] [ PREV_STATE_ROOT_INDEX + j] . cell ( ) ,
244
245
// chunk[i].postStateRoot
245
- hash_input_cells[ i + 2 ] [ CHAIN_ID_LEN + 32 + j] . cell ( ) ,
246
+ hash_input_cells[ i + 2 ] [ POST_STATE_ROOT_INDEX + j] . cell ( ) ,
246
247
) ?;
247
248
}
248
249
}
@@ -292,7 +293,7 @@ pub(crate) fn extract_accumulators_and_proof(
292
293
& snark. instances ,
293
294
& mut transcript_read,
294
295
) ;
295
- // wenqing: each accumulator has (lhs, rhs) based on Shplonk
296
+ // each accumulator has (lhs, rhs) based on Shplonk
296
297
// lhs and rhs are EC points
297
298
Shplonk :: succinct_verify ( & svk, & snark. protocol , & snark. instances , & proof)
298
299
} )
@@ -302,7 +303,7 @@ pub(crate) fn extract_accumulators_and_proof(
302
303
PoseidonTranscript :: < NativeLoader , Vec < u8 > > :: from_spec ( vec ! [ ] , POSEIDON_SPEC . clone ( ) ) ;
303
304
// We always use SHPLONK for accumulation scheme when aggregating proofs
304
305
let accumulator =
305
- // wenqing: core step
306
+ // core step
306
307
// KzgAs does KZG accumulation scheme based on given accumulators and random number (for adding blinding)
307
308
// accumulated ec_pt = ec_pt_1 * 1 + ec_pt_2 * r + ... + ec_pt_n * r^{n-1}
308
309
// ec_pt can be lhs and rhs
0 commit comments