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

WIP: implement EIP-5806 #3312

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/client/bin/cli.ts
Expand Up @@ -654,6 +654,9 @@ async function setupDevnet(prefundAddress: Address) {
istanbulBlock: 0,
berlinBlock: 0,
londonBlock: 0,
mergeForkBlock: 0,
shanghaiTime: 0,
cancunTime: 0,
...consensusConfig,
},
nonce: '0x0',
Expand All @@ -674,7 +677,11 @@ async function setupDevnet(prefundAddress: Address) {
extraData,
alloc: { [addr]: { balance: '0x10000000000000000000' } },
}
const common = Common.fromGethGenesis(chainData, { chain: 'devnet', hardfork: Hardfork.London })
const common = Common.fromGethGenesis(chainData, {
chain: 'devnet',
hardfork: Hardfork.Cancun,
eips: [5806], // TODO: remove
})
const customGenesisState = parseGethGenesisState(chainData)
return { common, customGenesisState }
}
Expand Down
7 changes: 6 additions & 1 deletion packages/client/src/net/protocol/ethprotocol.ts
Expand Up @@ -6,6 +6,7 @@
TransactionFactory,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isDelegateEIP5806Tx,
isFeeMarketEIP1559Tx,
isLegacyTx,
} from '@ethereumjs/tx'
Expand Down Expand Up @@ -262,7 +263,11 @@
// serialize txs as per type
if (isBlobEIP4844Tx(tx)) {
serializedTxs.push(tx.serializeNetworkWrapper())
} else if (isFeeMarketEIP1559Tx(tx) || isAccessListEIP2930Tx(tx)) {
} else if (
isAccessListEIP2930Tx(tx) ||
isFeeMarketEIP1559Tx(tx) ||
isDelegateEIP5806Tx(tx)
) {

Check warning on line 270 in packages/client/src/net/protocol/ethprotocol.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/net/protocol/ethprotocol.ts#L266-L270

Added lines #L266 - L270 were not covered by tests
serializedTxs.push(tx.serialize())
} else if (isLegacyTx(tx)) {
serializedTxs.push(tx.raw())
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/service/txpool.ts
Expand Up @@ -3,6 +3,7 @@ import {
Capability,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isDelegateEIP5806Tx,
isFeeMarketEIP1559Tx,
isLegacyTx,
} from '@ethereumjs/tx'
Expand Down Expand Up @@ -710,7 +711,7 @@ export class TxPool {
}
}

if (isFeeMarketEIP1559Tx(tx) || isBlobEIP4844Tx(tx)) {
if (isFeeMarketEIP1559Tx(tx) || isBlobEIP4844Tx(tx) || isDelegateEIP5806Tx(tx)) {
return {
maxFee: tx.maxFeePerGas,
tip: tx.maxPriorityFeePerGas,
Expand Down
7 changes: 7 additions & 0 deletions packages/common/src/eips.ts
Expand Up @@ -482,6 +482,13 @@ export const EIPs: EIPsDict = {
},
},
},
5806: {
comment: 'Deleate transaction',
url: 'https://eips.ethereum.org/EIPS/eip-5806',
status: Status.Draft,
minimumHardfork: Hardfork.Cancun, // TODO: Hardfork.Prague
requiredEIPs: [2718, 2930],
},
6780: {
comment: 'SELFDESTRUCT only in same transaction',
url: 'https://eips.ethereum.org/EIPS/eip-6780',
Expand Down
7 changes: 6 additions & 1 deletion packages/evm/src/evm.ts
Expand Up @@ -86,6 +86,7 @@ export class EVM implements EVMInterface {
protected _tx?: {
gasPrice: bigint
origin: Address
isEIP5806: boolean
}
protected _block?: Block

Expand Down Expand Up @@ -183,7 +184,7 @@ 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,
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 5806, 6780, 6800, 7516,
]

for (const eip of this.common.eips()) {
Expand Down Expand Up @@ -750,6 +751,7 @@ export class EVM implements EVMInterface {
blobVersionedHashes: message.blobVersionedHashes ?? [],
accessWitness: message.accessWitness,
createdAddresses: message.createdAddresses,
isEIP5806: this._tx!.isEIP5806,
}

const interpreter = new Interpreter(
Expand Down Expand Up @@ -825,6 +827,7 @@ export class EVM implements EVMInterface {
this._tx = {
gasPrice: opts.gasPrice ?? BIGINT_0,
origin: opts.origin ?? opts.caller ?? Address.zero(),
isEIP5806: opts.isEIP5806 ?? false,
}
const caller = opts.caller ?? Address.zero()

Expand All @@ -848,6 +851,7 @@ export class EVM implements EVMInterface {
value,
data: opts.data,
code: opts.code,
codeAddress: opts.codeAddress,
depth: opts.depth,
isCompiled: opts.isCompiled,
isStatic: opts.isStatic,
Expand Down Expand Up @@ -963,6 +967,7 @@ export class EVM implements EVMInterface {
this._tx = {
gasPrice: opts.gasPrice ?? BIGINT_0,
origin: opts.origin ?? opts.caller ?? Address.zero(),
isEIP5806: false,
}

const message = new Message({
Expand Down
1 change: 1 addition & 0 deletions packages/evm/src/exceptions.ts
Expand Up @@ -9,6 +9,7 @@ export enum ERROR {
OUT_OF_RANGE = 'value out of range',
REVERT = 'revert',
STATIC_STATE_CHANGE = 'static state change',
EIP5806_WRITE = 'write attempt in EIP-5806 transaction',
INTERNAL_ERROR = 'internal error',
CREATE_COLLISION = 'create collision',
STOP = 'stop',
Expand Down
1 change: 1 addition & 0 deletions packages/evm/src/interpreter.ts
Expand Up @@ -71,6 +71,7 @@ export interface Env {
createdAddresses?: Set<string>
accessWitness?: AccessWitness
chargeCodeAccesses?: boolean
isEIP5806?: boolean
}

export interface RunState {
Expand Down
28 changes: 28 additions & 0 deletions packages/evm/src/opcodes/functions.ts
Expand Up @@ -757,6 +757,13 @@
[
0x55,
async function (runState) {
if (
runState.interpreter._env.isEIP5806 === true &&
runState.interpreter._env.origin.equals(runState.interpreter._env.address)

Check warning on line 762 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L762

Added line #L762 was not covered by tests
) {
trap(ERROR.EIP5806_WRITE)
}

Check warning on line 765 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L764-L765

Added lines #L764 - L765 were not covered by tests

const [key, val] = runState.stack.popN(2)

const keyBuf = setLengthLeft(bigIntToBytes(key), 32)
Expand Down Expand Up @@ -994,6 +1001,13 @@
[
0xf0,
async function (runState, common) {
if (
runState.interpreter._env.isEIP5806 === true &&
runState.interpreter._env.origin.equals(runState.interpreter._env.address)

Check warning on line 1006 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1006

Added line #L1006 was not covered by tests
) {
trap(ERROR.EIP5806_WRITE)
}

Check warning on line 1009 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1008-L1009

Added lines #L1008 - L1009 were not covered by tests

const [value, offset, length] = runState.stack.popN(3)

if (
Expand All @@ -1020,6 +1034,13 @@
[
0xf5,
async function (runState, common) {
if (
runState.interpreter._env.isEIP5806 === true &&
runState.interpreter._env.origin.equals(runState.interpreter._env.address)

Check warning on line 1039 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1039

Added line #L1039 was not covered by tests
) {
trap(ERROR.EIP5806_WRITE)
}

Check warning on line 1042 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1041-L1042

Added lines #L1041 - L1042 were not covered by tests

if (runState.interpreter.isStatic()) {
trap(ERROR.STATIC_STATE_CHANGE)
}
Expand Down Expand Up @@ -1273,6 +1294,13 @@
[
0xff,
async function (runState) {
if (
runState.interpreter._env.isEIP5806 === true &&
runState.interpreter._env.origin.equals(runState.interpreter._env.address)

Check warning on line 1299 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1299

Added line #L1299 was not covered by tests
) {
trap(ERROR.EIP5806_WRITE)
}

Check warning on line 1302 in packages/evm/src/opcodes/functions.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/opcodes/functions.ts#L1301-L1302

Added lines #L1301 - L1302 were not covered by tests

const selfdestructToAddressBigInt = runState.stack.pop()
const selfdestructToAddress = new Address(addresstoBytes(selfdestructToAddressBigInt))
return runState.interpreter.selfDestruct(selfdestructToAddress)
Expand Down
4 changes: 4 additions & 0 deletions packages/evm/src/types.ts
Expand Up @@ -125,6 +125,10 @@ export interface EVMRunCallOpts extends EVMRunOpts {
message?: Message

accessWitness?: AccessWitness

codeAddress?: Address

isEIP5806?: boolean
}

interface NewContractEvent {
Expand Down