Skip to content

Commit f2404b1

Browse files
committed
Fixes
1 parent 64d4668 commit f2404b1

File tree

6 files changed

+55
-22
lines changed

6 files changed

+55
-22
lines changed

packages/common/src/eips.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export const eipsDict: EIPsDict = {
348348
* URL : https://eips.ethereum.org/EIPS/eip-6690
349349
* Status : Draft
350350
*/
351-
6990: {
351+
6690: {
352352
minimumHardfork: Hardfork.Prague,
353353
},
354354
/**

packages/evm/src/evm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class EVM implements EVMInterface {
250250
const supportedEIPs = [
251251
663, 1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3198, 3529, 3540, 3541, 3607, 3651, 3670,
252252
3855, 3860, 4200, 4399, 4750, 4788, 4844, 4895, 5133, 5450, 5656, 6110, 6206, 6780, 6800,
253-
6990, 7002, 7069, 7251, 7480, 7516, 7620, 7685, 7691, 7692, 7698, 7702, 7709,
253+
6690, 7002, 7069, 7251, 7480, 7516, 7620, 7685, 7691, 7692, 7698, 7702, 7709,
254254
]
255255

256256
for (const eip of this.common.eips()) {

packages/evm/src/evmmax/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const SETMODX_BASE_COST = 1
12
export const STOREX_BASE_COST = 1
23
export const LOADX_BASE_COST = 1
34
export const MAX_ALLOC_SIZE = 96 * 256

packages/evm/src/opcodes/gas.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
870870
async function (runState, gas, common): Promise<bigint> {
871871
const [dst, src, count] = runState.stack.peek(3)
872872

873-
if (!isUint64(src) || src >= runState.memoryWordCount) {
873+
if (!isUint64(src) || src >= runState.memory._store.length) {
874874
trap('src index out of bounds')
875875
}
876876
if (!isUint64(dst) || dst >= runState.evmmaxState.getActive().getNumElems()) {
@@ -880,7 +880,7 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
880880
trap('count must be less than number of field elements in the active space')
881881
}
882882
const storeSize = count * runState.evmmaxState.getActive().getNumElems()
883-
if (src + storeSize > runState.memoryWordCount) {
883+
if (src + storeSize > runState.memory._store.length) {
884884
trap('source of copy out of bounds of EVM memory')
885885
}
886886

@@ -890,7 +890,11 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
890890
return (
891891
gas +
892892
count *
893-
BigInt(MULMODX_COST[Number(runState.evmmaxState.getActive().getElemSize() / 8) - 1])
893+
BigInt(
894+
MULMODX_COST[
895+
Number(Math.ceil(runState.evmmaxState.getActive().getElemSize() / 8)) - 1
896+
],
897+
)
894898
)
895899
}
896900
},

packages/evm/test/eips/eip-6990.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
22
import { assert, describe, it } from 'vitest'
33
import { createEVM } from '../../src/index.ts'
44

5-
describe('EIP 6990 tests', async () => {
5+
describe('EIP 6690 tests', async () => {
66
it(`evmmax instantiation`, async () => {
77
const evm = await createEVM({
88
common: new Common({
99
hardfork: Hardfork.Prague,
10-
eips: [6990],
10+
eips: [6690],
1111
chain: Mainnet,
1212
}),
1313
})

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

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
22
import { assert, describe, it } from 'vitest'
33

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

78
const MSTORE8 = '53'
89
const RETURN = 'f3'
10+
const PUSH1 = '60'
911

1012
const SETMODX = 'c0'
1113
const LOADX = 'c1'
@@ -20,19 +22,32 @@ function numToOpcode(num: number) {
2022
}
2123

2224
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
2427
}
2528

2629
function ret(index: number, size: number) {
2730
return size + index + RETURN
2831
}
2932

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+
)
3245
}
3346

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+
)
3651
}
3752

3853
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
5368

5469
describe('EVM -> getActiveOpcodes()', () => {
5570
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+
})
5785
const evm = await createEVM({ common })
5886

5987
// create bytecode
6088
const bytecode =
6189
'0x' +
6290
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)
72100

73101
console.log(bytecode)
74102

0 commit comments

Comments
 (0)