@@ -22,7 +22,7 @@ import {
22
22
TYPE_MIN ,
23
23
VERSION ,
24
24
} from './constants.ts'
25
- import { EOFError , validationError } from './errors.ts'
25
+ import { EOFErrorMessage , validationError } from './errors.ts'
26
26
import { ContainerSectionType , verifyCode } from './verify.ts'
27
27
28
28
import type { EVM } from '../evm.ts'
@@ -64,7 +64,7 @@ class StreamReader {
64
64
readBytes ( amount : number , errorStr ?: string ) {
65
65
const end = this . ptr + amount
66
66
if ( end > this . data . length ) {
67
- validationError ( EOFError . OUT_OF_BOUNDS , this . ptr , errorStr )
67
+ validationError ( EOFErrorMessage . OUT_OF_BOUNDS , this . ptr , errorStr )
68
68
}
69
69
const ptr = this . ptr
70
70
this . ptr += amount
@@ -78,7 +78,7 @@ class StreamReader {
78
78
*/
79
79
readUint ( errorStr ?: string ) {
80
80
if ( this . ptr >= this . data . length ) {
81
- validationError ( EOFError . OUT_OF_BOUNDS , this . ptr , errorStr )
81
+ validationError ( EOFErrorMessage . OUT_OF_BOUNDS , this . ptr , errorStr )
82
82
}
83
83
return this . data [ this . ptr ++ ]
84
84
}
@@ -91,7 +91,7 @@ class StreamReader {
91
91
*/
92
92
verifyUint ( expect : number , errorStr ?: string ) {
93
93
if ( this . readUint ( ) !== expect ) {
94
- validationError ( EOFError . VERIFY_UINT , this . ptr - 1 , errorStr )
94
+ validationError ( EOFErrorMessage . VERIFY_UINT , this . ptr - 1 , errorStr )
95
95
}
96
96
}
97
97
@@ -103,7 +103,7 @@ class StreamReader {
103
103
readUint16 ( errorStr ?: string ) {
104
104
const end = this . ptr + 2
105
105
if ( end > this . data . length ) {
106
- validationError ( EOFError . OUT_OF_BOUNDS , this . ptr , errorStr )
106
+ validationError ( EOFErrorMessage . OUT_OF_BOUNDS , this . ptr , errorStr )
107
107
}
108
108
const ptr = this . ptr
109
109
this . ptr += 2
@@ -155,41 +155,41 @@ class EOFHeader {
155
155
}
156
156
const stream = new StreamReader ( input )
157
157
// Verify that the header starts with 0xEF0001
158
- stream . verifyUint ( FORMAT , EOFError . FORMAT )
159
- stream . verifyUint ( MAGIC , EOFError . MAGIC )
160
- stream . verifyUint ( VERSION , EOFError . VERSION )
158
+ stream . verifyUint ( FORMAT , EOFErrorMessage . FORMAT )
159
+ stream . verifyUint ( MAGIC , EOFErrorMessage . MAGIC )
160
+ stream . verifyUint ( VERSION , EOFErrorMessage . VERSION )
161
161
if ( input . length < 15 ) {
162
162
throw EthereumJSErrorWithoutCode ( 'err: container size less than minimum valid size' )
163
163
}
164
164
// Verify that the types section is present and its length is valid
165
- stream . verifyUint ( KIND_TYPE , EOFError . KIND_TYPE )
166
- const typeSize = stream . readUint16 ( EOFError . TYPE_SIZE )
165
+ stream . verifyUint ( KIND_TYPE , EOFErrorMessage . KIND_TYPE )
166
+ const typeSize = stream . readUint16 ( EOFErrorMessage . TYPE_SIZE )
167
167
if ( typeSize < TYPE_MIN ) {
168
- validationError ( EOFError . INVALID_TYPE_SIZE , typeSize )
168
+ validationError ( EOFErrorMessage . INVALID_TYPE_SIZE , typeSize )
169
169
}
170
170
if ( typeSize % TYPE_DIVISOR !== 0 ) {
171
- validationError ( EOFError . INVALID_TYPE_SIZE , typeSize )
171
+ validationError ( EOFErrorMessage . INVALID_TYPE_SIZE , typeSize )
172
172
}
173
173
if ( typeSize > TYPE_MAX ) {
174
174
throw EthereumJSErrorWithoutCode (
175
175
`err: number of code sections must not exceed 1024 (got ${ typeSize } )` ,
176
176
)
177
177
}
178
178
// Verify that the code section is present and its size is valid
179
- stream . verifyUint ( KIND_CODE , EOFError . KIND_CODE )
180
- const codeSize = stream . readUint16 ( EOFError . CODE_SIZE )
179
+ stream . verifyUint ( KIND_CODE , EOFErrorMessage . KIND_CODE )
180
+ const codeSize = stream . readUint16 ( EOFErrorMessage . CODE_SIZE )
181
181
if ( codeSize < CODE_MIN ) {
182
- validationError ( EOFError . MIN_CODE_SECTIONS )
182
+ validationError ( EOFErrorMessage . MIN_CODE_SECTIONS )
183
183
}
184
184
if ( codeSize !== typeSize / TYPE_DIVISOR ) {
185
- validationError ( EOFError . TYPE_SECTIONS , typeSize / TYPE_DIVISOR , codeSize )
185
+ validationError ( EOFErrorMessage . TYPE_SECTIONS , typeSize / TYPE_DIVISOR , codeSize )
186
186
}
187
187
// Read the actual code sizes in the code section and verify that each section has the minimum size
188
188
const codeSizes = [ ]
189
189
for ( let i = 0 ; i < codeSize ; i ++ ) {
190
- const codeSectionSize = stream . readUint16 ( EOFError . CODE_SECTION )
190
+ const codeSectionSize = stream . readUint16 ( EOFErrorMessage . CODE_SECTION )
191
191
if ( codeSectionSize < CODE_SIZE_MIN ) {
192
- validationError ( EOFError . CODE_SECTION_SIZE )
192
+ validationError ( EOFErrorMessage . CODE_SECTION_SIZE )
193
193
}
194
194
codeSizes . push ( codeSectionSize )
195
195
}
@@ -199,21 +199,21 @@ class EOFHeader {
199
199
const containerSizes : number [ ] = [ ]
200
200
if ( nextSection === KIND_CONTAINER ) {
201
201
// The optional container section is present, validate that the size is within bounds
202
- const containerSectionSize = stream . readUint16 ( EOFError . CONTAINER_SIZE )
202
+ const containerSectionSize = stream . readUint16 ( EOFErrorMessage . CONTAINER_SIZE )
203
203
204
204
if ( containerSectionSize < CONTAINER_MIN ) {
205
- validationError ( EOFError . CONTAINER_SECTION_SIZE )
205
+ validationError ( EOFErrorMessage . CONTAINER_SECTION_SIZE )
206
206
}
207
207
if ( containerSectionSize > CONTAINER_MAX ) {
208
- validationError ( EOFError . CONTAINER_SECTION_SIZE )
208
+ validationError ( EOFErrorMessage . CONTAINER_SECTION_SIZE )
209
209
}
210
210
211
211
// Read the actual container sections and validate that each section has the minimum size
212
212
for ( let i = 0 ; i < containerSectionSize ; i ++ ) {
213
- const containerSize = stream . readUint16 ( EOFError . CONTAINER_SECTION )
213
+ const containerSize = stream . readUint16 ( EOFErrorMessage . CONTAINER_SECTION )
214
214
215
215
if ( containerSize < CONTAINER_SIZE_MIN ) {
216
- validationError ( EOFError . CONTAINER_SECTION_MIN )
216
+ validationError ( EOFErrorMessage . CONTAINER_SECTION_MIN )
217
217
}
218
218
219
219
containerSizes . push ( containerSize )
@@ -224,15 +224,15 @@ class EOFHeader {
224
224
225
225
// Verify that the next section is of the data type
226
226
if ( nextSection !== KIND_DATA ) {
227
- validationError ( EOFError . KIND_DATA )
227
+ validationError ( EOFErrorMessage . KIND_DATA )
228
228
}
229
229
230
230
this . dataSizePtr = stream . getPtr ( )
231
231
232
- const dataSize = stream . readUint16 ( EOFError . DATA_SIZE )
232
+ const dataSize = stream . readUint16 ( EOFErrorMessage . DATA_SIZE )
233
233
234
234
// Verify that the header ends with the TERMINATOR byte
235
- stream . verifyUint ( TERMINATOR , EOFError . TERMINATOR )
235
+ stream . verifyUint ( TERMINATOR , EOFErrorMessage . TERMINATOR )
236
236
237
237
// Write all values to the header object
238
238
this . typeSize = typeSize
@@ -327,25 +327,25 @@ class EOFBody {
327
327
const typeSections : TypeSection [ ] = [ ]
328
328
// Read and parse each type section, and validate that the type section values are within valid bounds
329
329
for ( let i = 0 ; i < header . typeSize / 4 ; i ++ ) {
330
- const inputs = stream . readUint ( EOFError . INPUTS )
331
- const outputs = stream . readUint ( EOFError . OUTPUTS )
332
- const maxStackHeight = stream . readUint16 ( EOFError . MAX_STACK_HEIGHT )
330
+ const inputs = stream . readUint ( EOFErrorMessage . INPUTS )
331
+ const outputs = stream . readUint ( EOFErrorMessage . OUTPUTS )
332
+ const maxStackHeight = stream . readUint16 ( EOFErrorMessage . MAX_STACK_HEIGHT )
333
333
if ( i === 0 ) {
334
334
if ( inputs !== 0 ) {
335
- validationError ( EOFError . CODE0_INPUTS )
335
+ validationError ( EOFErrorMessage . CODE0_INPUTS )
336
336
}
337
337
if ( outputs !== 0x80 ) {
338
- validationError ( EOFError . CODE0_OUTPUTS )
338
+ validationError ( EOFErrorMessage . CODE0_OUTPUTS )
339
339
}
340
340
}
341
341
if ( inputs > INPUTS_MAX ) {
342
- validationError ( EOFError . MAX_INPUTS , i , inputs )
342
+ validationError ( EOFErrorMessage . MAX_INPUTS , i , inputs )
343
343
}
344
344
if ( outputs > OUTPUTS_MAX ) {
345
- validationError ( EOFError . MAX_OUTPUTS , i , outputs )
345
+ validationError ( EOFErrorMessage . MAX_OUTPUTS , i , outputs )
346
346
}
347
347
if ( maxStackHeight > MAX_STACK_HEIGHT ) {
348
- validationError ( EOFError . MAX_STACK_HEIGHT_LIMIT , i , maxStackHeight )
348
+ validationError ( EOFErrorMessage . MAX_STACK_HEIGHT_LIMIT , i , maxStackHeight )
349
349
}
350
350
typeSections . push ( {
351
351
inputs,
@@ -361,7 +361,7 @@ class EOFBody {
361
361
const code = stream . readBytes ( codeSize )
362
362
codes . push ( code )
363
363
} catch {
364
- validationError ( EOFError . CODE_SECTION , i )
364
+ validationError ( EOFErrorMessage . CODE_SECTION , i )
365
365
}
366
366
}
367
367
// Write the entire code section to the entireCodeSection
@@ -374,7 +374,7 @@ class EOFBody {
374
374
const container = stream . readBytes ( containerSize )
375
375
containers . push ( container )
376
376
} catch {
377
- validationError ( EOFError . CONTAINER_SECTION , i )
377
+ validationError ( EOFErrorMessage . CONTAINER_SECTION , i )
378
378
}
379
379
}
380
380
@@ -386,12 +386,12 @@ class EOFBody {
386
386
387
387
// Edge case: deployment code validation
388
388
if ( eofMode !== EOFContainerMode . Initmode && ! dataSectionAllowedSmaller ) {
389
- dataSection = stream . readBytes ( header . dataSize , EOFError . DATA_SECTION )
389
+ dataSection = stream . readBytes ( header . dataSize , EOFErrorMessage . DATA_SECTION )
390
390
391
391
if ( eofMode === EOFContainerMode . Default ) {
392
392
if ( ! stream . isAtEnd ( ) ) {
393
393
// If there are dangling bytes in default container mode, this is invalid
394
- validationError ( EOFError . DANGLING_BYTES )
394
+ validationError ( EOFErrorMessage . DANGLING_BYTES )
395
395
}
396
396
} else {
397
397
// Tx init mode: the remaining bytes (if any) are used as CALLDATA in the EVM, in case of a Tx init
@@ -401,7 +401,7 @@ class EOFBody {
401
401
dataSection = stream . readRemainder ( )
402
402
403
403
if ( dataSection . length > header . dataSize ) {
404
- validationError ( EOFError . DANGLING_BYTES )
404
+ validationError ( EOFErrorMessage . DANGLING_BYTES )
405
405
}
406
406
}
407
407
0 commit comments