1- import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
1+ import { Common , Mainnet } from '@ethereumjs/common'
22import { assert , describe , it } from 'vitest'
33
44import { type PrefixedHexString , createAddressFromString , hexToBytes } from '@ethereumjs/util'
@@ -51,8 +51,10 @@ function storex(dst: number, source: number, count: number) {
5151 )
5252}
5353
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+ )
5658}
5759
5860function addmodx (
@@ -76,12 +78,46 @@ function addmodx(
7678 )
7779}
7880
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+ )
81100}
82101
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+ )
85121}
86122
87123describe ( 'EVM -> getActiveOpcodes()' , ( ) => {
@@ -101,22 +137,25 @@ describe('EVM -> getActiveOpcodes()', () => {
101137 } ,
102138 } )
103139 const evm = await createEVM ( { common } )
140+ evm . events . on ( 'step' , ( e ) => {
141+ console . log ( e . opcode . name )
142+ } )
104143
105144 console . log ( 'dbg100' )
106145 console . log ( addmodx ( 0 , 1 , 1 , 1 , 2 , 1 , 1 ) )
107146 // create bytecode
108147 const bytecode =
109148 '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
111150 setupx ( 0 , 1 , 0 , 3 ) +
112151 mstore8 ( 1 , 3 ) +
113152 mstore8 ( 2 , 6 ) +
114153 storex ( 1 , 1 , 1 ) +
115154 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 )
120159 // + ret(96, 32)
121160
122161 const ADDR_TO_CALL = createAddressFromString ( '0x' + '20' . repeat ( 20 ) )
0 commit comments