Skip to content
18 changes: 9 additions & 9 deletions packages/client/test/rpc/engine/newPayloadV4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const [blockData] = beaconData

const parentBeaconBlockRoot = '0x42942949c4ed512cd85c2cb54ca88591338cbb0564d3a2bea7961a639ef29d64'
const validForkChoiceState = {
headBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
safeBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
finalizedBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
headBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
safeBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
finalizedBlockHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
}
const validPayloadAttributes = {
timestamp: '0x64ba84fd',
Expand All @@ -35,20 +35,20 @@ const electraGenesisContracts = {
// sender corresponding to the priv key 0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355
'0x610adc49ecd66cbf176a8247ebd59096c031bd9f': { balance: '0x6d6172697573766477000000' },
// eip 2925 contract
'0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc': {
'0x0000F90827F1C53A10CB7A02335B175320002935': {
balance: '0',
nonce: '1',
code: '0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500',
},
// consolidation requests contract
'0x00431f263ce400f4455c2dcf564e53007ca4bbbb': {
'0x0000BBDDC7CE488642FB579F8B00F3A590007251': {
nonce: '0x01',
balance: '0x00',
code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd',
storage: {},
},
// withdrawals request contract
'0x0c15f14308530b7cdb8460094bbb9cc28b9aaaaa': {
'0x00000961EF480EB55E80D19AD83579A64C007002': {
nonce: '0x01',
balance: '0x00',
code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd',
Expand Down Expand Up @@ -158,9 +158,9 @@ describe(`${method}: call with executionPayloadV4`, () => {
withdrawals: [],
blobGasUsed: '0x0',
excessBlobGas: '0x0',
parentHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc',
stateRoot: '0xebe157ea5c3dc6fb5970f67b76266903282aee9772030f06c112348f32037fd9',
blockHash: '0x725c21032b68ae7d2f143581d0196cfbfd14dbc45c14eaeab15443831de489b7',
parentHash: '0xa85d6596cb45ab895555e76857c45440a6cf74b1895fb6f560dacf45b7db782b',
stateRoot: '0x0fc3b4ec20ec28087d2784e973634e12818998dce76ecfb27ea34c65e058e39a',
blockHash: '0x81442acca0855f07575f7d80ba5f1830e3e4192d8dc278f224f7582d59357821',
}

const oldMethods = ['engine_newPayloadV1', 'engine_newPayloadV2', 'engine_newPayloadV3']
Expand Down
60 changes: 4 additions & 56 deletions packages/evm/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
bytesToHex,
bytesToInt,
concatBytes,
equalsBytes,
hexToBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
Expand All @@ -33,7 +31,6 @@
import { EOFError } from '../eof/errors.js'
import { EOFBYTES, EOFHASH, isEOF } from '../eof/util.js'
import { ERROR } from '../exceptions.js'
import { DELEGATION_7702_FLAG } from '../types.js'

import {
createAddressFromStackBigInt,
Expand Down Expand Up @@ -61,44 +58,6 @@

export type OpHandler = SyncOpHandler | AsyncOpHandler

// The PR https://github.com/ethereum/EIPs/pull/8969 has two definitions of the
// designator: the original (0xef0100) and the designator added in the changes (0xef01)
const eip7702Designator = hexToBytes('0xef01')
const eip7702HashBigInt = bytesToBigInt(keccak256(eip7702Designator))

function getEIP7702DelegatedAddress(code: Uint8Array) {
if (equalsBytes(code.slice(0, 3), DELEGATION_7702_FLAG)) {
return new Address(code.slice(3, 24))
}
}

/**
* This method performs checks to transform the code which the EVM observes regarding EIP-7702.
* If the code is 7702-delegated code, it will retrieve the code of the designated address
* in case of an executable operation (`isReadOperation` == false), or the 7702 designator
* code in case of a read operation
* @param runState
* @param code
* @param isReadOperation Boolean to determine if the target code is meant to be read or executed (default: `false`)
* @returns
*/
async function eip7702CodeCheck(
runState: RunState,
code: Uint8Array,
isReadOperation: boolean = false,
) {
const address = getEIP7702DelegatedAddress(code)
if (address !== undefined) {
if (isReadOperation) {
return eip7702Designator
} else {
return runState.stateManager.getCode(address)
}
}

return code
}

// the opcode functions
export const handlers: Map<number, OpHandler> = new Map([
// 0x00: STOP
Expand Down Expand Up @@ -551,17 +510,15 @@
// 0x3b: EXTCODESIZE
[
0x3b,
async function (runState, common) {
async function (runState) {
const addressBigInt = runState.stack.pop()
const address = createAddressFromStackBigInt(addressBigInt)
// EOF check
let code = await runState.stateManager.getCode(address)
const code = await runState.stateManager.getCode(address)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L517 was not covered by tests
if (isEOF(code)) {
// In legacy code, the target code is treated as to be "EOFBYTES" code
runState.stack.push(BigInt(EOFBYTES.length))
return
} else if (common.isActivatedEIP(7702)) {
code = await eip7702CodeCheck(runState, code, true)
}

const size = BigInt(code.length)
Expand All @@ -572,7 +529,7 @@
// 0x3c: EXTCODECOPY
[
0x3c,
async function (runState, common) {
async function (runState) {
const [addressBigInt, memOffset, codeOffset, dataLength] = runState.stack.popN(4)

if (dataLength !== BIGINT_0) {
Expand All @@ -582,8 +539,6 @@
if (isEOF(code)) {
// In legacy code, the target code is treated as to be "EOFBYTES" code
code = EOFBYTES
} else if (common.isActivatedEIP(7702)) {
code = await eip7702CodeCheck(runState, code, true)
}

const data = getDataSlice(code, codeOffset, dataLength)
Expand All @@ -596,7 +551,7 @@
// 0x3f: EXTCODEHASH
[
0x3f,
async function (runState, common) {
async function (runState) {
const addressBigInt = runState.stack.pop()
const address = createAddressFromStackBigInt(addressBigInt)

Expand All @@ -607,13 +562,6 @@
// Therefore, push the hash of EOFBYTES to the stack
runState.stack.push(bytesToBigInt(EOFHASH))
return
} else if (common.isActivatedEIP(7702)) {
const possibleDelegatedAddress = getEIP7702DelegatedAddress(code)
if (possibleDelegatedAddress !== undefined) {
// The account is delegated by an EIP-7702 tx. Push the EIP-7702 designator hash to the stack
runState.stack.push(eip7702HashBigInt)
return
}
}

const account = await runState.stateManager.getAccount(address)
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const paramsVM: ParamsDict = {
*/
2935: {
// config
historyStorageAddress: '0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC', // The address where the historical blockhashes are stored
historyStorageAddress: '0x0000F90827F1C53A10CB7A02335B175320002935', // The address where the historical blockhashes are stored
historyServeWindow: 8191, // The amount of blocks to be served by the historical blockhash contract
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address
},
Expand Down Expand Up @@ -84,7 +84,7 @@ export const paramsVM: ParamsDict = {
// config
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the withdrawal requests predeploy address
// See: https://github.com/ethereum/EIPs/pull/8934/files
withdrawalRequestPredeployAddress: '0x0c15F14308530b7CDB8460094BbB9cC28b9AaaAA', // Address of the validator excess address
withdrawalRequestPredeployAddress: '0x00000961EF480EB55E80D19AD83579A64C007002', // Address of the validator excess address
},

/**
Expand All @@ -94,7 +94,7 @@ export const paramsVM: ParamsDict = {
// config
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the consolidation requests predeploy address
// See: https://github.com/ethereum/EIPs/pull/8934/files
consolidationRequestPredeployAddress: '0x00431F263cE400f4455c2dCf564e53007Ca4bbBb', // Address of the consolidations contract
consolidationRequestPredeployAddress: '0x0000BBDDC7CE488642FB579F8B00F3A590007251', // Address of the consolidations contract
},
/**
. * Shard Blob Transactions
Expand Down
19 changes: 12 additions & 7 deletions packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
hexToBytes,
privateToAddress,
setLengthLeft,
toChecksumAddress,
} from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

Expand Down Expand Up @@ -97,14 +98,14 @@ const deploymentConfigs = [
// contract code
'0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500',
// deployment tx input
'0x60648060095f395ff33373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500',
'0x60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500',
// v r s
['0x1b', '0x539', '0x1b9b6eb1f0'],
['0x1b', '0x539', '0xaa12693182426612186309f02cfe8a80a0000'],
// sender, hash, deployed address
[
'0xe473f7e92ba2490e9fcbbe8bb9c3be3adbb74efc',
'0x3c769a03d6e2212f1d26ab59ba797dce0900df29ffd23c1dd391fd6b217973ad',
'0x0aae40965e6800cd9b1f4b05ff21581047e3f91e',
'0x3462413Af4609098e1E27A490f554f260213D685',
'0x67139a552b0d3fffc30c0fa7d0c20d42144138c8fe07fc5691f09c1cce632e15',
'0x0000F90827F1C53a10cb7A02335B175320002935',
],
],
]
Expand Down Expand Up @@ -158,14 +159,18 @@ describe('EIP 2935: historical block hashes', () => {

const deployTx = createLegacyTx(deployContractTxData)
const txSender = createAddressFromPublicKey(deployTx.getSenderPublicKey()).toString()
assert.equal(txSender, deploymentSender, 'tx sender should match')
assert.equal(toChecksumAddress(txSender), deploymentSender, 'tx sender should match')

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

// tx sender is a random address with likely no tx history
const txToAddress = bytesToHex(generateAddress(hexToBytes(txSender), bigIntToBytes(BIGINT_0)))
assert.equal(txToAddress, deployedToAddress, 'deployment address should match')
assert.equal(
toChecksumAddress(txToAddress),
deployedToAddress,
'deployment address should match',
)
})

it('should save genesis block hash to the history block hash contract', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/api/EIPs/eip-7002.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const deploymentTxData = {
),
v: BigInt('0x1b'),
r: BigInt('0x539'),
s: BigInt('0xeb793ed1dcd82833'),
s: BigInt('0x5feeb084551e4e03a3581e269bc2ea2f8d0008'),
}

const deploymentTx = createLegacyTx(deploymentTxData)
Expand Down
12 changes: 9 additions & 3 deletions packages/vm/test/api/EIPs/eip-7702.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ describe('test EIP-7702 opcodes', () => {
const randomCode = hexToBytes('0x010203040506')
const randomCodeAddress = createAddressFromString('0x' + 'aa'.repeat(20))

const delegatedCode = concatBytes(
eip7702Designator,
hexToBytes('0x00'),
randomCodeAddress.bytes,
)

const tests: {
code: PrefixedHexString
expectedStorage: Uint8Array
Expand All @@ -251,21 +257,21 @@ describe('test EIP-7702 opcodes', () => {
{
// PUSH20 <defaultAuthAddr> EXTCODESIZE PUSH0 SSTORE STOP
code: `0x73${defaultAuthAddr.toString().slice(2)}3b5f5500`,
expectedStorage: bigIntToUnpaddedBytes(BigInt(eip7702Designator.length)),
expectedStorage: bigIntToUnpaddedBytes(BigInt(delegatedCode.length)),
name: 'EXTCODESIZE',
},
// EXTCODEHASH
{
// PUSH20 <defaultAuthAddr> EXTCODEHASH PUSH0 SSTORE STOP
code: `0x73${defaultAuthAddr.toString().slice(2)}3f5f5500`,
expectedStorage: keccak256(eip7702Designator),
expectedStorage: keccak256(delegatedCode),
name: 'EXTCODEHASH',
},
// EXTCODECOPY
{
// PUSH1 32 PUSH0 PUSH0 PUSH20 <defaultAuthAddr> EXTCODEHASH PUSH0 MLOAD PUSH0 SSTORE STOP
code: `0x60205f5f73${defaultAuthAddr.toString().slice(2)}3c5f515f5500`,
expectedStorage: setLengthRight(eip7702Designator, 32),
expectedStorage: setLengthRight(delegatedCode, 32),
name: 'EXTCODECOPY',
},
]
Expand Down
Loading