Skip to content

Commit 4ed3482

Browse files
EVM: Update EIP-7702: devnet-6 readiness (#3839)
* EVM: Update EIP-7702: devnet-6 readiness * vm: fix tests * vm: update pectra system addresses * vm/client: update tests
1 parent 9240bd8 commit 4ed3482

File tree

6 files changed

+38
-79
lines changed

6 files changed

+38
-79
lines changed

packages/client/test/rpc/engine/newPayloadV4.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const [blockData] = beaconData
1212

1313
const parentBeaconBlockRoot = '0x42942949c4ed512cd85c2cb54ca88591338cbb0564d3a2bea7961a639ef29d64'
1414
const validForkChoiceState = {
15-
headBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
16-
safeBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
17-
finalizedBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
15+
headBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
16+
safeBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
17+
finalizedBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
1818
}
1919
const validPayloadAttributes = {
2020
timestamp: '0x64ba84fd',
@@ -35,20 +35,20 @@ const electraGenesisContracts = {
3535
// sender corresponding to the priv key 0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355
3636
'0x610adc49ecd66cbf176a8247ebd59096c031bd9f': { balance: '0x6d6172697573766477000000' },
3737
// eip 2925 contract
38-
'0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc': {
38+
'0x0000F90827F1C53A10CB7A02335B175320002935': {
3939
balance: '0',
4040
nonce: '1',
4141
code: '0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500',
4242
},
4343
// consolidation requests contract
44-
'0x00431f263ce400f4455c2dcf564e53007ca4bbbb': {
44+
'0x0000BBDDC7CE488642FB579F8B00F3A590007251': {
4545
nonce: '0x01',
4646
balance: '0x00',
4747
code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd',
4848
storage: {},
4949
},
5050
// withdrawals request contract
51-
'0x0c15f14308530b7cdb8460094bbb9cc28b9aaaaa': {
51+
'0x00000961EF480EB55E80D19AD83579A64C007002': {
5252
nonce: '0x01',
5353
balance: '0x00',
5454
code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd',
@@ -158,9 +158,9 @@ describe(`${method}: call with executionPayloadV4`, () => {
158158
withdrawals: [],
159159
blobGasUsed: '0x0',
160160
excessBlobGas: '0x0',
161-
parentHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
162-
stateRoot: '0xebe157ea5c3dc6fb5970f67b76266903282aee9772030f06c112348f32037fd9',
163-
blockHash: '0x725c21032b68ae7d2f143581d0196cfbfd14dbc45c14eaeab15443831de489b7',
161+
parentHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
162+
stateRoot: '0x0fc3b4ec20ec28087d2784e973634e12818998dce76ecfb27ea34c65e058e39a',
163+
blockHash: '0x81442acca0855f07575f7d80ba5f1830e3e4192d8dc278f224f7582d59357821',
164164
}
165165

166166
const oldMethods = ['engine_newPayloadV1', 'engine_newPayloadV2', 'engine_newPayloadV3']

packages/evm/src/opcodes/functions.ts

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import {
2323
bytesToHex,
2424
bytesToInt,
2525
concatBytes,
26-
equalsBytes,
27-
hexToBytes,
2826
setLengthLeft,
2927
} from '@ethereumjs/util'
3028
import { keccak256 } from 'ethereum-cryptography/keccak.js'
@@ -33,7 +31,6 @@ import { EOFContainer, EOFContainerMode } from '../eof/container.js'
3331
import { EOFError } from '../eof/errors.js'
3432
import { EOFBYTES, EOFHASH, isEOF } from '../eof/util.js'
3533
import { ERROR } from '../exceptions.js'
36-
import { DELEGATION_7702_FLAG } from '../types.js'
3734

3835
import {
3936
createAddressFromStackBigInt,
@@ -61,44 +58,6 @@ export interface AsyncOpHandler {
6158

6259
export type OpHandler = SyncOpHandler | AsyncOpHandler
6360

64-
// The PR https://github.com/ethereum/EIPs/pull/8969 has two definitions of the
65-
// designator: the original (0xef0100) and the designator added in the changes (0xef01)
66-
const eip7702Designator = hexToBytes('0xef01')
67-
const eip7702HashBigInt = bytesToBigInt(keccak256(eip7702Designator))
68-
69-
function getEIP7702DelegatedAddress(code: Uint8Array) {
70-
if (equalsBytes(code.slice(0, 3), DELEGATION_7702_FLAG)) {
71-
return new Address(code.slice(3, 24))
72-
}
73-
}
74-
75-
/**
76-
* This method performs checks to transform the code which the EVM observes regarding EIP-7702.
77-
* If the code is 7702-delegated code, it will retrieve the code of the designated address
78-
* in case of an executable operation (`isReadOperation` == false), or the 7702 designator
79-
* code in case of a read operation
80-
* @param runState
81-
* @param code
82-
* @param isReadOperation Boolean to determine if the target code is meant to be read or executed (default: `false`)
83-
* @returns
84-
*/
85-
async function eip7702CodeCheck(
86-
runState: RunState,
87-
code: Uint8Array,
88-
isReadOperation: boolean = false,
89-
) {
90-
const address = getEIP7702DelegatedAddress(code)
91-
if (address !== undefined) {
92-
if (isReadOperation) {
93-
return eip7702Designator
94-
} else {
95-
return runState.stateManager.getCode(address)
96-
}
97-
}
98-
99-
return code
100-
}
101-
10261
// the opcode functions
10362
export const handlers: Map<number, OpHandler> = new Map([
10463
// 0x00: STOP
@@ -551,17 +510,15 @@ export const handlers: Map<number, OpHandler> = new Map([
551510
// 0x3b: EXTCODESIZE
552511
[
553512
0x3b,
554-
async function (runState, common) {
513+
async function (runState) {
555514
const addressBigInt = runState.stack.pop()
556515
const address = createAddressFromStackBigInt(addressBigInt)
557516
// EOF check
558-
let code = await runState.stateManager.getCode(address)
517+
const code = await runState.stateManager.getCode(address)
559518
if (isEOF(code)) {
560519
// In legacy code, the target code is treated as to be "EOFBYTES" code
561520
runState.stack.push(BigInt(EOFBYTES.length))
562521
return
563-
} else if (common.isActivatedEIP(7702)) {
564-
code = await eip7702CodeCheck(runState, code, true)
565522
}
566523

567524
const size = BigInt(code.length)
@@ -572,7 +529,7 @@ export const handlers: Map<number, OpHandler> = new Map([
572529
// 0x3c: EXTCODECOPY
573530
[
574531
0x3c,
575-
async function (runState, common) {
532+
async function (runState) {
576533
const [addressBigInt, memOffset, codeOffset, dataLength] = runState.stack.popN(4)
577534

578535
if (dataLength !== BIGINT_0) {
@@ -582,8 +539,6 @@ export const handlers: Map<number, OpHandler> = new Map([
582539
if (isEOF(code)) {
583540
// In legacy code, the target code is treated as to be "EOFBYTES" code
584541
code = EOFBYTES
585-
} else if (common.isActivatedEIP(7702)) {
586-
code = await eip7702CodeCheck(runState, code, true)
587542
}
588543

589544
const data = getDataSlice(code, codeOffset, dataLength)
@@ -596,7 +551,7 @@ export const handlers: Map<number, OpHandler> = new Map([
596551
// 0x3f: EXTCODEHASH
597552
[
598553
0x3f,
599-
async function (runState, common) {
554+
async function (runState) {
600555
const addressBigInt = runState.stack.pop()
601556
const address = createAddressFromStackBigInt(addressBigInt)
602557

@@ -607,13 +562,6 @@ export const handlers: Map<number, OpHandler> = new Map([
607562
// Therefore, push the hash of EOFBYTES to the stack
608563
runState.stack.push(bytesToBigInt(EOFHASH))
609564
return
610-
} else if (common.isActivatedEIP(7702)) {
611-
const possibleDelegatedAddress = getEIP7702DelegatedAddress(code)
612-
if (possibleDelegatedAddress !== undefined) {
613-
// The account is delegated by an EIP-7702 tx. Push the EIP-7702 designator hash to the stack
614-
runState.stack.push(eip7702HashBigInt)
615-
return
616-
}
617565
}
618566

619567
const account = await runState.stateManager.getAccount(address)

packages/vm/src/params.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const paramsVM: ParamsDict = {
4040
*/
4141
2935: {
4242
// config
43-
historyStorageAddress: '0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC', // The address where the historical blockhashes are stored
43+
historyStorageAddress: '0x0000F90827F1C53A10CB7A02335B175320002935', // The address where the historical blockhashes are stored
4444
historyServeWindow: 8191, // The amount of blocks to be served by the historical blockhash contract
4545
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address
4646
},
@@ -84,7 +84,7 @@ export const paramsVM: ParamsDict = {
8484
// config
8585
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the withdrawal requests predeploy address
8686
// See: https://github.com/ethereum/EIPs/pull/8934/files
87-
withdrawalRequestPredeployAddress: '0x0c15F14308530b7CDB8460094BbB9cC28b9AaaAA', // Address of the validator excess address
87+
withdrawalRequestPredeployAddress: '0x00000961EF480EB55E80D19AD83579A64C007002', // Address of the validator excess address
8888
},
8989

9090
/**
@@ -94,7 +94,7 @@ export const paramsVM: ParamsDict = {
9494
// config
9595
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the consolidation requests predeploy address
9696
// See: https://github.com/ethereum/EIPs/pull/8934/files
97-
consolidationRequestPredeployAddress: '0x00431F263cE400f4455c2dCf564e53007Ca4bbBb', // Address of the consolidations contract
97+
consolidationRequestPredeployAddress: '0x0000BBDDC7CE488642FB579F8B00F3A590007251', // Address of the consolidations contract
9898
},
9999
/**
100100
. * Shard Blob Transactions

packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
hexToBytes,
1717
privateToAddress,
1818
setLengthLeft,
19+
toChecksumAddress,
1920
} from '@ethereumjs/util'
2021
import { assert, describe, it } from 'vitest'
2122

@@ -97,14 +98,14 @@ const deploymentConfigs = [
9798
// contract code
9899
'0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500',
99100
// deployment tx input
100-
'0x60648060095f395ff33373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500',
101+
'0x60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500',
101102
// v r s
102-
['0x1b', '0x539', '0x1b9b6eb1f0'],
103+
['0x1b', '0x539', '0xaa12693182426612186309f02cfe8a80a0000'],
103104
// sender, hash, deployed address
104105
[
105-
'0xe473f7e92ba2490e9fcbbe8bb9c3be3adbb74efc',
106-
'0x3c769a03d6e2212f1d26ab59ba797dce0900df29ffd23c1dd391fd6b217973ad',
107-
'0x0aae40965e6800cd9b1f4b05ff21581047e3f91e',
106+
'0x3462413Af4609098e1E27A490f554f260213D685',
107+
'0x67139a552b0d3fffc30c0fa7d0c20d42144138c8fe07fc5691f09c1cce632e15',
108+
'0x0000F90827F1C53a10cb7A02335B175320002935',
108109
],
109110
],
110111
]
@@ -158,14 +159,18 @@ describe('EIP 2935: historical block hashes', () => {
158159

159160
const deployTx = createLegacyTx(deployContractTxData)
160161
const txSender = createAddressFromPublicKey(deployTx.getSenderPublicKey()).toString()
161-
assert.equal(txSender, deploymentSender, 'tx sender should match')
162+
assert.equal(toChecksumAddress(txSender), deploymentSender, 'tx sender should match')
162163

163164
const txHash = bytesToHex(deployTx.hash())
164165
assert.equal(txHash, deploymentTxHash, 'tx hash should match')
165166

166167
// tx sender is a random address with likely no tx history
167168
const txToAddress = bytesToHex(generateAddress(hexToBytes(txSender), bigIntToBytes(BIGINT_0)))
168-
assert.equal(txToAddress, deployedToAddress, 'deployment address should match')
169+
assert.equal(
170+
toChecksumAddress(txToAddress),
171+
deployedToAddress,
172+
'deployment address should match',
173+
)
169174
})
170175

171176
it('should save genesis block hash to the history block hash contract', async () => {

packages/vm/test/api/EIPs/eip-7002.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const deploymentTxData = {
3636
),
3737
v: BigInt('0x1b'),
3838
r: BigInt('0x539'),
39-
s: BigInt('0xeb793ed1dcd82833'),
39+
s: BigInt('0x5feeb084551e4e03a3581e269bc2ea2f8d0008'),
4040
}
4141

4242
const deploymentTx = createLegacyTx(deploymentTxData)

packages/vm/test/api/EIPs/eip-7702.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ describe('test EIP-7702 opcodes', () => {
242242
const randomCode = hexToBytes('0x010203040506')
243243
const randomCodeAddress = createAddressFromString('0x' + 'aa'.repeat(20))
244244

245+
const delegatedCode = concatBytes(
246+
eip7702Designator,
247+
hexToBytes('0x00'),
248+
randomCodeAddress.bytes,
249+
)
250+
245251
const tests: {
246252
code: PrefixedHexString
247253
expectedStorage: Uint8Array
@@ -251,21 +257,21 @@ describe('test EIP-7702 opcodes', () => {
251257
{
252258
// PUSH20 <defaultAuthAddr> EXTCODESIZE PUSH0 SSTORE STOP
253259
code: `0x73${defaultAuthAddr.toString().slice(2)}3b5f5500`,
254-
expectedStorage: bigIntToUnpaddedBytes(BigInt(eip7702Designator.length)),
260+
expectedStorage: bigIntToUnpaddedBytes(BigInt(delegatedCode.length)),
255261
name: 'EXTCODESIZE',
256262
},
257263
// EXTCODEHASH
258264
{
259265
// PUSH20 <defaultAuthAddr> EXTCODEHASH PUSH0 SSTORE STOP
260266
code: `0x73${defaultAuthAddr.toString().slice(2)}3f5f5500`,
261-
expectedStorage: keccak256(eip7702Designator),
267+
expectedStorage: keccak256(delegatedCode),
262268
name: 'EXTCODEHASH',
263269
},
264270
// EXTCODECOPY
265271
{
266272
// PUSH1 32 PUSH0 PUSH0 PUSH20 <defaultAuthAddr> EXTCODEHASH PUSH0 MLOAD PUSH0 SSTORE STOP
267273
code: `0x60205f5f73${defaultAuthAddr.toString().slice(2)}3c5f515f5500`,
268-
expectedStorage: setLengthRight(eip7702Designator, 32),
274+
expectedStorage: setLengthRight(delegatedCode, 32),
269275
name: 'EXTCODECOPY',
270276
},
271277
]

0 commit comments

Comments
 (0)