From 94d02e6490a68a86e6576c5ba501e1fe78be2f08 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Fri, 12 Jul 2024 20:22:40 +0200 Subject: [PATCH] Fix Prague test runner (#3498) * prague: swap 3074 for 7702 eip * vm: requests: ensure system address nonce does not get updated * vm: state runner: fix some 7702 tests * vm: state: fix all 7702 state tests --- packages/common/src/hardforks.ts | 2 +- packages/vm/src/requests.ts | 14 ++++++++++---- packages/vm/test/util.ts | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/common/src/hardforks.ts b/packages/common/src/hardforks.ts index 0a3c927c78..b053ccffc6 100644 --- a/packages/common/src/hardforks.ts +++ b/packages/common/src/hardforks.ts @@ -841,7 +841,7 @@ export const hardforks: HardforksDict = { 'Next feature hardfork after cancun, internally used for pectra testing/implementation (incomplete/experimental)', url: 'https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/prague.md', status: Status.Draft, - eips: [2537, 2935, 3074, 6110, 7002, 7251, 7685], + eips: [2537, 2935, 6110, 7002, 7251, 7685, 7702], }, osaka: { name: 'osaka', diff --git a/packages/vm/src/requests.ts b/packages/vm/src/requests.ts index def8143248..eca12f47a7 100644 --- a/packages/vm/src/requests.ts +++ b/packages/vm/src/requests.ts @@ -78,7 +78,7 @@ const accumulateEIP7002Requests = async ( const systemAddressBytes = bigIntToAddressBytes(vm.common.param('vm', 'systemAddress')) const systemAddress = Address.fromString(bytesToHex(systemAddressBytes)) - const addrIsEmpty = (await vm.stateManager.getAccount(systemAddress)) === undefined + const originalAccount = await vm.stateManager.getAccount(systemAddress) const results = await vm.evm.runCall({ caller: systemAddress, @@ -98,8 +98,11 @@ const accumulateEIP7002Requests = async ( } } - if (addrIsEmpty) { + if (originalAccount === undefined) { await vm.stateManager.deleteAccount(systemAddress) + } else { + // Restore the original account (the `runCall` updates the nonce) + await vm.stateManager.putAccount(systemAddress, originalAccount) } } @@ -125,7 +128,7 @@ const accumulateEIP7251Requests = async ( const systemAddressBytes = bigIntToAddressBytes(vm.common.param('vm', 'systemAddress')) const systemAddress = Address.fromString(bytesToHex(systemAddressBytes)) - const addrIsEmpty = (await vm.stateManager.getAccount(systemAddress)) === undefined + const originalAccount = await vm.stateManager.getAccount(systemAddress) const results = await vm.evm.runCall({ caller: systemAddress, @@ -147,8 +150,11 @@ const accumulateEIP7251Requests = async ( } } - if (addrIsEmpty) { + if (originalAccount === undefined) { await vm.stateManager.deleteAccount(systemAddress) + } else { + // Restore the original account (the `runCall` updates the nonce) + await vm.stateManager.putAccount(systemAddress, originalAccount) } } diff --git a/packages/vm/test/util.ts b/packages/vm/test/util.ts index c77739d7f3..187af17d19 100644 --- a/packages/vm/test/util.ts +++ b/packages/vm/test/util.ts @@ -4,6 +4,7 @@ import { RLP } from '@ethereumjs/rlp' import { AccessListEIP2930Transaction, BlobEIP4844Transaction, + EOACodeEIP7702Transaction, FeeMarketEIP1559Transaction, LegacyTransaction, } from '@ethereumjs/tx' @@ -18,6 +19,7 @@ import { isHexString, setLengthLeft, toBytes, + unpadBytes, } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' @@ -116,12 +118,24 @@ export function makeTx( txData: any, opts?: TxOptions ): + | EOACodeEIP7702Transaction | BlobEIP4844Transaction | FeeMarketEIP1559Transaction | AccessListEIP2930Transaction | LegacyTransaction { let tx - if (txData.blobVersionedHashes !== undefined) { + if (txData.authorizationList !== undefined) { + // Convert `v` keys to `yParity` + for (const signature of txData.authorizationList) { + if (signature.v !== undefined) { + signature.yParity = bytesToHex(unpadBytes(hexToBytes(signature.v))) + } + if (signature.nonce !== undefined && signature.nonce[0] === '0x00') { + signature.nonce[0] = '0x' + } + } + tx = EOACodeEIP7702Transaction.fromTxData(txData, opts) + } else if (txData.blobVersionedHashes !== undefined) { tx = BlobEIP4844Transaction.fromTxData(txData, opts) } else if (txData.maxFeePerGas !== undefined) { tx = FeeMarketEIP1559Transaction.fromTxData(txData, opts)