Skip to content

Commit b92efed

Browse files
committed
execution witness fixes
1 parent 9f86549 commit b92efed

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/evm/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@ethereumjs/common": "^5.0.0-alpha.1",
5050
"@ethereumjs/statemanager": "^3.0.0-alpha.1",
5151
"@ethereumjs/util": "^10.0.0-alpha.1",
52+
"@ethereumjs/verkle": "^0.2.0-alpha.1",
5253
"@noble/curves": "^1.8.1",
5354
"@types/debug": "^4.1.9",
5455
"debug": "^4.3.3",

packages/evm/src/verkleAccessWitness.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
VERKLE_MAIN_STORAGE_OFFSET,
99
VERKLE_NODE_WIDTH,
1010
bytesToHex,
11+
equalsBytes,
1112
getVerkleKey,
1213
getVerkleStem,
1314
getVerkleTreeIndicesForCodeChunk,
@@ -403,15 +404,16 @@ export const generateExecutionWitness = async (
403404
}
404405
const accessedSuffixes = new Map<PrefixedHexString, number[]>()
405406
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
407408
if (accessedSuffixes.has(stem)) {
408409
const suffixes = accessedSuffixes.get(stem)
409-
suffixes!.push(parseInt(chunkKey.slice(34), 16))
410+
suffixes!.push(parseInt(chunkKey.slice(64), 16))
410411
accessedSuffixes.set(stem, suffixes!)
411412
} else {
412-
accessedSuffixes.set(stem, [parseInt(chunkKey.slice(34), 16)])
413+
accessedSuffixes.set(stem, [parseInt(chunkKey.slice(64), 16)])
413414
}
414415
}
416+
415417
// Get values
416418
for (const stem of accessedSuffixes.keys()) {
417419
trie.root(parentStateRoot)
@@ -420,14 +422,22 @@ export const generateExecutionWitness = async (
420422
const newValues = await trie.get(hexToBytes(stem), accessedSuffixes.get(stem)!)
421423
const stemStateDiff = []
422424
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
424432
stemStateDiff.push({
425433
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,
428436
})
429437
}
430438
ew.stateDiff.push({ stem, suffixDiffs: stemStateDiff })
431439
}
432440
return ew
433441
}
442+
443+
const notNullish = (value: any) => value !== null && value !== undefined

0 commit comments

Comments
 (0)