1
1
import {
2
- BALANCE_LEAF_KEY ,
3
2
BIGINT_0 ,
4
- CODE_HASH_LEAF_KEY ,
5
- CODE_OFFSET ,
6
- CODE_SIZE_LEAF_KEY ,
7
- HEADER_STORAGE_OFFSET ,
8
- MAIN_STORAGE_OFFSET ,
9
- NONCE_LEAF_KEY ,
3
+ VERKLE_BALANCE_LEAF_KEY ,
4
+ VERKLE_CODE_HASH_LEAF_KEY ,
5
+ VERKLE_CODE_OFFSET ,
6
+ VERKLE_CODE_SIZE_LEAF_KEY ,
7
+ VERKLE_HEADER_STORAGE_OFFSET ,
8
+ VERKLE_MAIN_STORAGE_OFFSET ,
10
9
VERKLE_NODE_WIDTH ,
11
- VERSION_LEAF_KEY ,
10
+ VERKLE_NONCE_LEAF_KEY ,
11
+ VERKLE_VERSION_LEAF_KEY ,
12
12
bytesToBigInt ,
13
13
bytesToHex ,
14
- getKey ,
15
- getStem ,
16
- getTreeIndicesForCodeChunk ,
14
+ getVerkleKey ,
15
+ getVerkleStem ,
16
+ getVerkleTreeIndicesForCodeChunk ,
17
17
hexToBytes ,
18
18
intToBytes ,
19
19
} from '@ethereumjs/util'
@@ -90,79 +90,79 @@ export class AccessWitness implements AccessWitnessInterface {
90
90
touchAndChargeProofOfAbsence ( address : Address ) : bigint {
91
91
let gas = BIGINT_0
92
92
93
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERSION_LEAF_KEY )
94
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , BALANCE_LEAF_KEY )
95
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , CODE_SIZE_LEAF_KEY )
96
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , CODE_HASH_LEAF_KEY )
97
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , NONCE_LEAF_KEY )
93
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_VERSION_LEAF_KEY )
94
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_BALANCE_LEAF_KEY )
95
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_CODE_SIZE_LEAF_KEY )
96
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_CODE_HASH_LEAF_KEY )
97
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_NONCE_LEAF_KEY )
98
98
99
99
return gas
100
100
}
101
101
102
102
touchAndChargeMessageCall ( address : Address ) : bigint {
103
103
let gas = BIGINT_0
104
104
105
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERSION_LEAF_KEY )
106
- gas += this . touchAddressOnReadAndComputeGas ( address , 0 , CODE_SIZE_LEAF_KEY )
105
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_VERSION_LEAF_KEY )
106
+ gas += this . touchAddressOnReadAndComputeGas ( address , 0 , VERKLE_CODE_SIZE_LEAF_KEY )
107
107
108
108
return gas
109
109
}
110
110
111
111
touchAndChargeValueTransfer ( caller : Address , target : Address ) : bigint {
112
112
let gas = BIGINT_0
113
113
114
- gas += this . touchAddressOnWriteAndComputeGas ( caller , 0 , BALANCE_LEAF_KEY )
115
- gas += this . touchAddressOnWriteAndComputeGas ( target , 0 , BALANCE_LEAF_KEY )
114
+ gas += this . touchAddressOnWriteAndComputeGas ( caller , 0 , VERKLE_BALANCE_LEAF_KEY )
115
+ gas += this . touchAddressOnWriteAndComputeGas ( target , 0 , VERKLE_BALANCE_LEAF_KEY )
116
116
117
117
return gas
118
118
}
119
119
120
120
touchAndChargeContractCreateInit ( address : Address ) : bigint {
121
121
let gas = BIGINT_0
122
122
123
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERSION_LEAF_KEY )
124
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , NONCE_LEAF_KEY )
123
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_VERSION_LEAF_KEY )
124
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_NONCE_LEAF_KEY )
125
125
126
126
return gas
127
127
}
128
128
129
129
touchAndChargeContractCreateCompleted ( address : Address ) : bigint {
130
130
let gas = BIGINT_0
131
131
132
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERSION_LEAF_KEY )
133
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , BALANCE_LEAF_KEY )
134
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , CODE_SIZE_LEAF_KEY )
135
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , CODE_HASH_LEAF_KEY )
136
- gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , NONCE_LEAF_KEY )
132
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_VERSION_LEAF_KEY )
133
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_BALANCE_LEAF_KEY )
134
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_CODE_SIZE_LEAF_KEY )
135
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_CODE_HASH_LEAF_KEY )
136
+ gas += this . touchAddressOnWriteAndComputeGas ( address , 0 , VERKLE_NONCE_LEAF_KEY )
137
137
138
138
return gas
139
139
}
140
140
141
141
touchTxOriginAndComputeGas ( origin : Address ) : bigint {
142
142
let gas = BIGINT_0
143
143
144
- gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , VERSION_LEAF_KEY )
145
- gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , CODE_SIZE_LEAF_KEY )
146
- gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , CODE_HASH_LEAF_KEY )
144
+ gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , VERKLE_VERSION_LEAF_KEY )
145
+ gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , VERKLE_CODE_SIZE_LEAF_KEY )
146
+ gas += this . touchAddressOnReadAndComputeGas ( origin , 0 , VERKLE_CODE_HASH_LEAF_KEY )
147
147
148
- gas += this . touchAddressOnWriteAndComputeGas ( origin , 0 , NONCE_LEAF_KEY )
149
- gas += this . touchAddressOnWriteAndComputeGas ( origin , 0 , BALANCE_LEAF_KEY )
148
+ gas += this . touchAddressOnWriteAndComputeGas ( origin , 0 , VERKLE_NONCE_LEAF_KEY )
149
+ gas += this . touchAddressOnWriteAndComputeGas ( origin , 0 , VERKLE_BALANCE_LEAF_KEY )
150
150
151
151
return gas
152
152
}
153
153
154
154
touchTxTargetAndComputeGas ( target : Address , { sendsValue } : { sendsValue ?: boolean } = { } ) {
155
155
let gas = BIGINT_0
156
156
157
- gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERSION_LEAF_KEY )
158
- gas += this . touchAddressOnReadAndComputeGas ( target , 0 , CODE_SIZE_LEAF_KEY )
159
- gas += this . touchAddressOnReadAndComputeGas ( target , 0 , CODE_HASH_LEAF_KEY )
160
- gas += this . touchAddressOnReadAndComputeGas ( target , 0 , NONCE_LEAF_KEY )
157
+ gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERKLE_VERSION_LEAF_KEY )
158
+ gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERKLE_CODE_SIZE_LEAF_KEY )
159
+ gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERKLE_CODE_HASH_LEAF_KEY )
160
+ gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERKLE_NONCE_LEAF_KEY )
161
161
162
162
if ( sendsValue === true ) {
163
- gas += this . touchAddressOnWriteAndComputeGas ( target , 0 , BALANCE_LEAF_KEY )
163
+ gas += this . touchAddressOnWriteAndComputeGas ( target , 0 , VERKLE_BALANCE_LEAF_KEY )
164
164
} else {
165
- gas += this . touchAddressOnReadAndComputeGas ( target , 0 , BALANCE_LEAF_KEY )
165
+ gas += this . touchAddressOnReadAndComputeGas ( target , 0 , VERKLE_BALANCE_LEAF_KEY )
166
166
}
167
167
168
168
return gas
@@ -171,7 +171,7 @@ export class AccessWitness implements AccessWitnessInterface {
171
171
touchCodeChunksRangeOnReadAndChargeGas ( contact : Address , startPc : number , endPc : number ) : bigint {
172
172
let gas = BIGINT_0
173
173
for ( let chunkNum = Math . floor ( startPc / 31 ) ; chunkNum <= Math . floor ( endPc / 31 ) ; chunkNum ++ ) {
174
- const { treeIndex, subIndex } = getTreeIndicesForCodeChunk ( chunkNum )
174
+ const { treeIndex, subIndex } = getVerkleTreeIndicesForCodeChunk ( chunkNum )
175
175
gas += this . touchAddressOnReadAndComputeGas ( contact , treeIndex , subIndex )
176
176
}
177
177
return gas
@@ -184,7 +184,7 @@ export class AccessWitness implements AccessWitnessInterface {
184
184
) : bigint {
185
185
let gas = BIGINT_0
186
186
for ( let chunkNum = Math . floor ( startPc / 31 ) ; chunkNum <= Math . floor ( endPc / 31 ) ; chunkNum ++ ) {
187
- const { treeIndex, subIndex } = getTreeIndicesForCodeChunk ( chunkNum )
187
+ const { treeIndex, subIndex } = getVerkleTreeIndicesForCodeChunk ( chunkNum )
188
188
gas += this . touchAddressOnWriteAndComputeGas ( contact , treeIndex , subIndex )
189
189
}
190
190
return gas
@@ -259,7 +259,7 @@ export class AccessWitness implements AccessWitnessInterface {
259
259
// i.e. no fill cost is charged right now
260
260
const chunkFill = false
261
261
262
- const accessedStemKey = getStem ( this . verkleCrypto , address , treeIndex )
262
+ const accessedStemKey = getVerkleStem ( this . verkleCrypto , address , treeIndex )
263
263
const accessedStemHex = bytesToHex ( accessedStemKey )
264
264
let accessedStem = this . stems . get ( accessedStemHex )
265
265
if ( accessedStem === undefined ) {
@@ -268,7 +268,7 @@ export class AccessWitness implements AccessWitnessInterface {
268
268
this . stems . set ( accessedStemHex , accessedStem )
269
269
}
270
270
271
- const accessedChunkKey = getKey (
271
+ const accessedChunkKey = getVerkleKey (
272
272
accessedStemKey ,
273
273
typeof subIndex === 'number' ? intToBytes ( subIndex ) : subIndex
274
274
)
@@ -368,18 +368,18 @@ export function decodeAccessedState(treeIndex: number | bigint, chunkIndex: numb
368
368
case BigInt ( 4 ) :
369
369
return { type : AccessedStateType . CodeSize }
370
370
default :
371
- if ( position < HEADER_STORAGE_OFFSET ) {
372
- throw Error ( `No attribute yet stored >=5 and <${ HEADER_STORAGE_OFFSET } ` )
371
+ if ( position < VERKLE_HEADER_STORAGE_OFFSET ) {
372
+ throw Error ( `No attribute yet stored >=5 and <${ VERKLE_HEADER_STORAGE_OFFSET } ` )
373
373
}
374
374
375
- if ( position >= HEADER_STORAGE_OFFSET && position < CODE_OFFSET ) {
376
- const slot = position - BigInt ( HEADER_STORAGE_OFFSET )
375
+ if ( position >= VERKLE_HEADER_STORAGE_OFFSET && position < VERKLE_CODE_OFFSET ) {
376
+ const slot = position - BigInt ( VERKLE_HEADER_STORAGE_OFFSET )
377
377
return { type : AccessedStateType . Storage , slot }
378
- } else if ( position >= CODE_OFFSET && position < MAIN_STORAGE_OFFSET ) {
379
- const codeChunkIdx = Number ( position ) - CODE_OFFSET
378
+ } else if ( position >= VERKLE_CODE_OFFSET && position < VERKLE_MAIN_STORAGE_OFFSET ) {
379
+ const codeChunkIdx = Number ( position ) - VERKLE_CODE_OFFSET
380
380
return { type : AccessedStateType . Code , codeOffset : codeChunkIdx * 31 }
381
- } else if ( position >= MAIN_STORAGE_OFFSET ) {
382
- const slot = BigInt ( position - MAIN_STORAGE_OFFSET )
381
+ } else if ( position >= VERKLE_MAIN_STORAGE_OFFSET ) {
382
+ const slot = BigInt ( position - VERKLE_MAIN_STORAGE_OFFSET )
383
383
return { type : AccessedStateType . Storage , slot }
384
384
} else {
385
385
throw Error (
0 commit comments