@@ -27,7 +27,8 @@ use zkevm_circuits::{
2727
2828use crate :: {
2929 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 ,
3132} ;
3233
3334/// Input the hash input bytes,
@@ -50,18 +51,18 @@ pub(crate) fn assign_batch_hashes<F: Field>(
5051 let num_rows = 1 << LOG_DEGREE ;
5152
5253 let timer = start_timer ! ( || ( "multi keccak" ) . to_string( ) ) ;
53- // wenqing: preimages consists of the following parts
54+ // preimages consists of the following parts
5455 // (1) batchPiHash preimage =
5556 // (chain_id ||
5657 // chunk[0].prev_state_root ||
5758 // chunk[k-1].post_state_root ||
5859 // chunk[k-1].withdraw_root ||
5960 // batch_data_hash)
60- // (2) batchDataHash preimage =
61+ // (2) batchDataHash preimage =
6162 // (chunk[0].dataHash || ... || chunk[k-1].dataHash)
6263 // (3) chunk[i].piHash preimage =
6364 // (chain id ||
64- // chunk[i].prevStateRoot || chunk[i].postStateRoot ||
65+ // chunk[i].prevStateRoot || chunk[i].postStateRoot ||
6566 // chunk[i].withdrawRoot || chunk[i].datahash)
6667 // each part of the preimage is mapped to image by Keccak256
6768 let witness = multi_keccak ( preimages, challenges, capacity ( num_rows) ) ?;
@@ -98,12 +99,12 @@ pub(crate) fn assign_batch_hashes<F: Field>(
9899 let row = config. set_row ( & mut region, offset, keccak_row) ?;
99100
100101 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
102103 current_hash_input_cells. push ( row[ 6 ] . clone ( ) ) ;
103104 cur_preimage_index = preimage_indices_iter. next ( ) ;
104105 }
105106 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
107108 current_hash_output_cells. push ( row. last ( ) . unwrap ( ) . clone ( ) ) ;
108109 cur_digest_index = digest_indices_iter. next ( ) ;
109110 }
@@ -142,14 +143,14 @@ pub(crate) fn assign_batch_hashes<F: Field>(
142143 for i in 0 ..4 {
143144 for j in 0 ..8 {
144145 // 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
146147 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 ] ,
148149 & hash_output_cells[ 1 ] [ ( 3 - i) * 8 + j] ,
149150 ) ;
150151 region. constrain_equal (
151152 // 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 ( ) ,
153154 hash_output_cells[ 1 ] [ ( 3 - i) * 8 + j] . cell ( ) ,
154155 ) ?;
155156 }
@@ -172,39 +173,39 @@ pub(crate) fn assign_batch_hashes<F: Field>(
172173 // chunk[i].postStateRoot ||
173174 // chunk[i].withdrawRoot ||
174175 // 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
179180 for i in 0 ..32 {
180181 // 2.2.1 chunk[0].prev_state_root
181182 // sanity check
182183 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 ] ,
185186 ) ;
186187 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 ( ) ,
189190 ) ?;
190191 // 2.2.2 chunk[k-1].post_state_root
191192 // sanity check
192193 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 ] ,
195196 ) ;
196197 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 ( ) ,
199200 ) ?;
200201 // 2.2.3 chunk[k-1].withdraw_root
201202 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 ] ,
204205 ) ;
205206 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 ( ) ,
208209 ) ?;
209210 }
210211
@@ -222,10 +223,10 @@ pub(crate) fn assign_batch_hashes<F: Field>(
222223 for ( i, chunk) in hash_input_cells[ 1 ] . chunks ( 32 ) . enumerate ( ) . take ( num_chunks) {
223224 for ( j, cell) in chunk. iter ( ) . enumerate ( ) {
224225 // 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 ] ) ;
226227 region. constrain_equal (
227228 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 ( ) ,
229230 ) ?;
230231 }
231232 }
@@ -235,14 +236,14 @@ pub(crate) fn assign_batch_hashes<F: Field>(
235236 for j in 0 ..32 {
236237 // sanity check
237238 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] ,
240241 ) ;
241242 region. constrain_equal (
242243 // 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 ( ) ,
244245 // 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 ( ) ,
246247 ) ?;
247248 }
248249 }
@@ -292,7 +293,7 @@ pub(crate) fn extract_accumulators_and_proof(
292293 & snark. instances ,
293294 & mut transcript_read,
294295 ) ;
295- // wenqing: each accumulator has (lhs, rhs) based on Shplonk
296+ // each accumulator has (lhs, rhs) based on Shplonk
296297 // lhs and rhs are EC points
297298 Shplonk :: succinct_verify ( & svk, & snark. protocol , & snark. instances , & proof)
298299 } )
@@ -302,7 +303,7 @@ pub(crate) fn extract_accumulators_and_proof(
302303 PoseidonTranscript :: < NativeLoader , Vec < u8 > > :: from_spec ( vec ! [ ] , POSEIDON_SPEC . clone ( ) ) ;
303304 // We always use SHPLONK for accumulation scheme when aggregating proofs
304305 let accumulator =
305- // wenqing: core step
306+ // core step
306307 // KzgAs does KZG accumulation scheme based on given accumulators and random number (for adding blinding)
307308 // accumulated ec_pt = ec_pt_1 * 1 + ec_pt_2 * r + ... + ec_pt_n * r^{n-1}
308309 // ec_pt can be lhs and rhs
0 commit comments