Skip to content
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

EIP 6690: EVMMAX implementation #3816

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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?

},
}
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)

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