8
8
VERKLE_MAIN_STORAGE_OFFSET ,
9
9
VERKLE_NODE_WIDTH ,
10
10
bytesToHex ,
11
+ equalsBytes ,
11
12
getVerkleKey ,
12
13
getVerkleStem ,
13
14
getVerkleTreeIndicesForCodeChunk ,
@@ -403,15 +404,16 @@ export const generateExecutionWitness = async (
403
404
}
404
405
const accessedSuffixes = new Map < PrefixedHexString , number [ ] > ( )
405
406
for ( const chunkKey of accessWitness [ 'chunks' ] . keys ( ) ) {
406
- const stem = chunkKey . slice ( 0 , 34 ) as PrefixedHexString
407
+ const stem = chunkKey . slice ( 0 , 64 ) as PrefixedHexString
407
408
if ( accessedSuffixes . has ( stem ) ) {
408
409
const suffixes = accessedSuffixes . get ( stem )
409
- suffixes ! . push ( parseInt ( chunkKey . slice ( 34 ) , 16 ) )
410
+ suffixes ! . push ( parseInt ( chunkKey . slice ( 64 ) , 16 ) )
410
411
accessedSuffixes . set ( stem , suffixes ! )
411
412
} else {
412
- accessedSuffixes . set ( stem , [ parseInt ( chunkKey . slice ( 34 ) , 16 ) ] )
413
+ accessedSuffixes . set ( stem , [ parseInt ( chunkKey . slice ( 64 ) , 16 ) ] )
413
414
}
414
415
}
416
+
415
417
// Get values
416
418
for ( const stem of accessedSuffixes . keys ( ) ) {
417
419
trie . root ( parentStateRoot )
@@ -420,14 +422,22 @@ export const generateExecutionWitness = async (
420
422
const newValues = await trie . get ( hexToBytes ( stem ) , accessedSuffixes . get ( stem ) ! )
421
423
const stemStateDiff = [ ]
422
424
for ( const suffix of accessedSuffixes . get ( stem ) ! ) {
423
- if ( currentValues [ suffix ] === newValues [ suffix ] ) continue
425
+ // skip if both are the same
426
+ if (
427
+ notNullish ( currentValues [ suffix ] ) &&
428
+ notNullish ( newValues [ suffix ] ) &&
429
+ equalsBytes ( currentValues [ suffix ] ! , newValues [ suffix ] ! )
430
+ )
431
+ continue
424
432
stemStateDiff . push ( {
425
433
suffix,
426
- currentValue : currentValues [ suffix ] ? bytesToHex ( currentValues [ suffix ] ) : null ,
427
- newValue : newValues [ suffix ] ? bytesToHex ( newValues [ suffix ] ) : null ,
434
+ currentValue : currentValues [ suffix ] ? bytesToHex ( currentValues [ suffix ] ! ) : null ,
435
+ newValue : newValues [ suffix ] ? bytesToHex ( newValues [ suffix ] ! ) : null ,
428
436
} )
429
437
}
430
438
ew . stateDiff . push ( { stem, suffixDiffs : stemStateDiff } )
431
439
}
432
440
return ew
433
441
}
442
+
443
+ const notNullish = ( value : any ) => value !== null && value !== undefined
0 commit comments