Skip to content

EIP 6690: EVMMAX implementation #3816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4f24ab4
Add evmmax to common
am1r021 Dec 18, 2024
7c85448
Add opcode handler skeletons
am1r021 Dec 18, 2024
f830abc
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Dec 18, 2024
3595599
Install bigint-mod-arith package
am1r021 Dec 18, 2024
6b5f895
Add helper function
am1r021 Dec 20, 2024
58c2dae
Add helper function
am1r021 Dec 20, 2024
553272e
Add base for FieldContext class
am1r021 Dec 20, 2024
40561c3
Remove utils and update arith helpers
am1r021 Jan 2, 2025
d827327
Complete implementation of fieldContext for binary modulus
am1r021 Jan 2, 2025
f76f420
Move helper and constant to arith
am1r021 Jan 2, 2025
d546bfb
Test fieldContext for binary modulus arithmetic
am1r021 Jan 2, 2025
70f3562
Export fieldContext
am1r021 Jan 2, 2025
bb4fd1b
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Jan 2, 2025
d432767
Fix linting issues
am1r021 Jan 2, 2025
0074f51
Fix lint/type issues and debug binary arithmetic issues
am1r021 Jan 2, 2025
006b104
Fix tests
am1r021 Jan 2, 2025
164a358
Complete and clean up fieldContext add, sub, and mod tests
am1r021 Jan 3, 2025
00896bf
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Jan 14, 2025
d0445a2
Implement 64-bit montMul, sub, and add preset functions and update tests
am1r021 Jan 16, 2025
82a64c3
Implement, debug, and add 128-bit preset functions
am1r021 Jan 21, 2025
9e0f864
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Jan 21, 2025
3685202
Finish rest of preset functions, organize code into files, document code
am1r021 Feb 6, 2025
e93d62e
Remove unused dep
am1r021 Feb 28, 2025
75eb7c8
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Feb 28, 2025
cb042d3
Do not activate evmmax opcodes from chainstart
am1r021 Feb 28, 2025
ab5dbb2
Add field context and allocations to evmmax runstate
am1r021 Mar 24, 2025
cdab157
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Mar 24, 2025
897f710
Add placeholder gas functions
am1r021 Mar 24, 2025
d3fe18e
Group code better
am1r021 Mar 24, 2025
278e800
Remove evmmax as hardfork and activate only via eip via common
am1r021 Mar 24, 2025
38e2bad
Add eip 6990 to activatable eips
am1r021 Mar 24, 2025
91ee64f
Implement opcode functions
am1r021 Mar 24, 2025
12e83bb
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Mar 26, 2025
c4e7198
Move evmmax util function to own util file
am1r021 Mar 26, 2025
88305d7
Addd constants
am1r021 Apr 1, 2025
8f1c864
Fix names and add getAlloced
am1r021 Apr 1, 2025
00e2930
Change gas handler types
am1r021 Apr 1, 2025
135dceb
Implement storex gas function and base evmmax cas cost model
am1r021 Apr 2, 2025
af34eae
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Apr 2, 2025
89265bf
Fix lint and build issues
am1r021 Apr 2, 2025
9d87011
Update constants
am1r021 Apr 3, 2025
cd88d03
Finish gas functions
am1r021 Apr 3, 2025
e92a597
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Apr 21, 2025
44decd3
Fix import
am1r021 Apr 22, 2025
1096460
Fix build errors
am1r021 Apr 22, 2025
64d4668
Add evmmax opcode test
am1r021 Apr 22, 2025
f2404b1
Fixes
am1r021 Apr 23, 2025
7ead43b
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Apr 23, 2025
2d40d54
Debug addmodx opcode
am1r021 Apr 23, 2025
2517715
evmmax: ensure correct immediates are read
jochem-brouwer Apr 23, 2025
8bddbb4
Push debug code
am1r021 Apr 29, 2025
47410f1
Merge branch 'master' of github.com:ethereumjs/ethereumjs-monorepo in…
am1r021 Apr 29, 2025
fe4646c
Debug arithmetic functions
am1r021 Apr 30, 2025
9c978c4
Debug evmmax opcode tests
am1r021 Apr 30, 2025
03336d1
Remove debug logs
am1r021 Apr 30, 2025
40ed073
Remove debug logs
am1r021 Apr 30, 2025
3503335
Update tests
am1r021 May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export const Mainnet: ChainConfig = {
name: 'osaka',
block: null,
},
{
name: 'evmmax',
block: null,
},
],
bootstrapNodes: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export enum Hardfork {
Prague = 'prague',
Osaka = 'osaka',
Verkle = 'verkle',
EVMMax = 'evmmax',
}

export enum ConsensusType {
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/hardforks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,7 @@ export const hardforksDict: HardforksDict = {
verkle: {
eips: [4762, 6800],
},
evmmax: {
eips: [6690],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should do an evmmax hardfork for this: if EVMMAX should be activated then the 6690 EIP should be activated (so instantiate a common and activate 6990 to use EVMMAX). I might have missed something from the EIP though. It seems to me that the EIP introduces new opcodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, currently 6 new opcodes are added upon evmmax activation.

},
}
1 change: 1 addition & 0 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function parseGethParams(json: any) {
[Hardfork.Cancun]: { name: 'cancunTime', postMerge: true, isTimestamp: true },
[Hardfork.Prague]: { name: 'pragueTime', postMerge: true, isTimestamp: true },
[Hardfork.Verkle]: { name: 'verkleTime', postMerge: true, isTimestamp: true },
[Hardfork.EVMMax]: { name: 'evmmaxTime', postMerge: true, isTimestamp: true },
}

// forkMapRev is the map from config field name to Hardfork
Expand Down
21 changes: 21 additions & 0 deletions packages/evm/src/opcodes/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
0xa3: dynamicGasOp('LOG'),
0xa4: dynamicGasOp('LOG'),

// '0xf0' range - extended range/width modular arithmetic
0xc0: asyncAndDynamicGasOp('SETMODX'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add these opcodes as available from all EVMs at all hardforks (so these opcodes are now available at Frontier / Chainstart)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the declarations here and only left the ones in eipOpcodes, I think that should fix this so that they only activate via eip activation via common.

0xc1: asyncAndDynamicGasOp('LOADX'),
0xc2: asyncAndDynamicGasOp('STOREX'),
0xc3: asyncAndDynamicGasOp('ADDMODX'),
0xc4: asyncAndDynamicGasOp('SUBMODX'),
0xc5: asyncAndDynamicGasOp('MULMODX'),

// '0xf0' range - closures
0xf0: asyncAndDynamicGasOp('CREATE'),
0xf1: asyncAndDynamicGasOp('CALL'),
Expand Down Expand Up @@ -372,6 +380,19 @@
0xee: asyncAndDynamicGasOp('RETURNCONTRACT'),
},
},
{
eip: 6690,
opcodes: {
// control & i/o
0xc0: asyncAndDynamicGasOp('SETMODX'),
0xc1: asyncAndDynamicGasOp('LOADX'),
0xc2: asyncAndDynamicGasOp('STOREX'),
// arithmetic
0xc3: asyncAndDynamicGasOp('ADDMODX'),
0xc4: asyncAndDynamicGasOp('SUBMODX'),
0xc5: asyncAndDynamicGasOp('MULMODX'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: for dynamic gas ops, a gas method should be provided in gas.ts, otherwise the Interpreter will crash (it expects an entry there if the opcode is marked as dynamic)

},
},
]

/**
Expand Down Expand Up @@ -436,7 +457,7 @@
}

for (const key in opcodeBuilder) {
const baseFee = Number(common.param(`${opcodeBuilder[key].name.toLowerCase()}Gas`))

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/asyncEvents.spec.ts > async events > should work

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/asyncEvents.spec.ts:11:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/blobVersionedHashes.spec.ts > BLOBHASH / access blobVersionedHashes in calldata > should work

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/blobVersionedHashes.spec.ts:25:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/blobVersionedHashes.spec.ts > BLOBHASH: access blobVersionedHashes within contract calls > should work

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/blobVersionedHashes.spec.ts:55:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/blobVersionedHashes.spec.ts > BLOBHASH: access blobVersionedHashes in a CREATE/CREATE2 frame > should work

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/blobVersionedHashes.spec.ts:105:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customCrypto.spec.ts > custom crypto > should use custom sha256 function

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customCrypto.spec.ts:25:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customCrypto.spec.ts > custom crypto > should use custom ecrecover function

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customCrypto.spec.ts:48:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customOpcodes.spec.ts > VM: custom opcodes > should add custom opcodes to the EVM

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customOpcodes.spec.ts:28:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customOpcodes.spec.ts > VM: custom opcodes > should delete opcodes from the EVM

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customOpcodes.spec.ts:46:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customOpcodes.spec.ts > VM: custom opcodes > should not override default opcodes

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customOpcodes.spec.ts:60:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / evm / test-evm

test/customOpcodes.spec.ts > VM: custom opcodes > should override opcodes in the EVM

Error: Missing parameter value for setmodxGas ❯ Common.param ../common/src/common.ts:360:13 ❯ Module.getOpcodesForHF src/opcodes/codes.ts:460:35 ❯ EVM.getActiveOpcodes src/evm.ts:254:18 ❯ new EVM src/evm.ts:217:10 ❯ Module.createEVM src/constructors.ts:35:10 ❯ test/customOpcodes.spec.ts:89:23

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/asyncEvents.spec.ts > async events > should work

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/asyncEvents.spec.ts:11:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/blobVersionedHashes.spec.ts > BLOBHASH / access blobVersionedHashes in calldata > should work

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/blobVersionedHashes.spec.ts:25:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/blobVersionedHashes.spec.ts > BLOBHASH: access blobVersionedHashes within contract calls > should work

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/blobVersionedHashes.spec.ts:55:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/blobVersionedHashes.spec.ts > BLOBHASH: access blobVersionedHashes in a CREATE/CREATE2 frame > should work

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/blobVersionedHashes.spec.ts:105:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customCrypto.spec.ts > custom crypto > should use custom sha256 function

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customCrypto.spec.ts:25:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customCrypto.spec.ts > custom crypto > should use custom ecrecover function

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customCrypto.spec.ts:48:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customOpcodes.spec.ts > VM: custom opcodes > should add custom opcodes to the EVM

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customOpcodes.spec.ts:28:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customOpcodes.spec.ts > VM: custom opcodes > should delete opcodes from the EVM

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customOpcodes.spec.ts:46:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customOpcodes.spec.ts > VM: custom opcodes > should not override default opcodes

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customOpcodes.spec.ts:60:22

Check failure on line 460 in packages/evm/src/opcodes/codes.ts

View workflow job for this annotation

GitHub Actions / browser / test-all-browser

test/customOpcodes.spec.ts > VM: custom opcodes > should override opcodes in the EVM

Error: Missing parameter value for setmodxGas ❯ getOpcodesForHF src/opcodes/codes.ts:460:34 ❯ EVM.getActiveOpcodes src/evm.ts:254:17 ❯ new EVM src/evm.ts:217:9 ❯ createEVM src/constructors.ts:35:9 ❯ test/customOpcodes.spec.ts:89:22
// explicitly verify that we have defined a base fee
if (baseFee === undefined) {
throw new Error(`base fee not defined for: ${opcodeBuilder[key].name}`)
Expand Down
42 changes: 42 additions & 0 deletions packages/evm/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,48 @@ export const handlers: Map<number, OpHandler> = new Map([
runState.interpreter.log(mem, topicsCount, topicsBuf)
},
],
// 0xc0: SETMODX
[
0xc0,
function (runState, _common) {
return
},
],
// 0xc1: STOREX
[
0xc1,
function (runState, _common) {
return
},
],
// 0xc2: LOADX
[
0xc2,
function (runState, _common) {
return
},
],
// 0xc3: ADDMODX
[
0xc3,
function (runState, _common) {
return
},
],
// 0xc4: SUBMODX
[
0xc4,
function (runState, _common) {
return
},
],
// 0xc5: MULMODX
[
0xc5,
function (runState, _common) {
return
},
],
// 0xd0: DATALOAD
[
0xd0,
Expand Down
Loading