@@ -2,10 +2,12 @@ import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
2
2
import { assert , describe , it } from 'vitest'
3
3
4
4
import { type PrefixedHexString , hexToBytes } from '@ethereumjs/util'
5
+ import { LOADX_BASE_COST , SETMODX_BASE_COST , STOREX_BASE_COST } from '../../src/evmmax/index.ts'
5
6
import { createEVM } from '../../src/index.ts'
6
7
7
8
const MSTORE8 = '53'
8
9
const RETURN = 'f3'
10
+ const PUSH1 = '60'
9
11
10
12
const SETMODX = 'c0'
11
13
const LOADX = 'c1'
@@ -20,19 +22,32 @@ function numToOpcode(num: number) {
20
22
}
21
23
22
24
function mstore8 ( index : number , value : number ) {
23
- return numToOpcode ( value ) + numToOpcode ( index ) + MSTORE8
25
+ // return numToOpcode(value) + numToOpcode(index) + MSTORE8
26
+ return PUSH1 + numToOpcode ( value ) + PUSH1 + numToOpcode ( index ) + MSTORE8
24
27
}
25
28
26
29
function ret ( index : number , size : number ) {
27
30
return size + index + RETURN
28
31
}
29
32
30
- function setupx ( num_val_slots : number , mod_size : number , mod_offset : number ) {
31
- return numToOpcode ( num_val_slots ) + numToOpcode ( mod_size ) + numToOpcode ( mod_offset ) + SETMODX
33
+ function setupx ( id : number , mod_size : number , mod_offset : number , alloc_count : number ) {
34
+ return (
35
+ PUSH1 +
36
+ numToOpcode ( alloc_count ) +
37
+ PUSH1 +
38
+ numToOpcode ( mod_size ) +
39
+ PUSH1 +
40
+ numToOpcode ( mod_offset ) +
41
+ PUSH1 +
42
+ numToOpcode ( id ) +
43
+ SETMODX
44
+ )
32
45
}
33
46
34
- function storex ( num_vals : number , val_offset : number , val_slot : number ) {
35
- return numToOpcode ( num_vals ) + numToOpcode ( val_offset ) + numToOpcode ( val_slot ) + STOREX
47
+ function storex ( dst : number , source : number , count : number ) {
48
+ return (
49
+ PUSH1 + numToOpcode ( dst ) + PUSH1 + numToOpcode ( source ) + PUSH1 + numToOpcode ( count ) + STOREX
50
+ )
36
51
}
37
52
38
53
function loadx ( num_vals : number , val_idx : number , mem_offset : number ) {
@@ -53,22 +68,35 @@ function mulmodx(result_slot_idx: number, x_slot_idx: number, y_slot_idx: number
53
68
54
69
describe ( 'EVM -> getActiveOpcodes()' , ( ) => {
55
70
it ( 'should not expose opcodes from a follow-up HF (istanbul -> petersburg)' , async ( ) => {
56
- const common = new Common ( { chain : Mainnet , eips : [ 6990 ] } )
71
+ const common = new Common ( {
72
+ chain : Mainnet ,
73
+ eips : [ 6690 ] ,
74
+ params : {
75
+ 6690 : {
76
+ setmodxGas : SETMODX_BASE_COST ,
77
+ loadxGas : LOADX_BASE_COST ,
78
+ storexGas : STOREX_BASE_COST ,
79
+ addmodxGas : 0 ,
80
+ submodxGas : 0 ,
81
+ mulmodxGas : 0 ,
82
+ } ,
83
+ } ,
84
+ } )
57
85
const evm = await createEVM ( { common } )
58
86
59
87
// create bytecode
60
88
const bytecode =
61
89
'0x' +
62
90
mstore8 ( 0 , 7 ) + // store value 0x07 at index 0 in memory
63
- setupx ( 3 , 32 , 0 ) +
64
- mstore8 ( 32 , 3 ) +
65
- mstore8 ( 64 , 6 ) +
66
- storex ( 2 , 32 , 0 ) +
67
- addmodx ( 2 , 1 , 0 ) +
68
- mulmodx ( 2 , 2 , 1 ) +
69
- submodx ( 2 , 2 , 1 ) +
70
- loadx ( 1 , 2 , 96 ) +
71
- ret ( 96 , 32 )
91
+ setupx ( 0 , 1 , 0 , 3 ) +
92
+ mstore8 ( 1 , 3 ) +
93
+ mstore8 ( 2 , 6 ) +
94
+ storex ( 2 , 0 , 0 ) +
95
+ addmodx ( 2 , 1 , 0 )
96
+ // + mulmodx(2, 2, 1)
97
+ // + submodx(2, 2, 1)
98
+ // + loadx(1, 2, 96)
99
+ // + ret(96, 32)
72
100
73
101
console . log ( bytecode )
74
102
0 commit comments