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

monorepo: remove EIP 2315 (JUMPSUB) #3342

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 0 additions & 21 deletions packages/common/src/eips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ export const EIPs: EIPsDict = {
},
},
},
2315: {
comment: 'Simple subroutines for the EVM',
url: 'https://eips.ethereum.org/EIPS/eip-2315',
status: Status.Draft,
minimumHardfork: Hardfork.Istanbul,
requiredEIPs: [],
gasPrices: {
beginsub: {
v: 2,
d: 'Base fee of the BEGINSUB opcode',
},
returnsub: {
v: 5,
d: 'Base fee of the RETURNSUB opcode',
},
jumpsub: {
v: 10,
d: 'Base fee of the JUMPSUB opcode',
},
},
},
2565: {
comment: 'ModExp gas cost',
url: 'https://eips.ethereum.org/EIPS/eip-2565',
Expand Down
10 changes: 0 additions & 10 deletions packages/common/test/eips.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ describe('[Common/EIPs]: Initialization / Chain params', () => {
*/
})

it('isActivatedEIP()', () => {
let c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
assert.equal(c.isActivatedEIP(2315), false, 'istanbul, eips: [] -> false (EIP-2315)')
c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul, eips: [2315] })
assert.equal(c.isActivatedEIP(2315), true, 'istanbul, eips: [2315] -> true (EIP-2315)')
c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin })
assert.equal(c.isActivatedEIP(2929), true, 'berlin, eips: [] -> true (EIP-2929)')
assert.equal(c.isActivatedEIP(2315), false, 'berlin, eips: [] -> true (EIP-2315)')
})

it('eipBlock', () => {
const c = new Common({ chain: Chain.Mainnet })

Expand Down
4 changes: 2 additions & 2 deletions packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export class EVM implements EVMInterface {

// Supported EIPs
const supportedEIPs = [
1153, 1559, 2315, 2565, 2718, 2929, 2930, 2935, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6780, 6800, 7516,
1153, 1559, 2565, 2718, 2929, 2930, 2935, 3074, 3198, 3529, 3540, 3541, 3607, 3651, 3670,
3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6780, 6800, 7516,
]

for (const eip of this.common.eips()) {
Expand Down
4 changes: 0 additions & 4 deletions packages/evm/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export interface RunState {
memoryWordCount: bigint
highestMemCost: bigint
stack: Stack
returnStack: Stack
code: Uint8Array
shouldDoJumpAnalysis: boolean
validJumps: Uint8Array // array of values where validJumps[index] has value 0 (default), 1 (jumpdest), 2 (beginsub)
Expand All @@ -105,7 +104,6 @@ export interface InterpreterStep {
gasRefund: bigint
stateManager: EVMStateManagerInterface
stack: bigint[]
returnStack: bigint[]
pc: number
depth: number
opcode: {
Expand Down Expand Up @@ -164,7 +162,6 @@ export class Interpreter {
memoryWordCount: BIGINT_0,
highestMemCost: BIGINT_0,
stack: new Stack(),
returnStack: new Stack(1023), // 1023 return stack height limit per EIP 2315 spec
code: new Uint8Array(0),
validJumps: Uint8Array.from([]),
cachedPushes: {},
Expand Down Expand Up @@ -413,7 +410,6 @@ export class Interpreter {
isAsync: opcode.isAsync,
},
stack: this._runState.stack.getStack(),
returnStack: this._runState.returnStack.getStack(),
depth: this._env.depth,
address: this._env.address,
account: this._env.contract,
Expand Down
8 changes: 0 additions & 8 deletions packages/evm/src/opcodes/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,6 @@ const eipOpcodes: { eip: number; opcodes: OpcodeEntry }[] = [
0x5d: { name: 'TSTORE', isAsync: false, dynamicGas: false },
},
},
{
eip: 2315,
opcodes: {
0x5c: { name: 'BEGINSUB', isAsync: false, dynamicGas: false },
0x5d: { name: 'RETURNSUB', isAsync: false, dynamicGas: false },
0x5e: { name: 'JUMPSUB', isAsync: false, dynamicGas: false },
},
},
{
eip: 3198,
opcodes: {
Expand Down
92 changes: 28 additions & 64 deletions packages/evm/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
fromTwos,
getDataSlice,
jumpIsValid,
jumpSubIsValid,
mod,
toTwos,
trap,
Expand Down Expand Up @@ -861,81 +860,46 @@ export const handlers: Map<number, OpHandler> = new Map([
],
// 0x5b: JUMPDEST
[0x5b, function () {}],
// 0x5c: BEGINSUB (EIP 2315) / TLOAD (EIP 1153)
// 0x5c: TLOAD (EIP 1153)
[
0x5c,
function (runState, common) {
if (common.isActivatedEIP(2315)) {
// BEGINSUB
trap(ERROR.INVALID_BEGINSUB + ' at ' + describeLocation(runState))
} else if (common.isActivatedEIP(1153)) {
// TLOAD
const key = runState.stack.pop()
const keyBuf = setLengthLeft(bigIntToBytes(key), 32)
const value = runState.interpreter.transientStorageLoad(keyBuf)
const valueBN = value.length ? bytesToBigInt(value) : BIGINT_0
runState.stack.push(valueBN)
}
function (runState) {
const key = runState.stack.pop()
const keyBuf = setLengthLeft(bigIntToBytes(key), 32)
const value = runState.interpreter.transientStorageLoad(keyBuf)
const valueBN = value.length ? bytesToBigInt(value) : BIGINT_0
runState.stack.push(valueBN)
},
],
// 0x5d: RETURNSUB (EIP 2315) / TSTORE (EIP 1153)
// 0x5d: TSTORE (EIP 1153)
[
0x5d,
function (runState, common) {
if (common.isActivatedEIP(2315)) {
// RETURNSUB
if (runState.returnStack.length < 1) {
trap(ERROR.INVALID_RETURNSUB)
}

const dest = runState.returnStack.pop()
runState.programCounter = Number(dest)
} else if (common.isActivatedEIP(1153)) {
// TSTORE
if (runState.interpreter.isStatic()) {
trap(ERROR.STATIC_STATE_CHANGE)
}
const [key, val] = runState.stack.popN(2)

const keyBuf = setLengthLeft(bigIntToBytes(key), 32)
// NOTE: this should be the shortest representation
let value
if (val === BIGINT_0) {
value = Uint8Array.from([])
} else {
value = bigIntToBytes(val)
}
function (runState) {
// TSTORE
if (runState.interpreter.isStatic()) {
trap(ERROR.STATIC_STATE_CHANGE)
}
const [key, val] = runState.stack.popN(2)

runState.interpreter.transientStorageStore(keyBuf, value)
const keyBuf = setLengthLeft(bigIntToBytes(key), 32)
// NOTE: this should be the shortest representation
let value
if (val === BIGINT_0) {
value = Uint8Array.from([])
} else {
value = bigIntToBytes(val)
}

runState.interpreter.transientStorageStore(keyBuf, value)
},
],
// 0x5e: JUMPSUB (2315) / MCOPY (5656)
// 0x5e: MCOPY (5656)
[
0x5e,
function (runState, common) {
if (common.isActivatedEIP(2315)) {
// JUMPSUB
const dest = runState.stack.pop()

if (dest > runState.interpreter.getCodeSize()) {
trap(ERROR.INVALID_JUMPSUB + ' at ' + describeLocation(runState))
}

const destNum = Number(dest)

if (!jumpSubIsValid(runState, destNum)) {
trap(ERROR.INVALID_JUMPSUB + ' at ' + describeLocation(runState))
}

runState.returnStack.push(BigInt(runState.programCounter))
runState.programCounter = destNum + 1
} else if (common.isActivatedEIP(5656)) {
// MCOPY
const [dst, src, length] = runState.stack.popN(3)
const data = runState.memory.read(Number(src), Number(length), true)
runState.memory.write(Number(dst), Number(length), data)
}
function (runState) {
const [dst, src, length] = runState.stack.popN(3)
const data = runState.memory.read(Number(src), Number(length), true)
runState.memory.write(Number(dst), Number(length), data)
},
],
// 0x5f: PUSH0
Expand Down
7 changes: 0 additions & 7 deletions packages/evm/src/opcodes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ export function jumpIsValid(runState: RunState, dest: number): boolean {
return runState.validJumps[dest] === 1
}

/**
* Checks if a jumpsub is valid given a destination (defined as a 2 in the validJumps array)
*/
export function jumpSubIsValid(runState: RunState, dest: number): boolean {
return runState.validJumps[dest] === 2
}

/**
* Returns an overflow-safe slice of an array. It right-pads
* the data with zeros to `length`.
Expand Down
1 change: 0 additions & 1 deletion packages/evm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export interface EVMOpts {
*
* - [EIP-1153](https://eips.ethereum.org/EIPS/eip-1153) - Transient storage opcodes (Cancun)
* - [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) - Fee market change for ETH 1.0 chain
* - [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315) - Simple subroutines for the EVM (`outdated`)
* - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - BLS precompiles (removed in v4.0.0, see latest v3 release)
* - [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565) - ModExp gas cost
* - [EIP-2718](https://eips.ethereum.org/EIPS/eip-2565) - Transaction Types
Expand Down
19 changes: 0 additions & 19 deletions packages/evm/test/opcodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { EVM } from '../src/index.js'
describe('EVM -> getActiveOpcodes()', () => {
const DIFFICULTY_PREVRANDAO = 0x44
const CHAINID = 0x46 //istanbul opcode
const BEGINSUB = 0x5c // EIP-2315 opcode

it('should not expose opcodes from a follow-up HF (istanbul -> petersburg)', async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg })
Expand Down Expand Up @@ -54,24 +53,6 @@ describe('EVM -> getActiveOpcodes()', () => {
)
})

it('should expose opcodes when EIP is active', async () => {
let common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul, eips: [2315] })
let evm = await EVM.create({ common })
assert.equal(
evm.getActiveOpcodes().get(BEGINSUB)!.name,
'BEGINSUB',
'EIP-2315 opcode BEGINSUB exposed (EIP-2315 activated)'
)

common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
evm = await EVM.create({ common })
assert.equal(
evm.getActiveOpcodes().get(BEGINSUB),
undefined,
'EIP-2315 opcode BEGINSUB not exposed (EIP-2315 not activated)'
)
})

it('should update opcodes on a hardfork change', async () => {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const evm = await EVM.create({ common })
Expand Down
Loading
Loading