@@ -164,113 +164,6 @@ global tail_path_multipliers_chunk3: [Field; 32] = [0x01000000000000000000000000
164
164
global tail_path_multipliers_chunk2 : [Field ; 32 ] = [0x01000000000000000000000000000000000000000000000000 , 0x01000000000000000000000000000000000000000000000000 , 0x01000000000000000000000000000000000000000000000000 , 0x01000000000000000000000000000000000000000000000000 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0100000000000000000000000000000000 , 0x0100000000000000000000000000000000 , 0x0100000000000000000000000000000000 , 0x0100000000000000000000000000000000 , 0x00 , 0x00 , 0x00 , 0x00 , 0x010000000000000000 , 0x010000000000000000 , 0x010000000000000000 , 0x010000000000000000 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 ];
165
165
global tail_path_multipliers_chunk1 : [Field ; 32 ] = [0x0100000000000000000000000000000000000000000000000000000000 , 0x0100000000000000000000000000000000000000000000000000000000 , 0x00 , 0x00 , 0x01000000000000000000000000000000000000000000000000 , 0x01000000000000000000000000000000000000000000000000 , 0x00 , 0x00 , 0x010000000000000000000000000000000000000000 , 0x010000000000000000000000000000000000000000 , 0x00 , 0x00 , 0x0100000000000000000000000000000000 , 0x0100000000000000000000000000000000 , 0x00 , 0x00 , 0x01000000000000000000000000 , 0x01000000000000000000000000 , 0x00 , 0x00 , 0x010000000000000000 , 0x010000000000000000 , 0x00 , 0x00 , 0x0100000000 , 0x0100000000 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 ];
166
166
global tail_path_multipliers_chunk0 : [Field ; 32 ] = [0x01000000000000000000000000000000000000000000000000000000000000 , 0x00 , 0x0100000000000000000000000000000000000000000000000000000000 , 0x00 , 0x010000000000000000000000000000000000000000000000000000 , 0x00 , 0x01000000000000000000000000000000000000000000000000 , 0x00 , 0x0100000000000000000000000000000000000000000000 , 0x00 , 0x010000000000000000000000000000000000000000 , 0x00 , 0x01000000000000000000000000000000000000 , 0x00 , 0x0100000000000000000000000000000000 , 0x00 , 0x010000000000000000000000000000 , 0x00 , 0x01000000000000000000000000 , 0x00 , 0x0100000000000000000000 , 0x00 , 0x010000000000000000 , 0x00 , 0x01000000000000 , 0x00 , 0x0100000000 , 0x00 , 0x010000 , 0x00 , 0x01 , 0x00 ];
167
- // // what do we multiply 4 byte chunk by
168
- // global tail_path_multipliers_chunk2: [Field; 32] = [
169
- // /* 0 (00000) */ 0,
170
- // /* 1 (00001) */ 0,
171
- // /* 2 (00010) */ 0,
172
- // /* 3 (00011) */ 0,
173
- // /* 4 (00100) */ 1,
174
- // /* 5 (00101) */ 1,
175
- // /* 6 (00110) */ 1,
176
- // /* 7 (00111) */ 1,
177
- // /* 8 (01000) */ 0,
178
- // /* 9 (01001) */ 0,
179
- // /* 10 (01010) */ 0,
180
- // /* 11 (01011) */ 0,
181
- // /* 12 (01100) */ two_pow_64,
182
- // /* 13 (01101) */ two_pow_64,
183
- // /* 14 (01110) */ two_pow_64,
184
- // /* 15 (01111) */ two_pow_64,
185
- // /* 16 (10000) */ 0,
186
- // /* 17 (10001) */ 0,
187
- // /* 18 (10010) */ 0,
188
- // /* 19 (10011) */ 0,
189
- // /* 20 (10100) */ two_pow_128,
190
- // /* 21 (10101) */ two_pow_128,
191
- // /* 22 (10110) */ two_pow_128,
192
- // /* 23 (10111) */ two_pow_128,
193
- // /* 24 (11000) */ 0,
194
- // /* 25 (11001) */ 0,
195
- // /* 26 (11010) */ 0,
196
- // /* 27 (11011) */ 0,
197
- // /* 28 (11100) */ two_pow_128 * two_pow_64,
198
- // /* 29 (11101) */ two_pow_128 * two_pow_64,
199
- // /* 30 (11110) */ two_pow_128 * two_pow_64,
200
- // /* 31 (11111) */ two_pow_128 * two_pow_64
201
- // ];
202
-
203
- // // what do we multiply 2 byte chunk by
204
- // global tail_path_multipliers_chunk1: [Field; 32] = [
205
- // /* 0 (00000) */ 0,
206
- // /* 1 (00001) */ 0,
207
- // /* 2 (00010) */ 1,
208
- // /* 3 (00011) */ 1,
209
- // /* 4 (00100) */ 0,
210
- // /* 5 (00101) */ 0,
211
- // /* 6 (00110) */ two_pow_32,
212
- // /* 7 (00111) */ two_pow_32,
213
- // /* 8 (01000) */ 0,
214
- // /* 9 (01001) */ 0,
215
- // /* 10 (01010) */ two_pow_64,
216
- // /* 11 (01011) */ two_pow_64,
217
- // /* 12 (01100) */ 0,
218
- // /* 13 (01101) */ 0,
219
- // /* 14 (01110) */ two_pow_64 * two_pow_32,
220
- // /* 15 (01111) */ two_pow_64 * two_pow_32,
221
- // /* 16 (10000) */ 0,
222
- // /* 17 (10001) */ 0,
223
- // /* 18 (10010) */ two_pow_128,
224
- // /* 19 (10011) */ two_pow_128,
225
- // /* 20 (10100) */ 0,
226
- // /* 21 (10101) */ 0,
227
- // /* 22 (10110) */ two_pow_128 * two_pow_32,
228
- // /* 23 (10111) */ two_pow_128 * two_pow_32,
229
- // /* 24 (11000) */ 0,
230
- // /* 25 (11001) */ 0,
231
- // /* 26 (11010) */ two_pow_128 * two_pow_64,
232
- // /* 27 (11011) */ two_pow_128 * two_pow_64,
233
- // /* 28 (11100) */ 0,
234
- // /* 29 (11101) */ 0,
235
- // /* 30 (11110) */ two_pow_128 * two_pow_64 * two_pow_32,
236
- // /* 31 (11111) */ two_pow_128 * two_pow_64 * two_pow_32
237
- // ];
238
-
239
- // // what do we multiply 1 byte chunk by
240
- // global tail_path_multipliers_chunk0: [Field; 32] = [
241
- // /* 0 (00000) */ 0,
242
- // /* 1 (00001) */ 1,
243
- // /* 2 (00010) */ 0,
244
- // /* 3 (00011) */ two_pow_16,
245
- // /* 4 (00100) */ 0,
246
- // /* 5 (00101) */ two_pow_32,
247
- // /* 6 (00110) */ 0,
248
- // /* 7 (00111) */ two_pow_16 * two_pow_32,
249
- // /* 8 (01000) */ 0,
250
- // /* 9 (01001) */ two_pow_64,
251
- // /* 10 (01010) */ 0,
252
- // /* 11 (01011) */ two_pow_64 * two_pow_16,
253
- // /* 12 (01100) */ 0,
254
- // /* 13 (01101) */ two_pow_64 * two_pow_32,
255
- // /* 14 (01110) */ 0,
256
- // /* 15 (01111) */ two_pow_64 * two_pow_32 * two_pow_16,
257
- // /* 16 (10000) */ 0,
258
- // /* 17 (10001) */ two_pow_128,
259
- // /* 18 (10010) */ 0,
260
- // /* 19 (10011) */ two_pow_128 * two_pow_16,
261
- // /* 20 (10100) */ 0,
262
- // /* 21 (10101) */ two_pow_128 * two_pow_32,
263
- // /* 22 (10110) */ 0,
264
- // /* 23 (10111) */ two_pow_128 * two_pow_32 * two_pow_16,
265
- // /* 24 (11000) */ 0,
266
- // /* 25 (11001) */ two_pow_128 * two_pow_64,
267
- // /* 26 (11010) */ 0,
268
- // /* 27 (11011) */ two_pow_128 * two_pow_64 * two_pow_16,
269
- // /* 28 (11100) */ 0,
270
- // /* 29 (11101) */ two_pow_128 * two_pow_64 * two_pow_32,
271
- // /* 30 (11110) */ 0,
272
- // /* 31 (11111) */ two_pow_128 * two_pow_64 * two_pow_32 * two_pow_16
273
- // ];
274
167
275
168
fn sum_var_bytes_into_field <let N : u32 >(body_text : [u8 ; N ], body_index : Field , num_bytes : Field ) -> Field {
276
169
let path = get_path (num_bytes ); // 5 gates
@@ -307,7 +200,6 @@ fn sum_var_bytes_into_field<let N: u32>(body_text: [u8; N], body_index: Field, n
307
200
+ body_text [idx + 12 ] as Field * 0x1000000 + body_text [idx + 13 ] as Field * 0x10000
308
201
+ body_text [idx + 14 ] as Field * 0x100 + body_text [idx + 15 ] as Field ;
309
202
310
- //chunks[4] = chunks[3] * chunks[3];
311
203
chunks [0 ] *= path_f [0 ];
312
204
chunks [1 ] *= path_f [1 ];
313
205
chunks [2 ] *= path_f [2 ];
@@ -316,15 +208,7 @@ fn sum_var_bytes_into_field<let N: u32>(body_text: [u8; N], body_index: Field, n
316
208
317
209
let mut sum : Field = 0 ;
318
210
319
- // if 0 0 1 1
320
-
321
- // if 0 1 0 1 (little endian)
322
- // we have chunk[1] and chunk[3]
323
- // therefore we need chunk[1] * 8^16
324
- // if 0 1 1 1 (little endian)
325
- // we need chunk[2] * 8^16, chunk[3] * 8^24
326
211
let mut multiplicand : Field = 1 ;
327
- // println(f"chunks = {chunks}");
328
212
sum += chunks [4 ];
329
213
multiplicand *= (0x100000000000000000000000000000000 * path_f [4 ]) + (1 - path_f [4 ]);
330
214
sum += chunks [3 ] * multiplicand ;
@@ -334,15 +218,8 @@ fn sum_var_bytes_into_field<let N: u32>(body_text: [u8; N], body_index: Field, n
334
218
sum += chunks [1 ] * multiplicand ;
335
219
multiplicand *= (0x10000 * path_f [1 ]) + (1 - path_f [1 ]);
336
220
sum += chunks [0 ] * multiplicand ;
337
-
338
- // sum *= BYTE_SHIFT[num_bytes];
339
- // 0x74657374410000000000000000000000000000000000000000000000000000
340
- // 0x74657374410000000000000000000000000000000000000000000000000000
341
- // length = l, byte_shift = (31 - l)
342
221
sum
343
222
}
344
- // 0x74657374410000000000000000000000000000000000000000000000000000
345
- // 0x7465737441
346
223
347
224
fn get_keyhash_chunky <let N : u32 >(body_text : [u8 ; N ], body_index : u16 , key_length : u16 ) -> Field {
348
225
assert (key_length < MaxKeyBytes , "key too large" );
@@ -379,15 +256,8 @@ impl<let KeyFields: u16> Hasher<KeyFields> {
379
256
380
257
fn get_keyhash <let NumPackedFields : u16 >(_ : Self , packed_fields : [Field ; NumPackedFields ], body_index : Field , key_length : Field ) -> Field {
381
258
let key_fields : [Field ; KeyFields ] = slice_fields (packed_fields , body_index , key_length );
382
-
383
- let hashed_full = dep::std::hash::poseidon2::Poseidon2 ::hash (key_fields , KeyFields as u32 );
384
- // let hashed_full: Field = key_fields[0] + key_fields[1] + key_fields[2];
385
-
386
- let r = slice_200_bits_from_field (hashed_full );
387
- r
388
- // let r = key_fields[0] + key_fields[1] + key_fields[2];
389
- // std::as_witness(r);
390
- // key_fields[2]
259
+ let hashed = dep::std::hash::poseidon2::Poseidon2 ::hash (key_fields , KeyFields as u32 );
260
+ slice_200_bits_from_field (hashed )
391
261
}
392
262
}
393
263
0 commit comments