Skip to content

Commit 3503335

Browse files
committed
Update tests
1 parent 40ed073 commit 3503335

File tree

1 file changed

+75
-11
lines changed

1 file changed

+75
-11
lines changed

packages/evm/test/evmmax/opcodes.spec.ts

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Common, Mainnet } from '@ethereumjs/common'
22
import { assert, describe, it } from 'vitest'
33

44
import { type PrefixedHexString, createAddressFromString, hexToBytes } from '@ethereumjs/util'
5+
import { bigIntToBytes } from '@ethereumjs/util'
56
import { LOADX_BASE_COST, SETMODX_BASE_COST, STOREX_BASE_COST } from '../../src/evmmax/index.ts'
67
import { createEVM } from '../../src/index.ts'
78

@@ -31,7 +32,7 @@ function ret(index: number, size: number) {
3132
return size + index + RETURN
3233
}
3334

34-
function setupx(id: number, mod_size: number, mod_offset: number, alloc_count: number) {
35+
function setupx(id: number, mod_offset: number, mod_size: number, alloc_count: number) {
3536
return (
3637
PUSH1 +
3738
numToOpcode(alloc_count) +
@@ -120,8 +121,66 @@ function mulmodx(
120121
)
121122
}
122123

123-
describe('EVM -> getActiveOpcodes()', () => {
124-
it('should not expose opcodes from a follow-up HF (istanbul -> petersburg)', async () => {
124+
describe('should be able to perform modular arithmetic with evmmax opcodes', () => {
125+
// it('1-byte modulus test', async () => {
126+
// const common = new Common({
127+
// chain: Mainnet,
128+
// eips: [6690],
129+
// params: {
130+
// 6690: {
131+
// setmodxGas: SETMODX_BASE_COST,
132+
// loadxGas: LOADX_BASE_COST,
133+
// storexGas: STOREX_BASE_COST,
134+
// addmodxGas: 0,
135+
// submodxGas: 0,
136+
// mulmodxGas: 0,
137+
// },
138+
// },
139+
// })
140+
// const evm = await createEVM({ common })
141+
// evm.events.on('step', (e) => {
142+
// console.log(e.opcode.name)
143+
// })
144+
145+
// const modulus = 8n
146+
// const modBytes = bigIntToBytes(modulus)
147+
148+
// console.log('dbg100')
149+
// console.log(addmodx(0, 1, 1, 1, 2, 1, 1))
150+
// console.log(modBytes)
151+
// // create bytecode
152+
// const bytecode =
153+
// '0x' +
154+
// mstore8(0, 8) + // store value 0x08 at index 0 in memory
155+
// setupx(0, 1, 0, 3) +
156+
// mstore8(1, 3) +
157+
// mstore8(2, 6) +
158+
// storex(1, 1, 1) +
159+
// storex(2, 2, 1) +
160+
// addmodx(0, 1, 1, 1, 2, 1, 1) +
161+
// mulmodx(0, 1, 1, 1, 2, 1, 1) +
162+
// submodx(0, 1, 1, 1, 2, 1, 1) +
163+
// loadx(0, 0, 1)
164+
// // + ret(96, 32)
165+
166+
// const ADDR_TO_CALL = createAddressFromString('0x' + '20'.repeat(20))
167+
168+
// await evm.stateManager.putCode(ADDR_TO_CALL, hexToBytes(bytecode as PrefixedHexString))
169+
170+
// const result = await evm.runCall({
171+
// to: ADDR_TO_CALL,
172+
// gasLimit: BigInt(0xffffff),
173+
// })
174+
175+
// // const result1 = await evm.runCall({
176+
// // data: hexToBytes(bytecode as PrefixedHexString),
177+
// // gasLimit: BigInt(0xffffff),
178+
// // })
179+
180+
// console.log(result)
181+
// })
182+
183+
it('2-byte modulus test', async () => {
125184
const common = new Common({
126185
chain: Mainnet,
127186
eips: [6690],
@@ -137,19 +196,24 @@ describe('EVM -> getActiveOpcodes()', () => {
137196
},
138197
})
139198
const evm = await createEVM({ common })
140-
evm.events.on('step', (e) => {
141-
console.log(e.opcode.name)
142-
})
199+
const modulus = 500n
200+
const modBytes = bigIntToBytes(modulus)
201+
202+
// const elemByteLen = Number(fieldCtx.elemSize)
203+
// const xBytes = padBigIntBytes(xInt, elemByteLen * 8)
204+
// const yBytes = padBigIntBytes(yInt, elemByteLen * 8)
205+
// const outBytes = new Uint8Array(elemByteLen * 8)
143206

144207
console.log('dbg100')
145-
console.log(addmodx(0, 1, 1, 1, 2, 1, 1))
208+
console.log(modBytes)
146209
// create bytecode
147210
const bytecode =
148211
'0x' +
149-
mstore8(0, 8) + // store value 0x08 at index 0 in memory
150-
setupx(0, 1, 0, 3) +
151-
mstore8(1, 3) +
152-
mstore8(2, 6) +
212+
mstore8(0, modBytes[1]) +
213+
mstore8(1, modBytes[0]) +
214+
setupx(0, 0, 2, 3) +
215+
mstore8(2, 220) +
216+
mstore8(4, 230) +
153217
storex(1, 1, 1) +
154218
storex(2, 2, 1) +
155219
addmodx(0, 1, 1, 1, 2, 1, 1) +

0 commit comments

Comments
 (0)