@@ -63,6 +63,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
63
63
protected _debug : Debugger
64
64
protected _caches ?: Caches
65
65
66
+ preStateRoot : Uint8Array
66
67
originalStorageCache : OriginalStorageCache
67
68
verkleCrypto : VerkleCrypto
68
69
@@ -75,7 +76,6 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
75
76
// Post-state provided from the executionWitness.
76
77
// Should not update. Used for comparing our computed post-state with the canonical one.
77
78
private _postState : VerkleState = { }
78
- private _preState : VerkleState = { }
79
79
80
80
/**
81
81
* StateManager is run in DEBUG mode (default: false)
@@ -88,6 +88,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
88
88
protected readonly DEBUG : boolean = false
89
89
90
90
private keccakFunction : Function
91
+
91
92
constructor ( opts : StatefulVerkleStateManagerOpts ) {
92
93
// Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables
93
94
// Additional window check is to prevent vite browser bundling (and potentially other) to break
@@ -118,6 +119,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
118
119
this . _caches = opts . caches
119
120
this . keccakFunction = opts . common . customCrypto . keccak256 ?? keccak256
120
121
this . verkleCrypto = opts . common . customCrypto . verkle
122
+ this . preStateRoot = new Uint8Array ( 32 ) // Initial state root is zeroes
121
123
}
122
124
123
125
/**
@@ -179,23 +181,9 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
179
181
throw Error ( errorMsg )
180
182
}
181
183
182
- // Populate the pre-state and post-state from the executionWitness
183
- const preStateRaw = executionWitness . stateDiff . flatMap ( ( { stem, suffixDiffs } ) => {
184
- const suffixDiffPairs = suffixDiffs . map ( ( { currentValue, suffix } ) => {
185
- const key = `${ stem } ${ padToEven ( Number ( suffix ) . toString ( 16 ) ) } `
186
- return {
187
- [ key ] : currentValue ,
188
- }
189
- } )
190
-
191
- return suffixDiffPairs
192
- } )
184
+ this . preStateRoot = hexToBytes ( executionWitness . parentStateRoot ) // set prestate root if given
193
185
194
- // also maintain a separate preState unaffected by any changes in _state
195
- this . _preState = preStateRaw . reduce ( ( prevValue , currentValue ) => {
196
- const acc = { ...prevValue , ...currentValue }
197
- return acc
198
- } , { } )
186
+ // Populate the post-state from the executionWitness
199
187
200
188
const postStateRaw = executionWitness . stateDiff . flatMap ( ( { stem, suffixDiffs } ) => {
201
189
const suffixDiffPairs = suffixDiffs . map ( ( { newValue, currentValue, suffix } ) => {
@@ -219,7 +207,6 @@ export class StatefulVerkleStateManager implements StateManagerInterface {
219
207
220
208
this . _postState = postState
221
209
222
- this . _debug ( `initVerkleExecutionWitness preState=${ JSON . stringify ( this . _preState ) } ` )
223
210
this . _debug ( `initVerkleExecutionWitness postState=${ JSON . stringify ( this . _postState ) } ` )
224
211
}
225
212
0 commit comments