1
- import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
1
+ import { Common , Mainnet } from '@ethereumjs/common'
2
2
import { assert , describe , it } from 'vitest'
3
3
4
4
import { type PrefixedHexString , createAddressFromString , hexToBytes } from '@ethereumjs/util'
@@ -51,8 +51,10 @@ function storex(dst: number, source: number, count: number) {
51
51
)
52
52
}
53
53
54
- function loadx ( num_vals : number , val_idx : number , mem_offset : number ) {
55
- return numToOpcode ( num_vals ) + numToOpcode ( val_idx ) + numToOpcode ( mem_offset ) + LOADX
54
+ function loadx ( dest : number , source : number , count : number ) {
55
+ return (
56
+ PUSH1 + numToOpcode ( count ) + PUSH1 + numToOpcode ( source ) + PUSH1 + numToOpcode ( dest ) + LOADX
57
+ )
56
58
}
57
59
58
60
function addmodx (
@@ -76,12 +78,46 @@ function addmodx(
76
78
)
77
79
}
78
80
79
- function submodx ( result_slot_idx : number , x_slot_idx : number , y_slot_idx : number ) {
80
- return SUBMODX + numToOpcode ( result_slot_idx ) + numToOpcode ( x_slot_idx ) + numToOpcode ( y_slot_idx )
81
+ function submodx (
82
+ result_slot_idx : number ,
83
+ result_stride : number ,
84
+ x_slot_idx : number ,
85
+ x_stride : number ,
86
+ y_slot_idx : number ,
87
+ y_stride : number ,
88
+ count : number ,
89
+ ) {
90
+ return (
91
+ SUBMODX +
92
+ numToOpcode ( result_slot_idx ) +
93
+ numToOpcode ( result_stride ) +
94
+ numToOpcode ( x_slot_idx ) +
95
+ numToOpcode ( x_stride ) +
96
+ numToOpcode ( y_slot_idx ) +
97
+ numToOpcode ( y_stride ) +
98
+ numToOpcode ( count )
99
+ )
81
100
}
82
101
83
- function mulmodx ( result_slot_idx : number , x_slot_idx : number , y_slot_idx : number ) {
84
- return MULMODX + numToOpcode ( result_slot_idx ) + numToOpcode ( x_slot_idx ) + numToOpcode ( y_slot_idx )
102
+ function mulmodx (
103
+ result_slot_idx : number ,
104
+ result_stride : number ,
105
+ x_slot_idx : number ,
106
+ x_stride : number ,
107
+ y_slot_idx : number ,
108
+ y_stride : number ,
109
+ count : number ,
110
+ ) {
111
+ return (
112
+ MULMODX +
113
+ numToOpcode ( result_slot_idx ) +
114
+ numToOpcode ( result_stride ) +
115
+ numToOpcode ( x_slot_idx ) +
116
+ numToOpcode ( x_stride ) +
117
+ numToOpcode ( y_slot_idx ) +
118
+ numToOpcode ( y_stride ) +
119
+ numToOpcode ( count )
120
+ )
85
121
}
86
122
87
123
describe ( 'EVM -> getActiveOpcodes()' , ( ) => {
@@ -101,22 +137,25 @@ describe('EVM -> getActiveOpcodes()', () => {
101
137
} ,
102
138
} )
103
139
const evm = await createEVM ( { common } )
140
+ evm . events . on ( 'step' , ( e ) => {
141
+ console . log ( e . opcode . name )
142
+ } )
104
143
105
144
console . log ( 'dbg100' )
106
145
console . log ( addmodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 ) )
107
146
// create bytecode
108
147
const bytecode =
109
148
'0x' +
110
- mstore8 ( 0 , 8 ) + // store value 0x07 at index 0 in memory
149
+ mstore8 ( 0 , 8 ) + // store value 0x08 at index 0 in memory
111
150
setupx ( 0 , 1 , 0 , 3 ) +
112
151
mstore8 ( 1 , 3 ) +
113
152
mstore8 ( 2 , 6 ) +
114
153
storex ( 1 , 1 , 1 ) +
115
154
storex ( 2 , 2 , 1 ) +
116
- addmodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 )
117
- // + mulmodx(2, 2, 1)
118
- // + submodx(2, 2, 1)
119
- // + loadx(1, 2, 96 )
155
+ addmodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 ) +
156
+ mulmodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 ) +
157
+ submodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 ) +
158
+ loadx ( 0 , 0 , 1 )
120
159
// + ret(96, 32)
121
160
122
161
const ADDR_TO_CALL = createAddressFromString ( '0x' + '20' . repeat ( 20 ) )
0 commit comments