diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index 9d5e9df6ea..aacb03038e 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -11,9 +11,9 @@ import { equalsBytes, fetchFromProvider, getProvider, - hexStringToBytes, intToPrefixedHexString, isHexPrefixed, + prefixedHexStringToBytes, } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak.js' @@ -302,7 +302,7 @@ export class Block { const txs = [] for (const [index, serializedTx] of transactions.entries()) { try { - const tx = TransactionFactory.fromSerializedData(hexStringToBytes(serializedTx), { + const tx = TransactionFactory.fromSerializedData(prefixedHexStringToBytes(serializedTx), { common: options?.common, }) txs.push(tx) @@ -330,7 +330,7 @@ export class Block { // we are not setting setHardfork as common is already set to the correct hf const block = Block.fromBlockData({ header, transactions: txs, withdrawals }, options) // Verify blockHash matches payload - if (!equalsBytes(block.hash(), hexStringToBytes(payload.blockHash))) { + if (!equalsBytes(block.hash(), prefixedHexStringToBytes(payload.blockHash))) { const validationError = `Invalid blockHash, expected: ${ payload.blockHash }, received: ${bytesToPrefixedHexString(block.hash())}` diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index 655299383a..3bc6b7d7af 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -6,6 +6,7 @@ import type { BigIntLike, BytesLike, JsonRpcWithdrawal, + PrefixedHexString, WithdrawalBytes, WithdrawalData, } from '@ethereumjs/util' @@ -190,29 +191,31 @@ export interface JsonRpcBlock { excessDataGas?: string // If EIP-4844 is enabled for this block, returns the excess data gas for the block } +// Note: all these strings are 0x-prefixed export type WithdrawalV1 = { - index: string // Quantity, 8 Bytes - validatorIndex: string // Quantity, 8 bytes - address: string // DATA, 20 bytes - amount: string // Quantity, 32 bytes + index: PrefixedHexString // Quantity, 8 Bytes + validatorIndex: PrefixedHexString // Quantity, 8 bytes + address: PrefixedHexString // DATA, 20 bytes + amount: PrefixedHexString // Quantity, 32 bytes } +// Note: all these strings are 0x-prefixed export type ExecutionPayload = { - parentHash: string // DATA, 32 Bytes - feeRecipient: string // DATA, 20 Bytes - stateRoot: string // DATA, 32 Bytes - receiptsRoot: string // DATA, 32 bytes - logsBloom: string // DATA, 256 Bytes - prevRandao: string // DATA, 32 Bytes - blockNumber: string // QUANTITY, 64 Bits - gasLimit: string // QUANTITY, 64 Bits - gasUsed: string // QUANTITY, 64 Bits - timestamp: string // QUANTITY, 64 Bits - extraData: string // DATA, 0 to 32 Bytes - baseFeePerGas: string // QUANTITY, 256 Bits - blockHash: string // DATA, 32 Bytes - transactions: string[] // Array of DATA - Array of transaction rlp strings, + parentHash: PrefixedHexString // DATA, 32 Bytes + feeRecipient: PrefixedHexString // DATA, 20 Bytes + stateRoot: PrefixedHexString // DATA, 32 Bytes + receiptsRoot: PrefixedHexString // DATA, 32 bytes + logsBloom: PrefixedHexString // DATA, 256 Bytes + prevRandao: PrefixedHexString // DATA, 32 Bytes + blockNumber: PrefixedHexString // QUANTITY, 64 Bits + gasLimit: PrefixedHexString // QUANTITY, 64 Bits + gasUsed: PrefixedHexString // QUANTITY, 64 Bits + timestamp: PrefixedHexString // QUANTITY, 64 Bits + extraData: PrefixedHexString // DATA, 0 to 32 Bytes + baseFeePerGas: PrefixedHexString // QUANTITY, 256 Bits + blockHash: PrefixedHexString // DATA, 32 Bytes + transactions: PrefixedHexString[] // Array of DATA - Array of transaction rlp strings, withdrawals?: WithdrawalV1[] // Array of withdrawal objects - dataGasUsed?: string // QUANTITY, 64 Bits - excessDataGas?: string // QUANTITY, 64 Bits + dataGasUsed?: PrefixedHexString // QUANTITY, 64 Bits + excessDataGas?: PrefixedHexString // QUANTITY, 64 Bits } diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index 24168405e4..90fe651bf8 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -1,6 +1,6 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' -import { bytesToHex, equalsBytes, hexStringToBytes, toBytes, zeros } from '@ethereumjs/util' +import { bytesToHex, equalsBytes, prefixedHexStringToBytes, toBytes, zeros } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' // explicitly import util, needed for karma-typescript bundling // eslint-disable-next-line @typescript-eslint/no-unused-vars, simple-import-sort/imports @@ -227,8 +227,8 @@ describe('[Block]: block functions', () => { it('should test genesis hashes (mainnet default)', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const rlp = hexStringToBytes(testDataGenesis.test.genesis_rlp_hex) - const hash = hexStringToBytes(testDataGenesis.test.genesis_hash) + const rlp = prefixedHexStringToBytes('0x' + testDataGenesis.test.genesis_rlp_hex) + const hash = prefixedHexStringToBytes('0x' + testDataGenesis.test.genesis_hash) const block = Block.fromRLPSerializedBlock(rlp, { common }) assert.ok(equalsBytes(block.hash(), hash), 'genesis hash match') }) @@ -272,7 +272,7 @@ describe('[Block]: block functions', () => { it('DAO hardfork', () => { const blockData = RLP.decode(testDataPreLondon2.blocks[0].rlp) as NestedUint8Array // Set block number from test block to mainnet DAO fork block 1920000 - blockData[0][8] = hexStringToBytes('1D4C00') + blockData[0][8] = prefixedHexStringToBytes('0x1D4C00') const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Dao }) assert.throws( @@ -285,7 +285,7 @@ describe('[Block]: block functions', () => { ) // eslint-disable-line // Set extraData to dao-hard-fork - blockData[0][12] = hexStringToBytes('64616f2d686172642d666f726b') + blockData[0][12] = prefixedHexStringToBytes('0x64616f2d686172642d666f726b') assert.doesNotThrow(function () { Block.fromValuesArray(blockData as BlockBytes, { common }) diff --git a/packages/block/test/clique.spec.ts b/packages/block/test/clique.spec.ts index 78c37751be..ec019113f3 100644 --- a/packages/block/test/clique.spec.ts +++ b/packages/block/test/clique.spec.ts @@ -1,5 +1,5 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { Address, hexStringToBytes } from '@ethereumjs/util' +import { Address, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { BlockHeader } from '../src/header.js' @@ -78,12 +78,12 @@ describe('[Header]: Clique PoA Functionality', () => { } const A: Signer = { - address: new Address(hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f')), - privateKey: hexStringToBytes( - '64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + address: new Address(prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')), + privateKey: prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' ), - publicKey: hexStringToBytes( - '40b2ebdf4b53206d2d3d3d59e7e2f13b1ea68305aec71d5d24cefe7f24ecae886d241f9267f04702d7f693655eb7b4aa23f30dcd0c3c5f2b970aad7c8a828195' + publicKey: prefixedHexStringToBytes( + '0x40b2ebdf4b53206d2d3d3d59e7e2f13b1ea68305aec71d5d24cefe7f24ecae886d241f9267f04702d7f693655eb7b4aa23f30dcd0c3c5f2b970aad7c8a828195' ), } diff --git a/packages/block/test/eip1559block.spec.ts b/packages/block/test/eip1559block.spec.ts index 48d364748f..9b9aafaee3 100644 --- a/packages/block/test/eip1559block.spec.ts +++ b/packages/block/test/eip1559block.spec.ts @@ -1,6 +1,6 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Block } from '../src/block.js' @@ -168,7 +168,7 @@ describe('EIP1559 tests', () => { parentHash: block1.hash(), timestamp: BigInt(2), gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block - baseFeePerGas: hexStringToBytes('342770c0'), + baseFeePerGas: prefixedHexStringToBytes('0x342770c0'), }, }, { @@ -280,7 +280,7 @@ describe('EIP1559 tests', () => { parentHash: block1.hash(), timestamp: BigInt(2), gasLimit: parentGasLimit + parentGasLimit / BigInt(1024) - BigInt(1), - baseFeePerGas: hexStringToBytes('342770c0'), + baseFeePerGas: prefixedHexStringToBytes('0x342770c0'), }, { calcDifficultyFromHeader: block1.header, @@ -296,7 +296,7 @@ describe('EIP1559 tests', () => { parentHash: block1.hash(), timestamp: BigInt(2), gasLimit: parentGasLimit - parentGasLimit / BigInt(1024) + BigInt(1), - baseFeePerGas: hexStringToBytes('342770c0'), + baseFeePerGas: prefixedHexStringToBytes('0x342770c0'), }, { calcDifficultyFromHeader: block1.header, @@ -339,7 +339,7 @@ describe('EIP1559 tests', () => { parentHash: block1.hash(), timestamp: BigInt(2), gasLimit: parentGasLimit + parentGasLimit / BigInt(1024), - baseFeePerGas: hexStringToBytes('342770c0'), + baseFeePerGas: prefixedHexStringToBytes('0x342770c0'), }, { calcDifficultyFromHeader: block1.header, @@ -389,7 +389,7 @@ describe('EIP1559 tests', () => { parentHash: block1.hash(), timestamp: BigInt(2), gasLimit: parentGasLimit - parentGasLimit / BigInt(1024), - baseFeePerGas: hexStringToBytes('342770c0'), + baseFeePerGas: prefixedHexStringToBytes('0x342770c0'), }, { calcDifficultyFromHeader: block1.header, @@ -414,7 +414,7 @@ describe('EIP1559 tests', () => { maxPriorityFeePerGas: BigInt(0), }, { common } - ).sign(hexStringToBytes('46'.repeat(32))) + ).sign(prefixedHexStringToBytes('0x' + '46'.repeat(32))) const block = Block.fromBlockData( { header: { diff --git a/packages/block/test/eip4895block.spec.ts b/packages/block/test/eip4895block.spec.ts index 12690b504b..a0975d3efc 100644 --- a/packages/block/test/eip4895block.spec.ts +++ b/packages/block/test/eip4895block.spec.ts @@ -1,6 +1,12 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' -import { Address, KECCAK256_RLP, Withdrawal, hexStringToBytes } from '@ethereumjs/util' +import { + Address, + KECCAK256_RLP, + Withdrawal, + prefixedHexStringToBytes, + zeros, +} from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Block } from '../src/block.js' @@ -31,7 +37,9 @@ common.hardforkBlock = function (hardfork: string | undefined) { describe('EIP4895 tests', () => { it('should correctly generate withdrawalsRoot', async () => { // get withdwalsArray - const gethBlockBytesArray = RLP.decode(hexStringToBytes(gethWithdrawals8BlockRlp)) + const gethBlockBytesArray = RLP.decode( + prefixedHexStringToBytes('0x' + gethWithdrawals8BlockRlp) + ) const withdrawals = (gethBlockBytesArray[3] as WithdrawalBytes[]).map((wa) => Withdrawal.fromValuesArray(wa) ) @@ -50,7 +58,7 @@ describe('EIP4895 tests', () => { () => { BlockHeader.fromHeaderData( { - withdrawalsRoot: hexStringToBytes('00'.repeat(32)), + withdrawalsRoot: zeros(32), }, { common: earlyCommon, @@ -72,7 +80,7 @@ describe('EIP4895 tests', () => { assert.doesNotThrow(() => { BlockHeader.fromHeaderData( { - withdrawalsRoot: hexStringToBytes('00'.repeat(32)), + withdrawalsRoot: zeros(32), }, { common, @@ -109,7 +117,7 @@ describe('EIP4895 tests', () => { Block.fromBlockData( { header: { - withdrawalsRoot: hexStringToBytes('00'.repeat(32)), + withdrawalsRoot: zeros(32), }, withdrawals: [], }, @@ -121,7 +129,7 @@ describe('EIP4895 tests', () => { const block = Block.fromBlockData( { header: { - withdrawalsRoot: hexStringToBytes('00'.repeat(32)), + withdrawalsRoot: zeros(32), }, withdrawals: [], }, @@ -153,15 +161,15 @@ describe('EIP4895 tests', () => { const withdrawal = { index: BigInt(0), validatorIndex: BigInt(0), - address: new Address(hexStringToBytes('20'.repeat(20))), + address: new Address(prefixedHexStringToBytes('0x' + '20'.repeat(20))), amount: BigInt(1000), } const validBlockWithWithdrawal = Block.fromBlockData( { header: { - withdrawalsRoot: hexStringToBytes( - '897ca49edcb278aecab2688bcc2b7b7ee43524cc489672534fee332a172f1718' + withdrawalsRoot: prefixedHexStringToBytes( + '0x897ca49edcb278aecab2688bcc2b7b7ee43524cc489672534fee332a172f1718' ), }, withdrawals: [withdrawal], @@ -178,15 +186,15 @@ describe('EIP4895 tests', () => { const withdrawal2 = { index: BigInt(1), validatorIndex: BigInt(11), - address: new Address(hexStringToBytes('30'.repeat(20))), + address: new Address(prefixedHexStringToBytes('0x' + '30'.repeat(20))), amount: BigInt(2000), } const validBlockWithWithdrawal2 = Block.fromBlockData( { header: { - withdrawalsRoot: hexStringToBytes( - '3b514862c42008079d461392e29d5b6775dd5ed370a6c4441ccb8ab742bf2436' + withdrawalsRoot: prefixedHexStringToBytes( + '0x3b514862c42008079d461392e29d5b6775dd5ed370a6c4441ccb8ab742bf2436' ), }, withdrawals: [withdrawal, withdrawal2], diff --git a/packages/block/test/from-rpc.spec.ts b/packages/block/test/from-rpc.spec.ts index fb3dd30d75..a8660d3c72 100644 --- a/packages/block/test/from-rpc.spec.ts +++ b/packages/block/test/from-rpc.spec.ts @@ -1,5 +1,5 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { bytesToPrefixedHexString, hexStringToBytes, randomBytes } from '@ethereumjs/util' +import { bytesToPrefixedHexString, prefixedHexStringToBytes, randomBytes } from '@ethereumjs/util' import { bytesToHex, equalsBytes } from 'ethereum-cryptography/utils' import { assert, describe, it } from 'vitest' @@ -32,7 +32,7 @@ describe('[fromRPC]: block #2924874', () => { it('should create a block header with the correct hash', () => { const block = blockHeaderFromRpc(blockData, { common }) - const hash = hexStringToBytes(blockData.hash) + const hash = prefixedHexStringToBytes(blockData.hash) assert.ok(equalsBytes(block.hash(), hash)) }) }) diff --git a/packages/block/test/header.spec.ts b/packages/block/test/header.spec.ts index 41a3d8a585..b07b3a8d2f 100644 --- a/packages/block/test/header.spec.ts +++ b/packages/block/test/header.spec.ts @@ -7,7 +7,7 @@ import { bytesToHex, concatBytes, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, toBytes, zeros, } from '@ethereumjs/util' @@ -113,8 +113,8 @@ describe('[Block]: Header functions', () => { ) header = BlockHeader.fromRLPSerializedHeader( - hexStringToBytes( - 'f90214a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000850400000000808213888080a011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82faa00000000000000000000000000000000000000000000000000000000000000000880000000000000042' + prefixedHexStringToBytes( + '0xf90214a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000850400000000808213888080a011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82faa00000000000000000000000000000000000000000000000000000000000000000880000000000000042' ), { common, setHardfork: false } ) diff --git a/packages/block/test/mergeBlock.spec.ts b/packages/block/test/mergeBlock.spec.ts index 67f7418e3a..d8885bb131 100644 --- a/packages/block/test/mergeBlock.spec.ts +++ b/packages/block/test/mergeBlock.spec.ts @@ -4,7 +4,7 @@ import { KECCAK256_RLP, KECCAK256_RLP_ARRAY, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, zeros, } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -48,7 +48,7 @@ describe('[Header]: Casper PoS / The Merge Functionality', () => { // Building a header with random values for constants try { const headerData = { - uncleHash: hexStringToBytes('123abc'), + uncleHash: prefixedHexStringToBytes('0x123abc'), } BlockHeader.fromHeaderData(headerData, { common }) assert.fail('should throw') diff --git a/packages/client/bin/cli.ts b/packages/client/bin/cli.ts index e09f4e711c..b8cc849679 100755 --- a/packages/client/bin/cli.ts +++ b/packages/client/bin/cli.ts @@ -8,9 +8,9 @@ import { Address, bytesToHex, bytesToPrefixedHexString, - hexStringToBytes, initKZG, parseGethGenesisState, + prefixedHexStringToBytes, randomBytes, short, toBytes, @@ -625,7 +625,7 @@ async function inputAccounts() { } } else { const acc = readFileSync(path.resolve(args.unlock!), 'utf-8').replace(/(\r\n|\n|\r)/gm, '') - const privKey = hexStringToBytes(acc) + const privKey = prefixedHexStringToBytes('0x' + acc) // See docs: acc has to be non-zero prefixed in the file const derivedAddress = Address.fromPrivateKey(privKey) accounts.push([derivedAddress, privKey]) } diff --git a/packages/client/bin/startRpc.ts b/packages/client/bin/startRpc.ts index 535a60640f..718ab28c11 100644 --- a/packages/client/bin/startRpc.ts +++ b/packages/client/bin/startRpc.ts @@ -1,4 +1,4 @@ -import { hexStringToBytes, randomBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes, randomBytes } from '@ethereumjs/util' import { bytesToHex } from 'ethereum-cryptography/utils' import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs' @@ -54,7 +54,7 @@ function parseJwtSecret(config: Config, jwtFilePath?: string): Uint8Array { if (jwtSecretHex === undefined || jwtSecretHex.length !== 64) { throw Error('Need a valid 256 bit hex encoded secret') } - jwtSecret = hexStringToBytes(jwtSecretHex) + jwtSecret = prefixedHexStringToBytes('0x' + jwtSecretHex) } else { const folderExists = existsSync(config.datadir) if (!folderExists) { diff --git a/packages/client/devnets/4844-interop/tools/txGenerator.ts b/packages/client/devnets/4844-interop/tools/txGenerator.ts index bf2e054a24..630de4ce3e 100644 --- a/packages/client/devnets/4844-interop/tools/txGenerator.ts +++ b/packages/client/devnets/4844-interop/tools/txGenerator.ts @@ -8,7 +8,7 @@ import { commitmentsToVersionedHashes, getBlobs, bytesToPrefixedHexString, - hexStringToBytes, + prefixedHexStringToBytes, } from '@ethereumjs/util' import kzg from 'c-kzg' @@ -19,7 +19,7 @@ import { Client } from 'jayson/promise' const clientPort = parseInt(process.argv[2]) // EL client port number const input = process.argv[3] // text to generate blob from const genesisJson = require(process.argv[4]) // Genesis parameters -const pkey = hexStringToBytes(process.argv[5]) // private key of tx sender as unprefixed hex string +const pkey = prefixedHexStringToBytes('0x' + process.argv[5]) // private key of tx sender as unprefixed hex string (unprefixed in args) initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet6.txt') diff --git a/packages/client/libp2pBrowserBuild/net/test/libp2psender.spec.ts b/packages/client/libp2pBrowserBuild/net/test/libp2psender.spec.ts index 8d71c6a4dc..53594789fa 100644 --- a/packages/client/libp2pBrowserBuild/net/test/libp2psender.spec.ts +++ b/packages/client/libp2pBrowserBuild/net/test/libp2psender.spec.ts @@ -1,4 +1,4 @@ -import { bytesToHex, hexStringToBytes } from '@ethereumjs/util' +import { bytesToHex, prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import { Libp2pSender } from '../../../src/net/protocol' @@ -15,7 +15,7 @@ tape('[Libp2pSender]', (t) => { t.equal(bytesToHex(receiver.status.id), '05', 'status getter') t.end() }) - sender.sendStatus({ id: hexStringToBytes('05') }) + sender.sendStatus({ id: prefixedHexStringToBytes('0x05') }) }) t.test('should send/receive message', (t) => { @@ -27,7 +27,7 @@ tape('[Libp2pSender]', (t) => { t.equal(bytesToHex(message.payload), '05', 'message received (payload)') t.end() }) - sender.sendMessage(1, hexStringToBytes('05')) + sender.sendMessage(1, prefixedHexStringToBytes('0x05')) }) t.test('should catch errors', (t) => { diff --git a/packages/client/src/net/peer/rlpxpeer.ts b/packages/client/src/net/peer/rlpxpeer.ts index fb18ea5d5f..74ac6327ca 100644 --- a/packages/client/src/net/peer/rlpxpeer.ts +++ b/packages/client/src/net/peer/rlpxpeer.ts @@ -4,7 +4,7 @@ import { RLPx as Devp2pRLPx, SNAP as Devp2pSNAP, } from '@ethereumjs/devp2p' -import { hexStringToBytes, randomBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes, randomBytes } from '@ethereumjs/util' import { Event } from '../../types' import { RlpxSender } from '../protocol' @@ -111,7 +111,7 @@ export class RlpxPeer extends Peer { common: this.config.chainCommon, }) await this.rlpx.connect({ - id: hexStringToBytes(this.id), + id: prefixedHexStringToBytes('0x' + this.id), address: this.host, tcpPort: this.port, }) diff --git a/packages/client/src/net/protocol/lesprotocol.ts b/packages/client/src/net/protocol/lesprotocol.ts index 8fab76a6d9..08dcbe73a2 100644 --- a/packages/client/src/net/protocol/lesprotocol.ts +++ b/packages/client/src/net/protocol/lesprotocol.ts @@ -3,8 +3,8 @@ import { bigIntToUnpaddedBytes, bytesToBigInt, bytesToInt, - hexStringToBytes, intToBytes, + prefixedHexStringToBytes, } from '@ethereumjs/util' import { Protocol } from './protocol' @@ -190,7 +190,7 @@ export class LesProtocol extends Protocol { const nextFork = this.config.chainCommon.nextHardforkBlockOrTimestamp( this.config.chainCommon.hardfork() ) - const forkID = [hexStringToBytes(forkHash.slice(2)), bigIntToUnpaddedBytes(nextFork ?? 0n)] + const forkID = [prefixedHexStringToBytes(forkHash), bigIntToUnpaddedBytes(nextFork ?? 0n)] return { networkId: bigIntToUnpaddedBytes(this.chain.networkId), diff --git a/packages/client/src/rpc/modules/debug.ts b/packages/client/src/rpc/modules/debug.ts index 680b530617..930423cc9f 100644 --- a/packages/client/src/rpc/modules/debug.ts +++ b/packages/client/src/rpc/modules/debug.ts @@ -1,4 +1,4 @@ -import { bigIntToHex, bytesToPrefixedHexString, hexStringToBytes } from '@ethereumjs/util' +import { bigIntToHex, bytesToPrefixedHexString, prefixedHexStringToBytes } from '@ethereumjs/util' import { INTERNAL_ERROR, INVALID_PARAMS } from '../error-code' import { middleware, validators } from '../validation' @@ -101,7 +101,7 @@ export class Debug { try { const result = await this.service.execution.receiptsManager.getReceiptByTxHash( - hexStringToBytes(txHash) + prefixedHexStringToBytes(txHash) ) if (!result) return null const [_, blockHash, txIndex] = result diff --git a/packages/client/src/rpc/modules/engine.ts b/packages/client/src/rpc/modules/engine.ts index 74620870ea..a2bca8eecd 100644 --- a/packages/client/src/rpc/modules/engine.ts +++ b/packages/client/src/rpc/modules/engine.ts @@ -6,7 +6,7 @@ import { bytesToHex, bytesToPrefixedHexString, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, toBytes, zeros, } from '@ethereumjs/util' @@ -270,7 +270,7 @@ const assembleBlock = async ( } catch (error) { const validationError = `Error assembling block during from payload: ${error}` config.logger.error(validationError) - const latestValidHash = await validHash(hexStringToBytes(payload.parentHash), chain) + const latestValidHash = await validHash(prefixedHexStringToBytes(payload.parentHash), chain) const response = { status: `${error}`.includes('Invalid blockHash') ? Status.INVALID_BLOCK_HASH : Status.INVALID, latestValidHash, @@ -470,7 +470,10 @@ export class Engine { if (!response) { const validationError = `Error assembling block during init` this.config.logger.debug(validationError) - const latestValidHash = await validHash(hexStringToBytes(payload.parentHash), this.chain) + const latestValidHash = await validHash( + prefixedHexStringToBytes(payload.parentHash), + this.chain + ) response = { status: Status.INVALID, latestValidHash, validationError } } return response @@ -498,7 +501,10 @@ export class Engine { for (let vIndex = 0; vIndex < versionedHashes.length; vIndex++) { // if mismatch, record error and break if ( - !equalsBytes(hexStringToBytes(versionedHashes[vIndex]), txVersionedHashes[vIndex]) + !equalsBytes( + prefixedHexStringToBytes(versionedHashes[vIndex]), + txVersionedHashes[vIndex] + ) ) { validationError = `Error verifying versionedHashes: mismatch at index=${vIndex} expected=${short( txVersionedHashes[vIndex] @@ -512,13 +518,13 @@ export class Engine { // if there was a validation error return invalid if (validationError !== null) { this.config.logger.debug(validationError) - const latestValidHash = await validHash(hexStringToBytes(parentHash), this.chain) + const latestValidHash = await validHash(prefixedHexStringToBytes(parentHash), this.chain) const response = { status: Status.INVALID, latestValidHash, validationError } return response } } else if (versionedHashes !== undefined && versionedHashes !== null) { const validationError = `Invalid versionedHashes before EIP-4844 is activated` - const latestValidHash = await validHash(hexStringToBytes(parentHash), this.chain) + const latestValidHash = await validHash(prefixedHexStringToBytes(parentHash), this.chain) const response = { status: Status.INVALID, latestValidHash, validationError } return response } @@ -541,7 +547,7 @@ export class Engine { // is pow block which this client would like to mint and attempt proposing it const optimisticLookup = await this.service.beaconSync?.extendChain(block) - const blockExists = await validBlock(hexStringToBytes(blockHash), this.chain) + const blockExists = await validBlock(prefixedHexStringToBytes(blockHash), this.chain) if (blockExists) { const isBlockExecuted = await this.vm.stateManager.hasStateRoot(blockExists.header.stateRoot) if (isBlockExecuted) { @@ -558,11 +564,11 @@ export class Engine { // get the parent from beacon skeleton or from remoteBlocks cache or from the chain const parent = (await this.service.beaconSync?.skeleton.getBlockByHash( - hexStringToBytes(parentHash), + prefixedHexStringToBytes(parentHash), true )) ?? this.remoteBlocks.get(parentHash.slice(2)) ?? - (await this.chain.getBlock(hexStringToBytes(parentHash))) + (await this.chain.getBlock(prefixedHexStringToBytes(parentHash))) // Validations with parent if (!parent._common.gteHardfork(Hardfork.Paris)) { @@ -584,7 +590,7 @@ export class Engine { block.validateBlobTransactions(parent.header) } catch (error: any) { const validationError = `Invalid 4844 transactions: ${error}` - const latestValidHash = await validHash(hexStringToBytes(parentHash), this.chain) + const latestValidHash = await validHash(prefixedHexStringToBytes(parentHash), this.chain) const response = { status: Status.INVALID, latestValidHash, validationError } return response } @@ -1033,7 +1039,7 @@ export class Engine { * @returns Instance of {@link ExecutionPayloadV1} or an error */ private async getPayload(params: [Bytes8]) { - const payloadId = hexStringToBytes(params[0]) + const payloadId = prefixedHexStringToBytes(params[0]) try { const built = await this.pendingBlock.build(payloadId) if (!built) { @@ -1119,7 +1125,7 @@ export class Engine { message: 'More than 32 execution payload bodies requested', } } - const hashes = params[0].map(hexStringToBytes) + const hashes = params[0].map(prefixedHexStringToBytes) const blocks: (ExecutionPayloadBodyV1 | null)[] = [] for (const hash of hashes) { try { diff --git a/packages/client/src/rpc/modules/eth.ts b/packages/client/src/rpc/modules/eth.ts index dc7d3a2862..f56479b178 100644 --- a/packages/client/src/rpc/modules/eth.ts +++ b/packages/client/src/rpc/modules/eth.ts @@ -4,8 +4,8 @@ import { TypeOutput, bigIntToHex, bytesToPrefixedHexString, - hexStringToBytes, intToPrefixedHexString, + prefixedHexStringToBytes, setLengthLeft, toType, utf8ToBytes, @@ -421,7 +421,7 @@ export class Eth { gasLimit: toType(gasLimit, TypeOutput.BigInt), gasPrice: toType(gasPrice, TypeOutput.BigInt), value: toType(value, TypeOutput.BigInt), - data: data !== undefined ? hexStringToBytes(data) : undefined, + data: data !== undefined ? prefixedHexStringToBytes(data) : undefined, } const { execResult } = await vm.evm.runCall(runCallOpts) return bytesToPrefixedHexString(execResult.returnValue) @@ -550,7 +550,7 @@ export class Eth { const [blockHash, includeTransactions] = params try { - const block = await this._chain.getBlock(hexStringToBytes(blockHash)) + const block = await this._chain.getBlock(prefixedHexStringToBytes(blockHash)) return await jsonRpcBlock(block, this._chain, includeTransactions) } catch (error) { throw { @@ -579,7 +579,7 @@ export class Eth { async getBlockTransactionCountByHash(params: [string]) { const [blockHash] = params try { - const block = await this._chain.getBlock(hexStringToBytes(blockHash)) + const block = await this._chain.getBlock(prefixedHexStringToBytes(blockHash)) return intToPrefixedHexString(block.transactions.length) } catch (error) { throw { @@ -641,7 +641,7 @@ export class Eth { if (account === undefined) { return EMPTY_SLOT } - const key = setLengthLeft(hexStringToBytes(keyHex), 32) + const key = setLengthLeft(prefixedHexStringToBytes(keyHex), 32) const storage = await vm.stateManager.getContractStorage(address, key) return storage !== null && storage !== undefined ? bytesToPrefixedHexString(setLengthLeft(Uint8Array.from(storage) as Uint8Array, 32)) @@ -658,7 +658,7 @@ export class Eth { try { const [blockHash, txIndexHex] = params const txIndex = parseInt(txIndexHex, 16) - const block = await this._chain.getBlock(hexStringToBytes(blockHash)) + const block = await this._chain.getBlock(prefixedHexStringToBytes(blockHash)) if (block.transactions.length <= txIndex) { return null } @@ -683,7 +683,7 @@ export class Eth { try { if (!this.receiptsManager) throw new Error('missing receiptsManager') - const result = await this.receiptsManager.getReceiptByTxHash(hexStringToBytes(txHash)) + const result = await this.receiptsManager.getReceiptByTxHash(prefixedHexStringToBytes(txHash)) if (!result) return null const [_receipt, blockHash, txIndex] = result const block = await this._chain.getBlock(blockHash) @@ -766,7 +766,7 @@ export class Eth { try { if (!this.receiptsManager) throw new Error('missing receiptsManager') - const result = await this.receiptsManager.getReceiptByTxHash(hexStringToBytes(txHash)) + const result = await this.receiptsManager.getReceiptByTxHash(prefixedHexStringToBytes(txHash)) if (!result) return null const [receipt, blockHash, txIndex, logIndex] = result const block = await this._chain.getBlock(blockHash) @@ -829,7 +829,7 @@ export class Eth { let from: Block, to: Block if (blockHash !== undefined) { try { - from = to = await this._chain.getBlock(hexStringToBytes(blockHash)) + from = to = await this._chain.getBlock(prefixedHexStringToBytes(blockHash)) } catch (error: any) { throw { code: INVALID_PARAMS, @@ -880,17 +880,17 @@ export class Eth { if (t === null) { return null } else if (Array.isArray(t)) { - return t.map((x) => hexStringToBytes(x)) + return t.map((x) => prefixedHexStringToBytes(x)) } else { - return hexStringToBytes(t) + return prefixedHexStringToBytes(t) } }) let addrs if (address !== undefined) { if (Array.isArray(address)) { - addrs = address.map((a) => hexStringToBytes(a)) + addrs = address.map((a) => prefixedHexStringToBytes(a)) } else { - addrs = [hexStringToBytes(address)] + addrs = [prefixedHexStringToBytes(address)] } } const logs = await this.receiptsManager.getLogs(from, to, addrs, formattedTopics) @@ -937,7 +937,7 @@ export class Eth { let tx try { - const txBuf = hexStringToBytes(serializedTx) + const txBuf = prefixedHexStringToBytes(serializedTx) if (txBuf[0] === 0x03) { // Blob Transactions sent over RPC are expected to be in Network Wrapper format tx = BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txBuf, { common }) @@ -1022,7 +1022,7 @@ export class Eth { await vm.stateManager.setStateRoot(block.header.stateRoot) const address = Address.fromString(addressHex) - const slots = slotsHex.map((slotHex) => setLengthLeft(hexStringToBytes(slotHex), 32)) + const slots = slotsHex.map((slotHex) => setLengthLeft(prefixedHexStringToBytes(slotHex), 32)) const proof = await vm.stateManager.getProof!(address, slots) return proof } diff --git a/packages/client/src/service/txpool.ts b/packages/client/src/service/txpool.ts index 61a93b1301..e7966dd4cf 100644 --- a/packages/client/src/service/txpool.ts +++ b/packages/client/src/service/txpool.ts @@ -6,7 +6,13 @@ import { isFeeMarketEIP1559Tx, isLegacyTx, } from '@ethereumjs/tx' -import { Account, Address, bytesToHex, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { + Account, + Address, + bytesToHex, + equalsBytes, + prefixedHexStringToBytes, +} from '@ethereumjs/util' import Heap from 'qheap' import type { Config } from '../config' @@ -708,7 +714,9 @@ export class TxPool { .map((obj) => obj.tx) .sort((a, b) => Number(a.nonce - b.nonce)) // Check if the account nonce matches the lowest known tx nonce - let account = await vm.stateManager.getAccount(new Address(hexStringToBytes(address))) + let account = await vm.stateManager.getAccount( + new Address(prefixedHexStringToBytes('0x' + address)) + ) if (account === undefined) { account = new Account() } diff --git a/packages/client/src/util/debug.ts b/packages/client/src/util/debug.ts index 22df19180a..457061e842 100644 --- a/packages/client/src/util/debug.ts +++ b/packages/client/src/util/debug.ts @@ -37,7 +37,7 @@ const main = async () => { const common = new Common({ chain: '${execution.config.execCommon.chainName()}', hardfork: '${ execution.hardfork }' }) - const block = Block.fromRLPSerializedBlock(hexStringToBytes('${bytesToHex( + const block = Block.fromRLPSerializedBlock(prefixedHexStringToBytes('0x${bytesToHex( block.serialize() )}'), { common }) @@ -45,7 +45,7 @@ const main = async () => { const trie = new Trie({ db: stateDB, useKeyHashing: true }) const stateManager = new DefaultStateManager({ trie, common }) // Ensure we run on the right root - stateManager.setStateRoot(hexStringToBytes('${bytesToHex( + stateManager.setStateRoot(prefixedHexStringToBytes('0x${bytesToHex( await execution.vm.stateManager.getStateRoot() )}')) diff --git a/packages/client/src/util/parse.ts b/packages/client/src/util/parse.ts index 3402674716..b3428873eb 100644 --- a/packages/client/src/util/parse.ts +++ b/packages/client/src/util/parse.ts @@ -1,4 +1,4 @@ -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { Multiaddr, multiaddr } from 'multiaddr' import { URL } from 'url' @@ -88,5 +88,5 @@ export function parseTransports(transports: string[]) { * @param input hexadecimal string or Uint8Array */ export function parseKey(input: string | Uint8Array): Uint8Array { - return input instanceof Uint8Array ? input : hexStringToBytes(input) + return input instanceof Uint8Array ? input : prefixedHexStringToBytes('0x' + input) } diff --git a/packages/client/test/integration/fullethereumservice.spec.ts b/packages/client/test/integration/fullethereumservice.spec.ts index 5295420e74..c2c42109b3 100644 --- a/packages/client/test/integration/fullethereumservice.spec.ts +++ b/packages/client/test/integration/fullethereumservice.spec.ts @@ -3,7 +3,13 @@ import { Blockchain } from '@ethereumjs/blockchain' import { Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' -import { Account, bytesToHex, equalsBytes, hexStringToBytes, toBytes } from '@ethereumjs/util' +import { + Account, + bytesToHex, + equalsBytes, + prefixedHexStringToBytes, + toBytes, +} from '@ethereumjs/util' import tape from 'tape' import td from 'testdouble' @@ -51,8 +57,8 @@ tape('[Integration:FullEthereumService]', async (t) => { const [server, service] = await setup() const peer = await server.accept('peer0') const [reqId1, headers] = await peer.eth!.getBlockHeaders({ block: BigInt(1), max: 2 }) - const hash = hexStringToBytes( - 'a321d27cd2743617c1c1b0d7ecb607dd14febcdfca8f01b79c3f0249505ea069' + const hash = prefixedHexStringToBytes( + '0xa321d27cd2743617c1c1b0d7ecb607dd14febcdfca8f01b79c3f0249505ea069' ) t.equal(reqId1, BigInt(1), 'handled GetBlockHeaders') t.ok(equalsBytes(headers![1].hash(), hash), 'handled GetBlockHeaders') diff --git a/packages/client/test/integration/merge.spec.ts b/packages/client/test/integration/merge.spec.ts index b210f97e4d..7f35904f37 100644 --- a/packages/client/test/integration/merge.spec.ts +++ b/packages/client/test/integration/merge.spec.ts @@ -7,7 +7,7 @@ import { ConsensusType, Hardfork, } from '@ethereumjs/common' -import { Address, hexStringToBytes } from '@ethereumjs/util' +import { Address, prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import { Chain } from '../../src/blockchain' @@ -67,8 +67,10 @@ tape('[Integration:Merge]', async (t) => { ) const accounts: [Address, Uint8Array][] = [ [ - new Address(hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f')), - hexStringToBytes('64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993'), + new Address(prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')), + prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + ), ], ] async function minerSetup(common: Common): Promise<[MockServer, FullEthereumService]> { diff --git a/packages/client/test/integration/miner.spec.ts b/packages/client/test/integration/miner.spec.ts index 5e9104ac1c..29eb4b4b3a 100644 --- a/packages/client/test/integration/miner.spec.ts +++ b/packages/client/test/integration/miner.spec.ts @@ -6,7 +6,7 @@ import { ConsensusType, Hardfork, } from '@ethereumjs/common' -import { Address, hexStringToBytes } from '@ethereumjs/util' +import { Address, prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import { Chain } from '../../src/blockchain' @@ -44,8 +44,10 @@ tape('[Integration:Miner]', async (t) => { ) const accounts: [Address, Uint8Array][] = [ [ - new Address(hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f')), - hexStringToBytes('64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993'), + new Address(prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')), + prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + ), ], ] async function minerSetup(): Promise<[MockServer, FullEthereumService]> { diff --git a/packages/client/test/miner/miner.spec.ts b/packages/client/test/miner/miner.spec.ts index 23e783272b..3b5a22b6c0 100644 --- a/packages/client/test/miner/miner.spec.ts +++ b/packages/client/test/miner/miner.spec.ts @@ -2,7 +2,7 @@ import { Block, BlockHeader } from '@ethereumjs/block' import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { FeeMarketEIP1559Transaction, LegacyTransaction } from '@ethereumjs/tx' -import { Address, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { Address, equalsBytes, prefixedHexStringToBytes } from '@ethereumjs/util' import { AbstractLevel } from 'abstract-level' import { keccak256 } from 'ethereum-cryptography/keccak' import tape from 'tape' @@ -20,13 +20,17 @@ import type { CliqueConsensus } from '@ethereumjs/blockchain' import type { VM } from '@ethereumjs/vm' const A = { - address: new Address(hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f')), - privateKey: hexStringToBytes('64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993'), + address: new Address(prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')), + privateKey: prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + ), } const B = { - address: new Address(hexStringToBytes('6f62d8382bf2587361db73ceca28be91b2acb6df')), - privateKey: hexStringToBytes('2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6'), + address: new Address(prefixedHexStringToBytes('0x6f62d8382bf2587361db73ceca28be91b2acb6df')), + privateKey: prefixedHexStringToBytes( + '0x2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6' + ), } const setBalance = async (vm: VM, address: Address, balance: bigint) => { diff --git a/packages/client/test/miner/pendingBlock.spec.ts b/packages/client/test/miner/pendingBlock.spec.ts index 48db6f7ace..66a0345d32 100644 --- a/packages/client/test/miner/pendingBlock.spec.ts +++ b/packages/client/test/miner/pendingBlock.spec.ts @@ -16,8 +16,8 @@ import { commitmentsToVersionedHashes, equalsBytes, getBlobs, - hexStringToBytes, initKZG, + prefixedHexStringToBytes, randomBytes, } from '@ethereumjs/util' import { VM } from '@ethereumjs/vm' @@ -35,13 +35,17 @@ import { mockBlockchain } from '../rpc/mockBlockchain' import type { TypedTransaction } from '@ethereumjs/tx' const A = { - address: new Address(hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f')), - privateKey: hexStringToBytes('64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993'), + address: new Address(prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')), + privateKey: prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + ), } const B = { - address: new Address(hexStringToBytes('6f62d8382bf2587361db73ceca28be91b2acb6df')), - privateKey: hexStringToBytes('2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6'), + address: new Address(prefixedHexStringToBytes('0x6f62d8382bf2587361db73ceca28be91b2acb6df')), + privateKey: prefixedHexStringToBytes( + '0x2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6' + ), } const setBalance = async (vm: VM, address: Address, balance: bigint) => { diff --git a/packages/client/test/net/protocol/ethprotocol.spec.ts b/packages/client/test/net/protocol/ethprotocol.spec.ts index 20be45041b..584104742e 100644 --- a/packages/client/test/net/protocol/ethprotocol.spec.ts +++ b/packages/client/test/net/protocol/ethprotocol.spec.ts @@ -1,7 +1,12 @@ import { Block } from '@ethereumjs/block' import { Common, Hardfork } from '@ethereumjs/common' import { FeeMarketEIP1559Transaction, TransactionFactory, TransactionType } from '@ethereumjs/tx' -import { bigIntToBytes, bytesToBigInt, hexStringToBytes, randomBytes } from '@ethereumjs/util' +import { + bigIntToBytes, + bytesToBigInt, + prefixedHexStringToBytes, + randomBytes, +} from '@ethereumjs/util' import tape from 'tape' import { Chain } from '../../../src/blockchain/chain' @@ -54,17 +59,17 @@ tape('[EthProtocol]', (t) => { t.deepEquals( p.encodeStatus(), { - networkId: hexStringToBytes('01'), - td: hexStringToBytes('64'), + networkId: prefixedHexStringToBytes('0x01'), + td: prefixedHexStringToBytes('0x64'), bestHash: '0xaa', genesisHash: '0xbb', - latestBlock: hexStringToBytes('0a'), + latestBlock: prefixedHexStringToBytes('0x0a'), }, 'encode status' ) const status = p.decodeStatus({ networkId: [0x01], - td: hexStringToBytes('64'), + td: prefixedHexStringToBytes('0x64'), bestHash: '0xaa', genesisHash: '0xbb', }) @@ -189,11 +194,11 @@ tape('[EthProtocol]', (t) => { }) t.equal(bytesToBigInt(res[0]), BigInt(1), 'correctly encoded reqId') const expectedSerializedReceipts = [ - hexStringToBytes( - '02f9016d0164b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f866f864940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a001010101010101010101010101010101010101010101010101010101010101018a00000000000000000000' + prefixedHexStringToBytes( + '0x02f9016d0164b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f866f864940000000000000000000000000000000000000000f842a00000000000000000000000000000000000000000000000000000000000000000a001010101010101010101010101010101010101010101010101010101010101018a00000000000000000000' ), - hexStringToBytes( - 'f9016f808203e8b9010001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101f866f864940101010101010101010101010101010101010101f842a00101010101010101010101010101010101010101010101010101010101010101a001010101010101010101010101010101010101010101010101010101010101018a00000000000000000000' + prefixedHexStringToBytes( + '0xf9016f808203e8b9010001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101f866f864940101010101010101010101010101010101010101f842a00101010101010101010101010101010101010101010101010101010101010101a001010101010101010101010101010101010101010101010101010101010101018a00000000000000000000' ), ] t.deepEqual(res[1], expectedSerializedReceipts, 'correctly encoded receipts') diff --git a/packages/client/test/net/protocol/snapprotocol.spec.ts b/packages/client/test/net/protocol/snapprotocol.spec.ts index 0a1a6366fd..3e0cf9cd11 100644 --- a/packages/client/test/net/protocol/snapprotocol.spec.ts +++ b/packages/client/test/net/protocol/snapprotocol.spec.ts @@ -7,7 +7,7 @@ import { bigIntToBytes, bytesToHex, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, setLengthLeft, } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' @@ -49,11 +49,11 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) const root = new Uint8Array(0) const reqId = BigInt(1) - const origin = hexStringToBytes( - '0000000000000000000000000000000000000000000000000000000000000000' + const origin = prefixedHexStringToBytes( + '0x0000000000000000000000000000000000000000000000000000000000000000' ) - const limit = hexStringToBytes( - '0000000000000000000000000f00000000000000000000000000000000000010' + const limit = prefixedHexStringToBytes( + '0x0000000000000000000000000f00000000000000000000000000000000000010' ) const bytes = BigInt(5000000) @@ -106,7 +106,7 @@ tape('[SnapProtocol]', (t) => { const chain = await Chain.create({ config }) const p = new SnapProtocol({ config, chain }) /* eslint-disable @typescript-eslint/no-use-before-define */ - const data = RLP.decode(hexStringToBytes(contractAccountRangeRLP)) as unknown + const data = RLP.decode(prefixedHexStringToBytes(contractAccountRangeRLP)) as unknown const { reqId, accounts, proof } = p.decode( p.messages.filter((message) => message.name === 'AccountRange')[0], data @@ -138,7 +138,7 @@ tape('[SnapProtocol]', (t) => { }) ) t.ok( - contractAccountRangeRLP === bytesToHex(payload), + contractAccountRangeRLP === '0x' + bytesToHex(payload), 'Re-encoded payload should match with original' ) t.end() @@ -150,7 +150,7 @@ tape('[SnapProtocol]', (t) => { const pSlim = new SnapProtocol({ config, chain }) const pFull = new SnapProtocol({ config, chain, convertSlimBody: true }) // accountRangeRLP is the corresponding response to getAccountRangeRLP - const resData = RLP.decode(hexStringToBytes(accountRangeRLP)) + const resData = RLP.decode(prefixedHexStringToBytes(accountRangeRLP)) const fullData = pFull.decode( pFull.messages.filter((message) => message.name === 'AccountRange')[0], @@ -188,13 +188,13 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) /* eslint-disable @typescript-eslint/no-use-before-define */ - const reqData = RLP.decode(hexStringToBytes(getAccountRangeRLP)) + const reqData = RLP.decode(prefixedHexStringToBytes(getAccountRangeRLP)) const { root: stateRoot } = p.decode( p.messages.filter((message) => message.name === 'GetAccountRange')[0], reqData ) // accountRangeRLP is the corresponding response to getAccountRangeRLP - const resData = RLP.decode(hexStringToBytes(accountRangeRLP)) + const resData = RLP.decode(prefixedHexStringToBytes(accountRangeRLP)) const { accounts, proof } = p.decode( p.messages.filter((message) => message.name === 'AccountRange')[0], resData @@ -228,16 +228,18 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) const root = new Uint8Array(0) const reqId = BigInt(1) - const origin = hexStringToBytes( - '0000000000000000000000000000000000000000000000000000000000000000' + const origin = prefixedHexStringToBytes( + '0x0000000000000000000000000000000000000000000000000000000000000000' ) - const limit = hexStringToBytes( - '0000000000000000000000000f00000000000000000000000000000000000010' + const limit = prefixedHexStringToBytes( + '0x0000000000000000000000000f00000000000000000000000000000000000010' ) const bytes = BigInt(5000000) const accounts = [ - keccak256(hexStringToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), - hexStringToBytes('0000000000000000000000000f00000000000000000000000000000000000010'), + keccak256(prefixedHexStringToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), + prefixedHexStringToBytes( + '0x0000000000000000000000000f00000000000000000000000000000000000010' + ), ] const payload = p.encode( @@ -292,7 +294,7 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) /* eslint-disable @typescript-eslint/no-use-before-define */ - const data = RLP.decode(hexStringToBytes(storageRangesRLP)) as unknown + const data = RLP.decode(prefixedHexStringToBytes(storageRangesRLP)) as unknown const { reqId, slots, proof } = p.decode( p.messages.filter((message) => message.name === 'StorageRanges')[0], data @@ -313,7 +315,10 @@ tape('[SnapProtocol]', (t) => { proof, }) ) - t.ok(storageRangesRLP === bytesToHex(payload), 'Re-encoded payload should match with original') + t.ok( + storageRangesRLP === '0x' + bytesToHex(payload), + 'Re-encoded payload should match with original' + ) t.end() }) @@ -323,7 +328,7 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) // Get the handle on the data for the account for which storageRanges has been fetched - const accountsData = RLP.decode(hexStringToBytes(contractAccountRangeRLP)) + const accountsData = RLP.decode(prefixedHexStringToBytes(contractAccountRangeRLP)) const { accounts } = p.decode( p.messages.filter((message) => message.name === 'AccountRange')[0], accountsData @@ -331,7 +336,7 @@ tape('[SnapProtocol]', (t) => { const lastAccount = accounts[accounts.length - 1] /* eslint-disable @typescript-eslint/no-use-before-define */ - const data = RLP.decode(hexStringToBytes(storageRangesRLP)) + const data = RLP.decode(prefixedHexStringToBytes(storageRangesRLP)) const { proof, slots } = p.decode( p.messages.filter((message) => message.name === 'StorageRanges')[0], data @@ -368,8 +373,10 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) const reqId = BigInt(1) const hashes = [ - keccak256(hexStringToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), - hexStringToBytes('0000000000000000000000000f00000000000000000000000000000000000010'), + keccak256(prefixedHexStringToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')), + prefixedHexStringToBytes( + '0x0000000000000000000000000f00000000000000000000000000000000000010' + ), ] const bytes = BigInt(5000000) @@ -407,7 +414,7 @@ tape('[SnapProtocol]', (t) => { const chain = await Chain.create({ config }) const p = new SnapProtocol({ config, chain }) - const codesRes = RLP.decode(hexStringToBytes(byteCodesRLP)) + const codesRes = RLP.decode(prefixedHexStringToBytes(byteCodesRLP)) const { reqId, codes } = p.decode( p.messages.filter((message) => message.name === 'ByteCodes')[0], codesRes @@ -422,7 +429,10 @@ tape('[SnapProtocol]', (t) => { codes, }) ) - t.ok(byteCodesRLP === bytesToHex(payload), 'Re-encoded payload should match with original') + t.ok( + byteCodesRLP === '0x' + bytesToHex(payload), + 'Re-encoded payload should match with original' + ) t.end() }) @@ -432,13 +442,13 @@ tape('[SnapProtocol]', (t) => { const p = new SnapProtocol({ config, chain }) /* eslint-disable @typescript-eslint/no-use-before-define */ - const codesReq = RLP.decode(hexStringToBytes(getByteCodesRLP)) + const codesReq = RLP.decode(prefixedHexStringToBytes(getByteCodesRLP)) const { hashes } = p.decode( p.messages.filter((message) => message.name === 'GetByteCodes')[0], codesReq ) const codeHash = hashes[0] - const codesRes = RLP.decode(hexStringToBytes(byteCodesRLP)) + const codesRes = RLP.decode(prefixedHexStringToBytes(byteCodesRLP)) const { codes } = p.decode( p.messages.filter((message) => message.name === 'ByteCodes')[0], codesRes @@ -518,54 +528,57 @@ tape('[SnapProtocol]', (t) => { nodes, }) ) - t.ok(trieNodesRLP === bytesToHex(payload), 'Re-encoded payload should match with original') + t.ok( + trieNodesRLP === '0x' + bytesToHex(payload), + 'Re-encoded payload should match with original' + ) t.end() }) }) const getAccountRangeRLP = - 'f86501a06f2b67d566fd7e82160a07d68d209ff56b87f5da362d5d60919a65550c89ac2ea00000000000000000000000000000000000000000000000000000000000000000a0f000000000000000000000000f0000000000000000000000000000000000001064' + '0xf86501a06f2b67d566fd7e82160a07d68d209ff56b87f5da362d5d60919a65550c89ac2ea00000000000000000000000000000000000000000000000000000000000000000a0f000000000000000000000000f0000000000000000000000000000000000001064' const accountRangeRLP = - 'f9097101f87ce6a000009b82f07b6d086a2f1574482af15472d565ea145ff42edfa412a1bd632625c411808080e6a00001b989dc49b9df17e95a9e1e50870aabf88e21b9d4cd4811b5507dad53517cc401808080eda00001ea42267f6ff20ada8604d602387163b25e87102bf3d214d52ceec8dcecefcb01870360051c8960008080f908efb90214f90211a0c1278c80295a5fd765db6f3ddb5848683d8451ce795e45cb45e58c2bbea38b23a09058fbfd1194da5ea2c32fe6621c87c311a521f3ade5a6fcdfb2ce6c77cc9457a0ca279fd327589e0862fe3108b5ded8d1591af95c21e49de44a7c530da86d1d5ba0060137d87fe07e9e74d2ced2631f31ff0f2e1a77ec8e55a0e3c0d95049aa3a81a0c7153c1a920cf18b4ddf2069572c60429a82fac1d617c7186eb5f2f6c67bb3eea008cb3728001b9e04fcf14818826a5c379cccc3f45df0b76c2a86bb7588354462a09bec68f4684acd7c0b81b49b6705cb90a21390046e5233eb8a3eceb362d7e699a0954b9259abd98bb1bbf3caef798f9b2c67394670c926900ccf5751253ed4f87aa003beafd9e8e865d5610de7f137d404814cf6c4a12085dae8892266de62ef660ba06236e72b0960753708738bacb7cb4f4ff1c8b2e915e9a18599c75603dda597eea0b063b409a64860fc0d300eba3d772b30680881d938e6ebaabd80f82a753b4414a0846bff10a2dd3084bd983544aaeaf01770867aa572162869a6fe77609bb36dbfa0e467d24298c2eabe85e2c94b8c923a1a514c12a5c9b8e2181216d8317e010693a0bad67c670ec6fd973215ff412f58f3f54a9018866b04869002d3e6e4208f4c2ea086fe0af717dc7e5c127ec7396e1d0e16fad054109942cb0a8dc4348ebb82398da011bb9f0056d3a9e901b99c73d2d3e76215b47c333365d8b8a73e1acade5bda4b80b90214f90211a0b00ba2f0bfa01de02b767dcdf38c7f5691e5c340def6df806741a59d85bd2a13a05658dbc276709dbf6bf2b28872227646841f6f0d0fe1da001a0d08725b9a060ca09c950f1c934b5298bdebd8e65a26bf8f6edb269cd3fcaaf37915695aa30e870fa05f46b447501b5831596af8212cdb5f5d00fa3c70e9eaa13f5b3731d4a2a1bf5ba0d247a7b93cca2a31070f508fb093576145e0f9a83ccff8fa2d6bf2ff42abd78ca0be5a7c7a50fe9ff7e9c6c0e1a8a960721fa3ca81dad009b3f74da76ac905c1eda0713fbc2d738d788f9de1e3b9c21cb51a8ef8814c0b2c650e93edfd442125fdb5a04174b732f2b7b079ad9941c2a445d2c23c604c5d448b9200c9bc24332f0d018ba04bc37f9ba4124a538df315d7d07718f30fd9e715cbf0837a89a4ea0e8db2852ea0a948b1640a4cfe054be12c3d92f4c7a8c2b93e87f5cbf0df9f6ebe89160b6ccaa0bf660df9cd53c9ce329942f8a6ce5e276fe29fde33e4ed94a73ffd11d116ac20a02051566c8da26729f53eaa1c08b8fb80d955a8dce41b52ea1a80d19604225e79a0d7977ed0bc385e1554e9fdc7fc1fa5f11e1ab354edcbb2b2bbc86b3458e16bfca07e455873c9ab889267be0090716d6b81981ee744a498e5e7c7e7537b3660e09da0f4e9fee500e1d0c09356223097b8b4bdd562575cbd6c7520a791b5d1d06bcc8ca075ea32ed4754e8fa6ac42396ec52159c755319ef139a40c89135780f02d2cd3d80b90214f90211a005d5c908571626e6429a2e60c12fb0a7cbb792990237b07f0b895262dd468002a0e8832065be7f27bfc9622718b3217e764a64139809e83a4f346974d0bf6d4cb1a0884edcf8063cd210c4f055c9a65fa9ba9f3140ed7b5ffea534eb46543747312ca06939eb03dfec57d4b19633637f591f9c9eaf823bb4b881cfee6d4f2cc438de15a0b3465275b807743c9d2babcc187bccfd4d5875e3be850ba15bdb49ecb0756b33a019f64beddb99d42a6d0aa559bb742099b75a56119110e536aec1e0dc8426d4bda00b2a64b5cfd0465225a77e8d36f33a8cd2e2955dd27f17858c6bff058560073da06d29ec54698740d1b0a31fbc108f7a7f34b54fca2469a1e741a7e6d238ca3223a089b0a60705c5aabdc613843831737ab0d4924dfaa98e36d0da5c5c701b9a184fa0beb52c58a15cbc60614935c901236d604e45a6fb777c5c2a96bbdaa6c5643401a091e8e3621e73c2f97d2f8a1e6aa0502c2d39c760c8ec75d5bb74dcb8c6042b07a0919f563a2f826f3375e0171d7aaed13d5d430231bb3ab153a804dea6ff3fad48a076199370d103d86301ddcfbac8dca567b32156d50d3884cefc52c86229b9c4dfa0d37db1d1a795c0ffd9fd3dab57c98b0986529ab1f32d306cdfd5063a2371875da019c8b72759269ffff97d1b3284696b037eb984c4520d3be799b49716e77d888fa08a5777ee67d4d9592dcd388b0f0f14a02225468f9d3339dc1d9ef25fb85f30f280b90174f90171a093c39d2f8d596b9d295b60221892e54bf39c276b77f25be68195379766ac6f1aa0f67ae81c632b1fcabbf55700389ff5735666139a48fcb88b1ec49e76d89f0dcda03ff27dc7b513d1790150232542a066f377c345d94891b818098ee07539656f8f80a04d0bd2a7147dd2e8dbd0b3e1166ec5f8f38e2509c4d7647bcb4d5f88bd0c015ba08d5f743d005ba218dbda14eb3e599616dfd95de81a52271cc7068c8d7d02b954a0319a502e4ba85543f9e87b56742ffa93e6bad838f6621173c268b6a47d927c66a0042be4c968761c0bb12a1663afc013d9224cdaafd24faa13af29ec685c5a9681808080a04c058f78c59efa16cf457b01f273d9a593d9bdb7b80bdee9172e1aa94bfb56e6a0e7198822750da3bafcda0bd58bc813c190a3e220710c8bb6eef3036061234dc0a028fb2d97af7dea9285b566bbd754bd20b8cb24abb865d382ebc14e7c2994be7fa0ac77041d0371ae76a4ffb9440a3bc827660d4bd2fc535cfd95c213524e89fd908080b86af8689f209b82f07b6d086a2f1574482af15472d565ea145ff42edfa412a1bd632625b846f8441180a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470b853f8518080808080808080808080a00cd5b0af242798bc101250a06cbfbdf37aec6ddb42aa1428ea9e51440650c3d18080a0f6d819bdf6861f54f23de70f48431954d5f0e20a0372ecb1cbdbf526beafd6b88080b870f86e9e3a42267f6ff20ada8604d602387163b25e87102bf3d214d52ceec8dcecefb84df84b01870360051c896000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' + '0xf9097101f87ce6a000009b82f07b6d086a2f1574482af15472d565ea145ff42edfa412a1bd632625c411808080e6a00001b989dc49b9df17e95a9e1e50870aabf88e21b9d4cd4811b5507dad53517cc401808080eda00001ea42267f6ff20ada8604d602387163b25e87102bf3d214d52ceec8dcecefcb01870360051c8960008080f908efb90214f90211a0c1278c80295a5fd765db6f3ddb5848683d8451ce795e45cb45e58c2bbea38b23a09058fbfd1194da5ea2c32fe6621c87c311a521f3ade5a6fcdfb2ce6c77cc9457a0ca279fd327589e0862fe3108b5ded8d1591af95c21e49de44a7c530da86d1d5ba0060137d87fe07e9e74d2ced2631f31ff0f2e1a77ec8e55a0e3c0d95049aa3a81a0c7153c1a920cf18b4ddf2069572c60429a82fac1d617c7186eb5f2f6c67bb3eea008cb3728001b9e04fcf14818826a5c379cccc3f45df0b76c2a86bb7588354462a09bec68f4684acd7c0b81b49b6705cb90a21390046e5233eb8a3eceb362d7e699a0954b9259abd98bb1bbf3caef798f9b2c67394670c926900ccf5751253ed4f87aa003beafd9e8e865d5610de7f137d404814cf6c4a12085dae8892266de62ef660ba06236e72b0960753708738bacb7cb4f4ff1c8b2e915e9a18599c75603dda597eea0b063b409a64860fc0d300eba3d772b30680881d938e6ebaabd80f82a753b4414a0846bff10a2dd3084bd983544aaeaf01770867aa572162869a6fe77609bb36dbfa0e467d24298c2eabe85e2c94b8c923a1a514c12a5c9b8e2181216d8317e010693a0bad67c670ec6fd973215ff412f58f3f54a9018866b04869002d3e6e4208f4c2ea086fe0af717dc7e5c127ec7396e1d0e16fad054109942cb0a8dc4348ebb82398da011bb9f0056d3a9e901b99c73d2d3e76215b47c333365d8b8a73e1acade5bda4b80b90214f90211a0b00ba2f0bfa01de02b767dcdf38c7f5691e5c340def6df806741a59d85bd2a13a05658dbc276709dbf6bf2b28872227646841f6f0d0fe1da001a0d08725b9a060ca09c950f1c934b5298bdebd8e65a26bf8f6edb269cd3fcaaf37915695aa30e870fa05f46b447501b5831596af8212cdb5f5d00fa3c70e9eaa13f5b3731d4a2a1bf5ba0d247a7b93cca2a31070f508fb093576145e0f9a83ccff8fa2d6bf2ff42abd78ca0be5a7c7a50fe9ff7e9c6c0e1a8a960721fa3ca81dad009b3f74da76ac905c1eda0713fbc2d738d788f9de1e3b9c21cb51a8ef8814c0b2c650e93edfd442125fdb5a04174b732f2b7b079ad9941c2a445d2c23c604c5d448b9200c9bc24332f0d018ba04bc37f9ba4124a538df315d7d07718f30fd9e715cbf0837a89a4ea0e8db2852ea0a948b1640a4cfe054be12c3d92f4c7a8c2b93e87f5cbf0df9f6ebe89160b6ccaa0bf660df9cd53c9ce329942f8a6ce5e276fe29fde33e4ed94a73ffd11d116ac20a02051566c8da26729f53eaa1c08b8fb80d955a8dce41b52ea1a80d19604225e79a0d7977ed0bc385e1554e9fdc7fc1fa5f11e1ab354edcbb2b2bbc86b3458e16bfca07e455873c9ab889267be0090716d6b81981ee744a498e5e7c7e7537b3660e09da0f4e9fee500e1d0c09356223097b8b4bdd562575cbd6c7520a791b5d1d06bcc8ca075ea32ed4754e8fa6ac42396ec52159c755319ef139a40c89135780f02d2cd3d80b90214f90211a005d5c908571626e6429a2e60c12fb0a7cbb792990237b07f0b895262dd468002a0e8832065be7f27bfc9622718b3217e764a64139809e83a4f346974d0bf6d4cb1a0884edcf8063cd210c4f055c9a65fa9ba9f3140ed7b5ffea534eb46543747312ca06939eb03dfec57d4b19633637f591f9c9eaf823bb4b881cfee6d4f2cc438de15a0b3465275b807743c9d2babcc187bccfd4d5875e3be850ba15bdb49ecb0756b33a019f64beddb99d42a6d0aa559bb742099b75a56119110e536aec1e0dc8426d4bda00b2a64b5cfd0465225a77e8d36f33a8cd2e2955dd27f17858c6bff058560073da06d29ec54698740d1b0a31fbc108f7a7f34b54fca2469a1e741a7e6d238ca3223a089b0a60705c5aabdc613843831737ab0d4924dfaa98e36d0da5c5c701b9a184fa0beb52c58a15cbc60614935c901236d604e45a6fb777c5c2a96bbdaa6c5643401a091e8e3621e73c2f97d2f8a1e6aa0502c2d39c760c8ec75d5bb74dcb8c6042b07a0919f563a2f826f3375e0171d7aaed13d5d430231bb3ab153a804dea6ff3fad48a076199370d103d86301ddcfbac8dca567b32156d50d3884cefc52c86229b9c4dfa0d37db1d1a795c0ffd9fd3dab57c98b0986529ab1f32d306cdfd5063a2371875da019c8b72759269ffff97d1b3284696b037eb984c4520d3be799b49716e77d888fa08a5777ee67d4d9592dcd388b0f0f14a02225468f9d3339dc1d9ef25fb85f30f280b90174f90171a093c39d2f8d596b9d295b60221892e54bf39c276b77f25be68195379766ac6f1aa0f67ae81c632b1fcabbf55700389ff5735666139a48fcb88b1ec49e76d89f0dcda03ff27dc7b513d1790150232542a066f377c345d94891b818098ee07539656f8f80a04d0bd2a7147dd2e8dbd0b3e1166ec5f8f38e2509c4d7647bcb4d5f88bd0c015ba08d5f743d005ba218dbda14eb3e599616dfd95de81a52271cc7068c8d7d02b954a0319a502e4ba85543f9e87b56742ffa93e6bad838f6621173c268b6a47d927c66a0042be4c968761c0bb12a1663afc013d9224cdaafd24faa13af29ec685c5a9681808080a04c058f78c59efa16cf457b01f273d9a593d9bdb7b80bdee9172e1aa94bfb56e6a0e7198822750da3bafcda0bd58bc813c190a3e220710c8bb6eef3036061234dc0a028fb2d97af7dea9285b566bbd754bd20b8cb24abb865d382ebc14e7c2994be7fa0ac77041d0371ae76a4ffb9440a3bc827660d4bd2fc535cfd95c213524e89fd908080b86af8689f209b82f07b6d086a2f1574482af15472d565ea145ff42edfa412a1bd632625b846f8441180a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470b853f8518080808080808080808080a00cd5b0af242798bc101250a06cbfbdf37aec6ddb42aa1428ea9e51440650c3d18080a0f6d819bdf6861f54f23de70f48431954d5f0e20a0372ecb1cbdbf526beafd6b88080b870f86e9e3a42267f6ff20ada8604d602387163b25e87102bf3d214d52ceec8dcecefb84df84b01870360051c896000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' //await peer!.snap!.getAccountRange({ // root: stateRoot, // origin: hexToBytes( // '27be64f6a1510e4166b35201a920e543e0579df3b947b8743458736e51549f0c' // ), -// limit: hexStringToBytes('f000000000000000000000000f00000000000000000000000000000000000010'), +// limit: prefixedHexStringToBytes('0xf000000000000000000000000f00000000000000000000000000000000000010'), // bytes: BigInt(100), // }) const contractAccountRangeRLP = - 'f909cb01f897eda027be64f6a1510e4166b35201a920e543e0579df3b947b8743458736e51549f0ccb0187059d006abec0008080f867a027be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215f8440180a03dc6d3cfdc6210b8591ea852961d880821298c7891dea399e02d87550af9d40ea0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66f9092eb90214f90211a03e317f72529393d592a14a980728964491a795b0b17bce46dd6462cd73178528a031d9a927f50c38e26b733420d54e018ad136a2acfb0f62ff0a530622d0910501a0e16176464ca43ffccd8dcac69c254e4c232b3736cb50b22fcba2aca674d97657a0c468309ef106b3c7c011c79bbf30f6d84f50e9ee70efcbb6e2ee3ed3532d8d5aa04b7a7527c301a3e8ccaa0065144bcca966d4dc1bf5091fffb59fee96235ddab7a0cc9f49ba7f69154937a24ce1bdce4c525c57fad23a866d35cdc14a0ffb4fd569a05c6688038fa3c868118abc35cb33757b11892df27f5949be6533822d38d023cba0bcd60cfb5cd40113a3b91ef2ef582a5598e1d1c02f4ef19eb3a01f4a7385d9e2a0b01c57e7623a52c797bfad0b234864f0478defd52a604f52c6c13240cf263582a0467b446d76308ce3f6afabbb9e50487842359da4c5ea803c98d01ea1100ee3a9a041cc43991ff1d05d306179415fd0108c80af2ed0ecc1968d54c4804a3a3e7d26a0de817ee6846ebffe2f0ba07b9e43a5531deb13fec227914fa829cf9e0b6b1feba0d110eeeee544612b96d241eb1923301192bc1937105c4f8d42950074d1b20523a042c0d15d6d12fed334ac2905230c9596dbac86c43e2f7659649a0aaabb614a59a05e4fde55ac428253d2bf44dbacdd90617c6c7a7037ccff59bf1bd5e8e9fd8cb1a0b93d6175cacaa3ff73e2be3aa1bf980a3a0f08554b46cc9346687b5436a9af9080b90214f90211a03fb9d5e64403a8b57c0d8f19b52be351600547e0810d2bd363ce27fca733c351a0cd52ee7470e730d3f28b2ffa8b6521061b79d5d6c19743953dc2c444a6a7a9a8a05ffa4be37e29f4506242483f75d1b2e6b834e38e2f3008ee278ef6f3859d3fbea01ad32ca2d763d2c80b1d2726a9e9d76b19f7aaa343c0ecdae7d4c528216c38aaa0ad31f5349953c3284cf53b6f64d5f50520d77415d68ac8c2c74e11e20328e930a048ad1822f5b77ed9199a0ed08dd819f609420f4859c68795ee85c60a337e77e5a08b8a8b33dfe0ac28f5528a76f4ba05475f0c11a1c1a43eff431a19c4e106241fa0a65e791df46225d6f86b19c29ecd3fb1515e43425cf62520c04b78dc05042db0a02767fe0d42f7171f249a3bca1fe485feeccab4a4e54562cf9d86246d61d69d45a026165555bfc36933cbae97d2c9ca3566789dd65b26f5b1459b883e5817c4d842a0e9847655d69a1d2765b177c9effca84e30a4358527378e0e2579290cd2bfe1d7a0176d992c06eac5d9709b0c88ab9662ff33d8832a3a656844adcfcda20a7a5d1ea0517bb9f09a79ac65969b60ed8cf88ad4469a8c089392993ed5ae36588d167ce3a06c2d5a9a44fcbdb4a78cadf1ff198e13a05a1cbfdfe4322b651a54fba43c80c4a0f31f6a2b80f6e5994e4d7a6d7ade8e374717ecb382a6c2e2fa84da289a7311dda0da149b02c25ec3cbe790d968f3f0796b1d97b47406c4e048c0876f188c8843db80b90214f90211a05692dce2e2b9e931f11de516711dfc9fd7f072aafa94246842327bb5cc88d299a05a34d682e1f48b5c7a561899cadf6d9f5728a28b47a2299c50c583401c8adcf4a09ac2be05ecbf11e8f04293413c3f265ba0f7936fdca301e70e863a3fd97351f2a0be65aeda766d5b431ba66f6fc7426d1d14225f4c7c21abf531b1179bd723de37a0d434197f2a4d480134b96f54df371cf553bc9d419bf7b8fe97915c3bafe5cc38a06a6f87d8033eb91704f16d3bc5ac7d1dd92ccea236a66f7bee58ea6ddbd66662a03dcae49ff1dba7426fe91798df52719aa8aec85bb8ecd290a8c7f3f625c0e04ca0da18286af20d2bef143807e6153ebef7c4bbce1a8758759e5c868245302dc522a082e530d64d6839289db6a7ba5fc084203054555b4c22b36c95792cb73afdb5c1a0a7b0b714bf64e738ffdc0bc2450469a1ee53e0eb2ac6604de791b93280d9522fa0649ce83d40c4071a4a6f3241cdc97884cad2820106df5a558cd1460a51af737ca0d9e5428057bd3ea9c9ee66fe928d1c5fe2291f038798b627a6ba32132aa446c8a036df1ab5e4a79ecb2083143256cda9964baab9af378806c66d8116c5ac9d1c18a0ab83c42863e83767739e3557582ab1a9ec0546202522bf8142d2abe4339ef547a07063deef264a623d2fe6e94863a6daedd8f4431aa15db5c5f08d60db15be8889a00d4901e40f514f6bf7ed86f0ad4ff104c73dd34583398b06044ffb6c0ef0ceaf80b90194f90191a021100e99c4cf6f11817174a1d6494935c5db672a4147e2d7c7b1183d1cd194dd80a0a60cc6818e6cb02b94dd71ee2cf9945b296bd1a97f18132865a8c4ee5f8d808fa0c82f7a3e2bd946f042a958ae4e45463b2bdfb41d13791b0284e741b8d088e809a01b33f2aff8cfe1f85607cda408ab1be19824112301cb5bf7ad39c33ca6a3ae6ca0136ee30ad667bd05b9032352046171e5a4b1cc6f0dab92447cd1e993d176d11380a002989ef278f5e1ea994d747aa0e03eff3781884176a11244bfa0093e0cbabaa0a0e2ce43841c561596e3c20ca0d9e65926877bb0563f97d8ba840bff17bc71eedc80a0355479422e131a63a41dfff1359c763783128c2ca46113cc2fad097716d980cea0ca2306ad965fd1fc2c374794f27f9ae974e4518acfc5a45c4fd243faecdbb968a0b70fe21f9920ffb1e85f76f3d68ace66fda9fba2a18ee40c56be30d205e163b180a0a87f04fea647cc1fab13bbd4f95c99da77b56d1ba3e70b2bfbeffb00b85bec2aa01736c3eae15545b633b8344eda0d6f53d3de180b9b1abd4d5f0452ef8a8d197880b873f871808080808080a091ce7aa54a929b46c827f31c7a50e4d820d7e0c940cf2fdfe8f489ef3f5ada62a0d9b516fbc9b3dc7ceb6045550fc6eb75301f312f7ce74374d8f90f7248dbfeac8080a0f92923e2c55de59cbd770ee6bb9cd1f6ddf481e60e80c25839faf29c8850dbad808080808080b870f86e9e34f6a1510e4166b35201a920e543e0579df3b947b8743458736e51549f0cb84df84b0187059d006abec000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470b869f8679e3c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215b846f8440180a03dc6d3cfdc6210b8591ea852961d880821298c7891dea399e02d87550af9d40ea0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66' + '0xf909cb01f897eda027be64f6a1510e4166b35201a920e543e0579df3b947b8743458736e51549f0ccb0187059d006abec0008080f867a027be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215f8440180a03dc6d3cfdc6210b8591ea852961d880821298c7891dea399e02d87550af9d40ea0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66f9092eb90214f90211a03e317f72529393d592a14a980728964491a795b0b17bce46dd6462cd73178528a031d9a927f50c38e26b733420d54e018ad136a2acfb0f62ff0a530622d0910501a0e16176464ca43ffccd8dcac69c254e4c232b3736cb50b22fcba2aca674d97657a0c468309ef106b3c7c011c79bbf30f6d84f50e9ee70efcbb6e2ee3ed3532d8d5aa04b7a7527c301a3e8ccaa0065144bcca966d4dc1bf5091fffb59fee96235ddab7a0cc9f49ba7f69154937a24ce1bdce4c525c57fad23a866d35cdc14a0ffb4fd569a05c6688038fa3c868118abc35cb33757b11892df27f5949be6533822d38d023cba0bcd60cfb5cd40113a3b91ef2ef582a5598e1d1c02f4ef19eb3a01f4a7385d9e2a0b01c57e7623a52c797bfad0b234864f0478defd52a604f52c6c13240cf263582a0467b446d76308ce3f6afabbb9e50487842359da4c5ea803c98d01ea1100ee3a9a041cc43991ff1d05d306179415fd0108c80af2ed0ecc1968d54c4804a3a3e7d26a0de817ee6846ebffe2f0ba07b9e43a5531deb13fec227914fa829cf9e0b6b1feba0d110eeeee544612b96d241eb1923301192bc1937105c4f8d42950074d1b20523a042c0d15d6d12fed334ac2905230c9596dbac86c43e2f7659649a0aaabb614a59a05e4fde55ac428253d2bf44dbacdd90617c6c7a7037ccff59bf1bd5e8e9fd8cb1a0b93d6175cacaa3ff73e2be3aa1bf980a3a0f08554b46cc9346687b5436a9af9080b90214f90211a03fb9d5e64403a8b57c0d8f19b52be351600547e0810d2bd363ce27fca733c351a0cd52ee7470e730d3f28b2ffa8b6521061b79d5d6c19743953dc2c444a6a7a9a8a05ffa4be37e29f4506242483f75d1b2e6b834e38e2f3008ee278ef6f3859d3fbea01ad32ca2d763d2c80b1d2726a9e9d76b19f7aaa343c0ecdae7d4c528216c38aaa0ad31f5349953c3284cf53b6f64d5f50520d77415d68ac8c2c74e11e20328e930a048ad1822f5b77ed9199a0ed08dd819f609420f4859c68795ee85c60a337e77e5a08b8a8b33dfe0ac28f5528a76f4ba05475f0c11a1c1a43eff431a19c4e106241fa0a65e791df46225d6f86b19c29ecd3fb1515e43425cf62520c04b78dc05042db0a02767fe0d42f7171f249a3bca1fe485feeccab4a4e54562cf9d86246d61d69d45a026165555bfc36933cbae97d2c9ca3566789dd65b26f5b1459b883e5817c4d842a0e9847655d69a1d2765b177c9effca84e30a4358527378e0e2579290cd2bfe1d7a0176d992c06eac5d9709b0c88ab9662ff33d8832a3a656844adcfcda20a7a5d1ea0517bb9f09a79ac65969b60ed8cf88ad4469a8c089392993ed5ae36588d167ce3a06c2d5a9a44fcbdb4a78cadf1ff198e13a05a1cbfdfe4322b651a54fba43c80c4a0f31f6a2b80f6e5994e4d7a6d7ade8e374717ecb382a6c2e2fa84da289a7311dda0da149b02c25ec3cbe790d968f3f0796b1d97b47406c4e048c0876f188c8843db80b90214f90211a05692dce2e2b9e931f11de516711dfc9fd7f072aafa94246842327bb5cc88d299a05a34d682e1f48b5c7a561899cadf6d9f5728a28b47a2299c50c583401c8adcf4a09ac2be05ecbf11e8f04293413c3f265ba0f7936fdca301e70e863a3fd97351f2a0be65aeda766d5b431ba66f6fc7426d1d14225f4c7c21abf531b1179bd723de37a0d434197f2a4d480134b96f54df371cf553bc9d419bf7b8fe97915c3bafe5cc38a06a6f87d8033eb91704f16d3bc5ac7d1dd92ccea236a66f7bee58ea6ddbd66662a03dcae49ff1dba7426fe91798df52719aa8aec85bb8ecd290a8c7f3f625c0e04ca0da18286af20d2bef143807e6153ebef7c4bbce1a8758759e5c868245302dc522a082e530d64d6839289db6a7ba5fc084203054555b4c22b36c95792cb73afdb5c1a0a7b0b714bf64e738ffdc0bc2450469a1ee53e0eb2ac6604de791b93280d9522fa0649ce83d40c4071a4a6f3241cdc97884cad2820106df5a558cd1460a51af737ca0d9e5428057bd3ea9c9ee66fe928d1c5fe2291f038798b627a6ba32132aa446c8a036df1ab5e4a79ecb2083143256cda9964baab9af378806c66d8116c5ac9d1c18a0ab83c42863e83767739e3557582ab1a9ec0546202522bf8142d2abe4339ef547a07063deef264a623d2fe6e94863a6daedd8f4431aa15db5c5f08d60db15be8889a00d4901e40f514f6bf7ed86f0ad4ff104c73dd34583398b06044ffb6c0ef0ceaf80b90194f90191a021100e99c4cf6f11817174a1d6494935c5db672a4147e2d7c7b1183d1cd194dd80a0a60cc6818e6cb02b94dd71ee2cf9945b296bd1a97f18132865a8c4ee5f8d808fa0c82f7a3e2bd946f042a958ae4e45463b2bdfb41d13791b0284e741b8d088e809a01b33f2aff8cfe1f85607cda408ab1be19824112301cb5bf7ad39c33ca6a3ae6ca0136ee30ad667bd05b9032352046171e5a4b1cc6f0dab92447cd1e993d176d11380a002989ef278f5e1ea994d747aa0e03eff3781884176a11244bfa0093e0cbabaa0a0e2ce43841c561596e3c20ca0d9e65926877bb0563f97d8ba840bff17bc71eedc80a0355479422e131a63a41dfff1359c763783128c2ca46113cc2fad097716d980cea0ca2306ad965fd1fc2c374794f27f9ae974e4518acfc5a45c4fd243faecdbb968a0b70fe21f9920ffb1e85f76f3d68ace66fda9fba2a18ee40c56be30d205e163b180a0a87f04fea647cc1fab13bbd4f95c99da77b56d1ba3e70b2bfbeffb00b85bec2aa01736c3eae15545b633b8344eda0d6f53d3de180b9b1abd4d5f0452ef8a8d197880b873f871808080808080a091ce7aa54a929b46c827f31c7a50e4d820d7e0c940cf2fdfe8f489ef3f5ada62a0d9b516fbc9b3dc7ceb6045550fc6eb75301f312f7ce74374d8f90f7248dbfeac8080a0f92923e2c55de59cbd770ee6bb9cd1f6ddf481e60e80c25839faf29c8850dbad808080808080b870f86e9e34f6a1510e4166b35201a920e543e0579df3b947b8743458736e51549f0cb84df84b0187059d006abec000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470b869f8679e3c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215b846f8440180a03dc6d3cfdc6210b8591ea852961d880821298c7891dea399e02d87550af9d40ea0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66' // Even though we don't require using getStorageRangesRLP in the test, but this is here in case one // wants to inspect the request that led to the response // await peer!.snap!.getStorageRanges({ // root: stateRoot, // accounts: [ -// hexStringToBytes('27be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215'), +// prefixedHexStringToBytes('0x27be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215'), // ], -// origin: hexStringToBytes( -// '0000000000000000000000000f00000000000000000000000000000000000000'), -// limit: hexStringToBytes('f000000000000000000000000f00000000000000000000000000000000000010'), +// origin: prefixedHexStringToBytes( +// '0x0000000000000000000000000f00000000000000000000000000000000000000'), +// limit: prefixedHexStringToBytes('0xf000000000000000000000000f00000000000000000000000000000000000010'), // bytes: BigInt(100), // }) const _getStorageRangesRLP = - 'f88701a0842c311cc3e0242fe3877f10a06ff26581a5102ddc1d3de1198dc081e2407fe9e1a027be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215a00000000000000000000000000f00000000000000000000000000000000000000a0f000000000000000000000000f0000000000000000000000000000000000001064' + '0xf88701a0842c311cc3e0242fe3877f10a06ff26581a5102ddc1d3de1198dc081e2407fe9e1a027be7c29a7a7d6da542205ed52b91990e625039a545702874be74db9f40fb215a00000000000000000000000000f00000000000000000000000000000000000000a0f000000000000000000000000f0000000000000000000000000000000000001064' const storageRangesRLP = - 'f9020201f885f883e2a0011495c4db39fdb3ff374636d517fe5802b9856190833a6cec035be5d4928a7c01f7a0290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639594c72da985e2209a8ea7bca2f2a5e2308b7c4a3929e7a060264186ee63f748d340388f07b244d96d007fff5cbc397bbd69f8747c421f79858462b66ae7f90177b8d3f8d1a0072ebf377f0339cbfdf33e9ec4a7ca991324dacfcb249467567d260835778f4480a06abdc8e224c631c3998a6c2a982d3dddb4d071739433b45e8a086b0a02a5c9dd808080a0c3d3e38f431316e13d65759577651bbf81d8e25b5dc6b583bbbc9c2f5f332be680a06512473128eb2f4b680fdcfd7e3d05ec0ad9bdccbfe10dbea0e8519945ce8df7808080a04e4ac86a66b6adb6cceffd43be3970fb09804b6c63eabbacc87b3b6f8cb1729080a0d68af628d6ba5ce332a2182b0da71ca12010a9a80c37bd95244446c36fe65fb38080a3e2a0311495c4db39fdb3ff374636d517fe5802b9856190833a6cec035be5d4928a7c01b853f851a07a674b9ad2b903117d470c39b3f7070a9ffef66e9b6d5ef1df82a656dbcad0c4808080a0530024120eca2e19bde6a5bf7ffcea39cb938fa79f77cccb61121ea27032688b808080808080808080808080a8e7a020264186ee63f748d340388f07b244d96d007fff5cbc397bbd69f8747c421f79858462b66ae7' + '0xf9020201f885f883e2a0011495c4db39fdb3ff374636d517fe5802b9856190833a6cec035be5d4928a7c01f7a0290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639594c72da985e2209a8ea7bca2f2a5e2308b7c4a3929e7a060264186ee63f748d340388f07b244d96d007fff5cbc397bbd69f8747c421f79858462b66ae7f90177b8d3f8d1a0072ebf377f0339cbfdf33e9ec4a7ca991324dacfcb249467567d260835778f4480a06abdc8e224c631c3998a6c2a982d3dddb4d071739433b45e8a086b0a02a5c9dd808080a0c3d3e38f431316e13d65759577651bbf81d8e25b5dc6b583bbbc9c2f5f332be680a06512473128eb2f4b680fdcfd7e3d05ec0ad9bdccbfe10dbea0e8519945ce8df7808080a04e4ac86a66b6adb6cceffd43be3970fb09804b6c63eabbacc87b3b6f8cb1729080a0d68af628d6ba5ce332a2182b0da71ca12010a9a80c37bd95244446c36fe65fb38080a3e2a0311495c4db39fdb3ff374636d517fe5802b9856190833a6cec035be5d4928a7c01b853f851a07a674b9ad2b903117d470c39b3f7070a9ffef66e9b6d5ef1df82a656dbcad0c4808080a0530024120eca2e19bde6a5bf7ffcea39cb938fa79f77cccb61121ea27032688b808080808080808080808080a8e7a020264186ee63f748d340388f07b244d96d007fff5cbc397bbd69f8747c421f79858462b66ae7' // await peer!.snap!.getByteCodes({ // hashes: [ -// hexStringToBytes('e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66'), +// prefixedHexStringToBytes('0xe68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c66'), // ], // bytes: BigInt(50000), // }) const getByteCodesRLP = - 'e601e1a0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c6682c350' + '0xe601e1a0e68fe0bb7c4a483affd0f19cc2b989105242bd6b256c6de3afd738f8acd80c6682c350' const byteCodesRLP = - 'f9182c01f91828b918256080604052600436106100a75760003560e01c80635daf08ca116100645780635daf08ca146105135780638da5cb5b14610601578063c127c24714610658578063ee8ca76e14610740578063f2fde38b14610826578063f602ae2714610877576100a7565b8063013cf08b146102565780630b1ca49a14610335578063373058b814610386578063391068211461039d578063400e39491461040257806358dc93bc1461042d575b6000600180808054905003815481106100bc57fe5b906000526020600020906008020190508060060160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561012557600080fd5b60018160060160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080600301600081548092919060010191905055506000349050808260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055507fa398b89ba344a0b23a0b9de53db298b2a1a868b396c1878b7e9dcbafecd49b133334604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15050005b34801561026257600080fd5b5061028f6004803603602081101561027957600080fd5b81019080803590602001909291905050506108b4565b60405180878152602001806020018615151515815260200185151515158152602001848152602001838152602001828103825287818151815260200191508051906020019080838360005b838110156102f55780820151818401526020810190506102da565b50505050905090810190601f1680156103225780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b34801561034157600080fd5b506103846004803603602081101561035857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109af565b005b34801561039257600080fd5b5061039b610c0b565b005b3480156103a957600080fd5b506103ec600480360360208110156103c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d94565b6040518082815260200191505060405180910390f35b34801561040e57600080fd5b50610417610dac565b6040518082815260200191505060405180910390f35b34801561043957600080fd5b506104fd6004803603604081101561045057600080fd5b81019080803590602001909291908035906020019064010000000081111561047757600080fd5b82018360208201111561048957600080fd5b803590602001918460018302840111640100000000831117156104ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610db2565b6040518082815260200191505060405180910390f35b34801561051f57600080fd5b5061054c6004803603602081101561053657600080fd5b8101908080359060200190929190505050610e12565b604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b838110156105c45780820151818401526020810190506105a9565b50505050905090810190601f1680156105f15780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561060d57600080fd5b50610616610f01565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561066457600080fd5b5061073e6004803603604081101561067b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001906401000000008111156106b857600080fd5b8201836020820111156106ca57600080fd5b803590602001918460018302840111640100000000831117156106ec57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610f26565b005b34801561074c57600080fd5b506108106004803603604081101561076357600080fd5b81019080803590602001909291908035906020019064010000000081111561078a57600080fd5b82018360208201111561079c57600080fd5b803590602001918460018302840111640100000000831117156107be57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061115e565b6040518082815260200191505060405180910390f35b34801561083257600080fd5b506108756004803603602081101561084957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112ff565b005b34801561088357600080fd5b506108b26004803603602081101561089a57600080fd5b8101908080351515906020019092919050505061139b565b005b600181815481106108c157fe5b9060005260206000209060080201600091509050806000015490806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109735780601f1061094857610100808354040283529160200191610973565b820191906000526020600020905b81548152906001019060200180831161095657829003601f168201915b5050505050908060020160009054906101000a900460ff16908060020160019054906101000a900460ff16908060030154908060040154905086565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a0857600080fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610a5557600080fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b600160048054905003811015610b8c5760046001820181548110610aba57fe5b906000526020600020906003020160048281548110610ad557fe5b90600052602060002090600302016000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018201816001019080546001816001161561010002031660029004610b7192919061142d565b50600282015481600201559050508080600101915050610a9a565b50600460016004805490500381548110610ba257fe5b9060005260206000209060030201600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000610be891906114b4565b600282016000905550506004805480919060019003610c0791906114fc565b5050565b600060018080805490500381548110610c2057fe5b90600052602060002090600802019050600115158160020160019054906101000a900460ff161515148015610c6457508060020160009054906101000a900460ff16155b610c6d57600080fd5b60008160070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905060008260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000811115610d90573373ffffffffffffffffffffffffffffffffffffffff166108fc836000015483029081150290604051600060405180830381858888f1935050505015610d4857610d8f565b808260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b5b5050565b60036020528060005260406000206000915090505481565b60025481565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610e0057600080fd5b610e0a838361115e565b905092915050565b60048181548110610e1f57fe5b90600052602060002090600302016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ef15780601f10610ec657610100808354040283529160200191610ef1565b820191906000526020600020905b815481529060010190602001808311610ed457829003601f168201915b5050505050908060020154905083565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f7f57600080fd5b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141561102c57600480549050600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506004805480919060010161102991906114fc565b90505b60405180606001604052808473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001428152506004828154811061106a57fe5b906000526020600020906003020160008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010190805190602001906110db92919061152e565b50604082015181600201559050507f27b022af4a8347100c7a041ce5ccf8e14d644ff05de696315196faae8cd50c9b836001604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001821515151581526020019250505060405180910390a1505050565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414156111ac57600080fd5b600180548091906001016111c091906115ae565b90506000600182815481106111d157fe5b90600052602060002090600802019050838160000181905550828160010190805190602001906112029291906115e0565b5060008160020160006101000a81548160ff02191690831515021790555060008160020160016101000a81548160ff021916908315150217905550600081600301819055507ff970aa486598017b8116c2beb18c50d4584ecbc3c688817f59b26796725f31bf82846040518083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156112b0578082015181840152602081019050611295565b50505050905090810190601f1680156112dd5780820380516001836020036101000a031916815260200191505b50935050505060405180910390a1600182016002819055508191505092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461135857600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414156113e857600080fd5b6000600180808054905003815481106113fd57fe5b90600052602060002090600802019050818160020160016101000a81548160ff0219169083151502179055505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061146657805485556114a3565b828001600101855582156114a357600052602060002091601f016020900482015b828111156114a2578254825591600101919060010190611487565b5b5090506114b09190611660565b5090565b50805460018160011615610100020316600290046000825580601f106114da57506114f9565b601f0160209004906000526020600020908101906114f89190611660565b5b50565b815481835581811115611529576003028160030283600052602060002091820191016115289190611685565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061156f57805160ff191683800117855561159d565b8280016001018555821561159d579182015b8281111561159c578251825591602001919060010190611581565b5b5090506115aa9190611660565b5090565b8154818355818111156115db576008028160080283600052602060002091820191016115da91906116e3565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061162157805160ff191683800117855561164f565b8280016001018555821561164f579182015b8281111561164e578251825591602001919060010190611633565b5b50905061165c9190611660565b5090565b61168291905b8082111561167e576000816000905550600101611666565b5090565b90565b6116e091905b808211156116dc57600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006116cb91906114b4565b60028201600090555060030161168b565b5090565b90565b61175f91905b8082111561175b5760008082016000905560018201600061170a91906114b4565b6002820160006101000a81549060ff02191690556002820160016101000a81549060ff0219169055600382016000905560048201600090556005820160006117529190611762565b506008016116e9565b5090565b90565b50805460008255600202906000526020600020908101906117839190611786565b50565b6117ed91905b808211156117e957600080820160006101000a81549060ff02191690556000820160016101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006117e091906114b4565b5060020161178c565b5090565b9056fea265627a7a72315820dab2c528e4480dabb4e56f71d881f0f7d5e0025f206c1bd42f28582b67c1c99a64736f6c63430005110032' + '0xf9182c01f91828b918256080604052600436106100a75760003560e01c80635daf08ca116100645780635daf08ca146105135780638da5cb5b14610601578063c127c24714610658578063ee8ca76e14610740578063f2fde38b14610826578063f602ae2714610877576100a7565b8063013cf08b146102565780630b1ca49a14610335578063373058b814610386578063391068211461039d578063400e39491461040257806358dc93bc1461042d575b6000600180808054905003815481106100bc57fe5b906000526020600020906008020190508060060160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161561012557600080fd5b60018160060160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080600301600081548092919060010191905055506000349050808260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055507fa398b89ba344a0b23a0b9de53db298b2a1a868b396c1878b7e9dcbafecd49b133334604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15050005b34801561026257600080fd5b5061028f6004803603602081101561027957600080fd5b81019080803590602001909291905050506108b4565b60405180878152602001806020018615151515815260200185151515158152602001848152602001838152602001828103825287818151815260200191508051906020019080838360005b838110156102f55780820151818401526020810190506102da565b50505050905090810190601f1680156103225780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b34801561034157600080fd5b506103846004803603602081101561035857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109af565b005b34801561039257600080fd5b5061039b610c0b565b005b3480156103a957600080fd5b506103ec600480360360208110156103c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d94565b6040518082815260200191505060405180910390f35b34801561040e57600080fd5b50610417610dac565b6040518082815260200191505060405180910390f35b34801561043957600080fd5b506104fd6004803603604081101561045057600080fd5b81019080803590602001909291908035906020019064010000000081111561047757600080fd5b82018360208201111561048957600080fd5b803590602001918460018302840111640100000000831117156104ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610db2565b6040518082815260200191505060405180910390f35b34801561051f57600080fd5b5061054c6004803603602081101561053657600080fd5b8101908080359060200190929190505050610e12565b604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b838110156105c45780820151818401526020810190506105a9565b50505050905090810190601f1680156105f15780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561060d57600080fd5b50610616610f01565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561066457600080fd5b5061073e6004803603604081101561067b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001906401000000008111156106b857600080fd5b8201836020820111156106ca57600080fd5b803590602001918460018302840111640100000000831117156106ec57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610f26565b005b34801561074c57600080fd5b506108106004803603604081101561076357600080fd5b81019080803590602001909291908035906020019064010000000081111561078a57600080fd5b82018360208201111561079c57600080fd5b803590602001918460018302840111640100000000831117156107be57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061115e565b6040518082815260200191505060405180910390f35b34801561083257600080fd5b506108756004803603602081101561084957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112ff565b005b34801561088357600080fd5b506108b26004803603602081101561089a57600080fd5b8101908080351515906020019092919050505061139b565b005b600181815481106108c157fe5b9060005260206000209060080201600091509050806000015490806001018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109735780601f1061094857610100808354040283529160200191610973565b820191906000526020600020905b81548152906001019060200180831161095657829003601f168201915b5050505050908060020160009054906101000a900460ff16908060020160019054906101000a900460ff16908060030154908060040154905086565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610a0857600080fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610a5557600080fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490505b600160048054905003811015610b8c5760046001820181548110610aba57fe5b906000526020600020906003020160048281548110610ad557fe5b90600052602060002090600302016000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018201816001019080546001816001161561010002031660029004610b7192919061142d565b50600282015481600201559050508080600101915050610a9a565b50600460016004805490500381548110610ba257fe5b9060005260206000209060030201600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000610be891906114b4565b600282016000905550506004805480919060019003610c0791906114fc565b5050565b600060018080805490500381548110610c2057fe5b90600052602060002090600802019050600115158160020160019054906101000a900460ff161515148015610c6457508060020160009054906101000a900460ff16155b610c6d57600080fd5b60008160070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905060008260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000811115610d90573373ffffffffffffffffffffffffffffffffffffffff166108fc836000015483029081150290604051600060405180830381858888f1935050505015610d4857610d8f565b808260070160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b5b5050565b60036020528060005260406000206000915090505481565b60025481565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610e0057600080fd5b610e0a838361115e565b905092915050565b60048181548110610e1f57fe5b90600052602060002090600302016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690806001018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ef15780601f10610ec657610100808354040283529160200191610ef1565b820191906000526020600020905b815481529060010190602001808311610ed457829003601f168201915b5050505050908060020154905083565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f7f57600080fd5b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141561102c57600480549050600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506004805480919060010161102991906114fc565b90505b60405180606001604052808473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001428152506004828154811061106a57fe5b906000526020600020906003020160008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010190805190602001906110db92919061152e565b50604082015181600201559050507f27b022af4a8347100c7a041ce5ccf8e14d644ff05de696315196faae8cd50c9b836001604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001821515151581526020019250505060405180910390a1505050565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414156111ac57600080fd5b600180548091906001016111c091906115ae565b90506000600182815481106111d157fe5b90600052602060002090600802019050838160000181905550828160010190805190602001906112029291906115e0565b5060008160020160006101000a81548160ff02191690831515021790555060008160020160016101000a81548160ff021916908315150217905550600081600301819055507ff970aa486598017b8116c2beb18c50d4584ecbc3c688817f59b26796725f31bf82846040518083815260200180602001828103825283818151815260200191508051906020019080838360005b838110156112b0578082015181840152602081019050611295565b50505050905090810190601f1680156112dd5780820380516001836020036101000a031916815260200191505b50935050505060405180910390a1600182016002819055508191505092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461135857600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414156113e857600080fd5b6000600180808054905003815481106113fd57fe5b90600052602060002090600802019050818160020160016101000a81548160ff0219169083151502179055505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061146657805485556114a3565b828001600101855582156114a357600052602060002091601f016020900482015b828111156114a2578254825591600101919060010190611487565b5b5090506114b09190611660565b5090565b50805460018160011615610100020316600290046000825580601f106114da57506114f9565b601f0160209004906000526020600020908101906114f89190611660565b5b50565b815481835581811115611529576003028160030283600052602060002091820191016115289190611685565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061156f57805160ff191683800117855561159d565b8280016001018555821561159d579182015b8281111561159c578251825591602001919060010190611581565b5b5090506115aa9190611660565b5090565b8154818355818111156115db576008028160080283600052602060002091820191016115da91906116e3565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061162157805160ff191683800117855561164f565b8280016001018555821561164f579182015b8281111561164e578251825591602001919060010190611633565b5b50905061165c9190611660565b5090565b61168291905b8082111561167e576000816000905550600101611666565b5090565b90565b6116e091905b808211156116dc57600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006116cb91906114b4565b60028201600090555060030161168b565b5090565b90565b61175f91905b8082111561175b5760008082016000905560018201600061170a91906114b4565b6002820160006101000a81549060ff02191690556002820160016101000a81549060ff0219169055600382016000905560048201600090556005820160006117529190611762565b506008016116e9565b5090565b90565b50805460008255600202906000526020600020908101906117839190611786565b50565b6117ed91905b808211156117e957600080820160006101000a81549060ff02191690556000820160016101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006117e091906114b4565b5060020161178c565b5090565b9056fea265627a7a72315820dab2c528e4480dabb4e56f71d881f0f7d5e0025f206c1bd42f28582b67c1c99a64736f6c63430005110032' // captured from a client that was fully synced up to block number 2023946 on the Sepolia network // const getTrieNodesResult = await peer!.snap!.getTrieNodes({ @@ -577,6 +590,6 @@ const byteCodesRLP = // bytes: BigInt(5000000), // }) const _getTrieNodesRLP = - 'eb01a0aa3cd09df0b7c0efbd473200c6db3117b51b68af7a5523334db0208d05e1729ec4c180c180834c4b40' + '0xeb01a0aa3cd09df0b7c0efbd473200c6db3117b51b68af7a5523334db0208d05e1729ec4c180c180834c4b40' const trieNodesRLP = - 'f9043201f9042eb90214f90211a0a9ac33b1678bc29752428899dfdf20b68e681beabb147911ab3351bf5ad54d16a08771055e79da516f30ef2093acf2563a207353c9d189e4f03e0eff738bf555aca007d50972296a3141479449190f74f9594ffd26b279152c0d7a6a63507e6b9089a03f660f0caadd7931c779f36d48fdd23a97f3fb7cc2bf4d429dc2831c16ce5a32a05b97aaa9eb2aae115307d72688bb30a6ebac972ec6ba2d0bcb791ebf39d71916a010e1e7f29a5c06fc555582a970c71ef88c232efaf2ca51a2d49324616c2191a4a0c9505973461d0fe37936edfa00848f149b493c1ebdf3f17708fc6e08d2190324a00a95b5e4f0c4c50ce8be1bd0adca7db282837232cbc1fe3d75afee0fd31f32d3a0e704bcf809216973e3da205dfc2e8e0b0143dc2ca6746e0e7b65a6f88ef74e8ea0f4ed296b1dd56c26bab94eb29a8bdfba97df2df998f68425022435e4d1fb4ec0a02cc04a4870d97146d7c03f87ef1c6bc339027ea2cb63f15518f947b8662e5527a03e011d662ed4d68bf73a790d07e7fe4298a3f92488ccb5486888d972490f4c13a0eba9aa90bef59f1928fd7f864ec1b04155f0c979cf3fa43b4c46c0a973c95f56a0ff8a97113f81de7b80c90593dcac9637d7eb233f8b7fa7d2cabc05c4ae73af8da03c056af73e3d12557d1a93dd777326dc91e4e9bb30e0376cdf931169ba0659aaa0c6e6bc9f45fe9996716c3bdde66f89008ab614bb64e7f7f2e17795530c7d5a1d80b90214f90211a0a9ac33b1678bc29752428899dfdf20b68e681beabb147911ab3351bf5ad54d16a08771055e79da516f30ef2093acf2563a207353c9d189e4f03e0eff738bf555aca007d50972296a3141479449190f74f9594ffd26b279152c0d7a6a63507e6b9089a03f660f0caadd7931c779f36d48fdd23a97f3fb7cc2bf4d429dc2831c16ce5a32a05b97aaa9eb2aae115307d72688bb30a6ebac972ec6ba2d0bcb791ebf39d71916a010e1e7f29a5c06fc555582a970c71ef88c232efaf2ca51a2d49324616c2191a4a0c9505973461d0fe37936edfa00848f149b493c1ebdf3f17708fc6e08d2190324a00a95b5e4f0c4c50ce8be1bd0adca7db282837232cbc1fe3d75afee0fd31f32d3a0e704bcf809216973e3da205dfc2e8e0b0143dc2ca6746e0e7b65a6f88ef74e8ea0f4ed296b1dd56c26bab94eb29a8bdfba97df2df998f68425022435e4d1fb4ec0a02cc04a4870d97146d7c03f87ef1c6bc339027ea2cb63f15518f947b8662e5527a03e011d662ed4d68bf73a790d07e7fe4298a3f92488ccb5486888d972490f4c13a0eba9aa90bef59f1928fd7f864ec1b04155f0c979cf3fa43b4c46c0a973c95f56a0ff8a97113f81de7b80c90593dcac9637d7eb233f8b7fa7d2cabc05c4ae73af8da03c056af73e3d12557d1a93dd777326dc91e4e9bb30e0376cdf931169ba0659aaa0c6e6bc9f45fe9996716c3bdde66f89008ab614bb64e7f7f2e17795530c7d5a1d80' + '0xf9043201f9042eb90214f90211a0a9ac33b1678bc29752428899dfdf20b68e681beabb147911ab3351bf5ad54d16a08771055e79da516f30ef2093acf2563a207353c9d189e4f03e0eff738bf555aca007d50972296a3141479449190f74f9594ffd26b279152c0d7a6a63507e6b9089a03f660f0caadd7931c779f36d48fdd23a97f3fb7cc2bf4d429dc2831c16ce5a32a05b97aaa9eb2aae115307d72688bb30a6ebac972ec6ba2d0bcb791ebf39d71916a010e1e7f29a5c06fc555582a970c71ef88c232efaf2ca51a2d49324616c2191a4a0c9505973461d0fe37936edfa00848f149b493c1ebdf3f17708fc6e08d2190324a00a95b5e4f0c4c50ce8be1bd0adca7db282837232cbc1fe3d75afee0fd31f32d3a0e704bcf809216973e3da205dfc2e8e0b0143dc2ca6746e0e7b65a6f88ef74e8ea0f4ed296b1dd56c26bab94eb29a8bdfba97df2df998f68425022435e4d1fb4ec0a02cc04a4870d97146d7c03f87ef1c6bc339027ea2cb63f15518f947b8662e5527a03e011d662ed4d68bf73a790d07e7fe4298a3f92488ccb5486888d972490f4c13a0eba9aa90bef59f1928fd7f864ec1b04155f0c979cf3fa43b4c46c0a973c95f56a0ff8a97113f81de7b80c90593dcac9637d7eb233f8b7fa7d2cabc05c4ae73af8da03c056af73e3d12557d1a93dd777326dc91e4e9bb30e0376cdf931169ba0659aaa0c6e6bc9f45fe9996716c3bdde66f89008ab614bb64e7f7f2e17795530c7d5a1d80b90214f90211a0a9ac33b1678bc29752428899dfdf20b68e681beabb147911ab3351bf5ad54d16a08771055e79da516f30ef2093acf2563a207353c9d189e4f03e0eff738bf555aca007d50972296a3141479449190f74f9594ffd26b279152c0d7a6a63507e6b9089a03f660f0caadd7931c779f36d48fdd23a97f3fb7cc2bf4d429dc2831c16ce5a32a05b97aaa9eb2aae115307d72688bb30a6ebac972ec6ba2d0bcb791ebf39d71916a010e1e7f29a5c06fc555582a970c71ef88c232efaf2ca51a2d49324616c2191a4a0c9505973461d0fe37936edfa00848f149b493c1ebdf3f17708fc6e08d2190324a00a95b5e4f0c4c50ce8be1bd0adca7db282837232cbc1fe3d75afee0fd31f32d3a0e704bcf809216973e3da205dfc2e8e0b0143dc2ca6746e0e7b65a6f88ef74e8ea0f4ed296b1dd56c26bab94eb29a8bdfba97df2df998f68425022435e4d1fb4ec0a02cc04a4870d97146d7c03f87ef1c6bc339027ea2cb63f15518f947b8662e5527a03e011d662ed4d68bf73a790d07e7fe4298a3f92488ccb5486888d972490f4c13a0eba9aa90bef59f1928fd7f864ec1b04155f0c979cf3fa43b4c46c0a973c95f56a0ff8a97113f81de7b80c90593dcac9637d7eb233f8b7fa7d2cabc05c4ae73af8da03c056af73e3d12557d1a93dd777326dc91e4e9bb30e0376cdf931169ba0659aaa0c6e6bc9f45fe9996716c3bdde66f89008ab614bb64e7f7f2e17795530c7d5a1d80' diff --git a/packages/client/test/net/server/rlpxserver.spec.ts b/packages/client/test/net/server/rlpxserver.spec.ts index 1ebafedc45..654ba98e5b 100644 --- a/packages/client/test/net/server/rlpxserver.spec.ts +++ b/packages/client/test/net/server/rlpxserver.spec.ts @@ -1,4 +1,4 @@ -import { equalsBytes, hexStringToBytes, utf8ToBytes } from '@ethereumjs/util' +import { equalsBytes, prefixedHexStringToBytes, utf8ToBytes } from '@ethereumjs/util' import { EventEmitter } from 'events' import { multiaddr } from 'multiaddr' import tape from 'tape' @@ -52,7 +52,7 @@ tape('[RlpxServer]', async (t) => { key: 'abcd', }) t.equals(server.name, 'rlpx', 'get name') - t.ok(equalsBytes(server.key!, hexStringToBytes('abcd')), 'key parse') + t.ok(equalsBytes(server.key!, prefixedHexStringToBytes('0xabcd')), 'key parse') t.deepEquals( server.bootnodes, [multiaddr('/ip4/10.0.0.1/tcp/1234'), multiaddr('/ip4/10.0.0.2/tcp/1234')], @@ -128,7 +128,7 @@ tape('[RlpxServer]', async (t) => { ;(server as any).rlpx = td.object({ destroy: td.func(), }) - server.rlpx!._id = hexStringToBytes(mockId) + server.rlpx!._id = prefixedHexStringToBytes('0x' + mockId) td.when( server.dpt!.bootstrap({ address: '10.0.0.1', udpPort: 1234, tcpPort: 1234 }) ).thenResolve(undefined) @@ -172,7 +172,7 @@ tape('[RlpxServer]', async (t) => { ;(server as any).rlpx = td.object({ destroy: td.func(), }) - server.rlpx!._id = hexStringToBytes(mockId) + server.rlpx!._id = prefixedHexStringToBytes('0x' + mockId) td.when( server.dpt!.bootstrap({ address: '10.0.0.1', udpPort: 1234, tcpPort: 1234 }) ).thenResolve(undefined) @@ -261,7 +261,7 @@ tape('[RlpxServer]', async (t) => { ;(server as any).peers.set('01', { id: '01' } as any) server.rlpx!.emit('peer:removed', rlpxPeer) server.rlpx!.emit('peer:error', rlpxPeer, new Error('err0')) - server.rlpx!._id = hexStringToBytes('ff') + server.rlpx!._id = prefixedHexStringToBytes('0xff') server.rlpx!.emit('listening') }) diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts index 62bd603ad7..552313e312 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts @@ -6,7 +6,7 @@ import { Account, Address, bytesToPrefixedHexString, - hexStringToBytes, + prefixedHexStringToBytes, randomBytes, } from '@ethereumjs/util' import tape from 'tape' @@ -47,7 +47,9 @@ tape(`${method}: call with valid parameters`, async (t) => { hardfork: Hardfork.Cancun, }) common.setHardfork(Hardfork.Cancun) - const pkey = hexStringToBytes('9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355') + const pkey = prefixedHexStringToBytes( + '0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355' + ) const address = Address.fromPrivateKey(pkey) await service.execution.vm.stateManager.putAccount(address, new Account()) const account = await service.execution.vm.stateManager.getAccount(address) @@ -137,7 +139,9 @@ tape(`${method}: call with valid parameters on pre-Shanghai block`, async (t) => } ) common.setHardfork(Hardfork.London) - const pkey = hexStringToBytes('9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355') + const pkey = prefixedHexStringToBytes( + '0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355' + ) const address = Address.fromPrivateKey(pkey) await service.execution.vm.stateManager.putAccount(address, new Account()) const account = await service.execution.vm.stateManager.getAccount(address) diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts index b9b782b2ef..6fd9fbfc3b 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts @@ -2,7 +2,12 @@ import { Block, BlockHeader } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { TransactionFactory } from '@ethereumjs/tx' -import { Account, Address, bytesToPrefixedHexString, hexStringToBytes } from '@ethereumjs/util' +import { + Account, + Address, + bytesToPrefixedHexString, + prefixedHexStringToBytes, +} from '@ethereumjs/util' import tape from 'tape' import { INVALID_PARAMS, TOO_LARGE_REQUEST } from '../../../src/rpc/error-code' @@ -50,7 +55,9 @@ tape(`${method}: call with valid parameters`, async (t) => { hardfork: Hardfork.Cancun, }) common.setHardfork(Hardfork.Cancun) - const pkey = hexStringToBytes('9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355') + const pkey = prefixedHexStringToBytes( + '0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355' + ) const address = Address.fromPrivateKey(pkey) await service.execution.vm.stateManager.putAccount(address, new Account()) const account = await service.execution.vm.stateManager.getAccount(address) @@ -143,7 +150,9 @@ tape(`${method}: call with valid parameters on pre-Shanghai hardfork`, async (t) hardfork: Hardfork.London, }) common.setHardfork(Hardfork.London) - const pkey = hexStringToBytes('9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355') + const pkey = prefixedHexStringToBytes( + '0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355' + ) const address = Address.fromPrivateKey(pkey) await service.execution.vm.stateManager.putAccount(address, new Account()) const account = await service.execution.vm.stateManager.getAccount(address) diff --git a/packages/client/test/rpc/engine/getPayloadV3.spec.ts b/packages/client/test/rpc/engine/getPayloadV3.spec.ts index 10ac104a89..2dadb1fd82 100644 --- a/packages/client/test/rpc/engine/getPayloadV3.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadV3.spec.ts @@ -9,8 +9,8 @@ import { bytesToPrefixedHexString, commitmentsToVersionedHashes, getBlobs, - hexStringToBytes, initKZG, + prefixedHexStringToBytes, } from '@ethereumjs/util' import kzg from 'c-kzg' import tape from 'tape' @@ -74,7 +74,9 @@ tape(`${method}: call with known payload`, async (t) => { hardfork: Hardfork.Cancun, }) common.setHardfork(Hardfork.Cancun) - const pkey = hexStringToBytes('9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355') + const pkey = prefixedHexStringToBytes( + '0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355' + ) const address = Address.fromPrivateKey(pkey) await service.execution.vm.stateManager.putAccount(address, new Account()) const account = await service.execution.vm.stateManager.getAccount(address) diff --git a/packages/client/test/rpc/engine/newPayloadV1.spec.ts b/packages/client/test/rpc/engine/newPayloadV1.spec.ts index 2c7eca91a2..9eecda7110 100644 --- a/packages/client/test/rpc/engine/newPayloadV1.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV1.spec.ts @@ -1,6 +1,11 @@ import { BlockHeader } from '@ethereumjs/block' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' -import { Address, bytesToPrefixedHexString, hexStringToBytes, zeros } from '@ethereumjs/util' +import { + Address, + bytesToPrefixedHexString, + prefixedHexStringToBytes, + zeros, +} from '@ethereumjs/util' import tape from 'tape' import td from 'testdouble' @@ -220,8 +225,8 @@ tape(`${method}: call with valid data & valid transaction but not signed`, async }) tape(`${method}: call with valid data & valid transaction`, async (t) => { - const accountPk = hexStringToBytes( - 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' + const accountPk = prefixedHexStringToBytes( + '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' ) const accountAddress = Address.fromPrivateKey(accountPk) const newGenesisJSON = { diff --git a/packages/client/test/rpc/engine/newPayloadV2.spec.ts b/packages/client/test/rpc/engine/newPayloadV2.spec.ts index 5aa4a8519c..9ffa501a5d 100644 --- a/packages/client/test/rpc/engine/newPayloadV2.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV2.spec.ts @@ -1,6 +1,11 @@ import { BlockHeader } from '@ethereumjs/block' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' -import { Address, bytesToPrefixedHexString, hexStringToBytes, zeros } from '@ethereumjs/util' +import { + Address, + bytesToPrefixedHexString, + prefixedHexStringToBytes, + zeros, +} from '@ethereumjs/util' import tape from 'tape' import td from 'testdouble' @@ -216,8 +221,8 @@ tape(`${method}: call with executionPayloadV1`, (v1) => { }) v1.test(`${method}: call with valid data & valid transaction`, async (t) => { - const accountPk = hexStringToBytes( - 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' + const accountPk = prefixedHexStringToBytes( + '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' ) const accountAddress = Address.fromPrivateKey(accountPk) const newGenesisJSON = { diff --git a/packages/client/test/rpc/engine/newPayloadV3.spec.ts b/packages/client/test/rpc/engine/newPayloadV3.spec.ts index 6fdbf02093..8d0d049682 100644 --- a/packages/client/test/rpc/engine/newPayloadV3.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV3.spec.ts @@ -1,6 +1,11 @@ import { BlockHeader } from '@ethereumjs/block' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' -import { Address, bytesToPrefixedHexString, hexStringToBytes, zeros } from '@ethereumjs/util' +import { + Address, + bytesToPrefixedHexString, + prefixedHexStringToBytes, + zeros, +} from '@ethereumjs/util' import tape from 'tape' import td from 'testdouble' @@ -216,8 +221,8 @@ tape(`${method}: call with executionPayloadV1`, (v1) => { }) v1.test(`${method}: call with valid data & valid transaction`, async (t) => { - const accountPk = hexStringToBytes( - 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' + const accountPk = prefixedHexStringToBytes( + '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' ) const accountAddress = Address.fromPrivateKey(accountPk) const newGenesisJSON = { diff --git a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts index c4ca549eb8..824e0c4fea 100644 --- a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts +++ b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts @@ -1,6 +1,6 @@ import { Block } from '@ethereumjs/block' import { LegacyTransaction } from '@ethereumjs/tx' -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import { INVALID_PARAMS } from '../../../src/rpc/error-code' @@ -11,11 +11,11 @@ const mockedTx1 = LegacyTransaction.fromTxData({}).sign(dummy.privKey) const mockedTx2 = LegacyTransaction.fromTxData({ nonce: 1 }).sign(dummy.privKey) function createChain() { - const genesisBlockHash = hexStringToBytes( - 'dcf93da321b27bca12087d6526d2c10540a4c8dc29db1b36610c3004e0e5d2d5' + const genesisBlockHash = prefixedHexStringToBytes( + '0xdcf93da321b27bca12087d6526d2c10540a4c8dc29db1b36610c3004e0e5d2d5' ) - const blockHash = hexStringToBytes( - 'dcf93da321b27bca12087d6526d2c10540a4c8dc29db1b36610c3004e0e5d2d5' + const blockHash = prefixedHexStringToBytes( + '0xdcf93da321b27bca12087d6526d2c10540a4c8dc29db1b36610c3004e0e5d2d5' ) const transactions = [mockedTx1] const transactions2 = [mockedTx2] diff --git a/packages/client/test/rpc/eth/getLogs.spec.ts b/packages/client/test/rpc/eth/getLogs.spec.ts index 4d917372a1..c02c83345b 100644 --- a/packages/client/test/rpc/eth/getLogs.spec.ts +++ b/packages/client/test/rpc/eth/getLogs.spec.ts @@ -1,5 +1,5 @@ import { LegacyTransaction } from '@ethereumjs/tx' -import { Address, bytesToPrefixedHexString, hexStringToBytes } from '@ethereumjs/util' +import { Address, bytesToPrefixedHexString, prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import { INVALID_PARAMS } from '../../../src/rpc/error-code' @@ -23,8 +23,8 @@ const method = 'eth_getLogs' } ``` */ -const logExampleBytecode = hexStringToBytes( - '608060405234801561001057600080fd5b50610257806100206000396000f3fe608060405234801561001057600080fd5b5060043610610048576000357c010000000000000000000000000000000000000000000000000000000090048063aefb4f0a1461004d575b600080fd5b610067600480360381019061006291906100de565b610069565b005b60005b858110156100c1578284867fbf642f3055e2ef2589825c2c0dd4855c1137a63f6260d9d112629e5cd034a3eb856040516100a69190610168565b60405180910390a480806100b99061018d565b91505061006c565b505050505050565b6000813590506100d88161020a565b92915050565b600080600080600060a086880312156100fa576100f9610205565b5b6000610108888289016100c9565b9550506020610119888289016100c9565b945050604061012a888289016100c9565b935050606061013b888289016100c9565b925050608061014c888289016100c9565b9150509295509295909350565b61016281610183565b82525050565b600060208201905061017d6000830184610159565b92915050565b6000819050919050565b600061019882610183565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156101cb576101ca6101d6565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b61021381610183565b811461021e57600080fd5b5056fea2646970667358221220b98f45f4d4112e71fd287ab0ce7cc1872e53b463eb0abf1182b892192d3d8a1d64736f6c63430008070033' +const logExampleBytecode = prefixedHexStringToBytes( + '0x608060405234801561001057600080fd5b50610257806100206000396000f3fe608060405234801561001057600080fd5b5060043610610048576000357c010000000000000000000000000000000000000000000000000000000090048063aefb4f0a1461004d575b600080fd5b610067600480360381019061006291906100de565b610069565b005b60005b858110156100c1578284867fbf642f3055e2ef2589825c2c0dd4855c1137a63f6260d9d112629e5cd034a3eb856040516100a69190610168565b60405180910390a480806100b99061018d565b91505061006c565b505050505050565b6000813590506100d88161020a565b92915050565b600080600080600060a086880312156100fa576100f9610205565b5b6000610108888289016100c9565b9550506020610119888289016100c9565b945050604061012a888289016100c9565b935050606061013b888289016100c9565b925050608061014c888289016100c9565b9150509295509295909350565b61016281610183565b82525050565b600060208201905061017d6000830184610159565b92915050565b6000819050919050565b600061019882610183565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156101cb576101ca6101d6565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b61021381610183565b811461021e57600080fd5b5056fea2646970667358221220b98f45f4d4112e71fd287ab0ce7cc1872e53b463eb0abf1182b892192d3d8a1d64736f6c63430008070033' ) tape(`${method}: call with valid arguments`, async (t) => { @@ -53,8 +53,8 @@ tape(`${method}: call with valid arguments`, async (t) => { const contractAddr2 = Address.generate(dummy.addr, BigInt(1)) // construct txs to emit the logs // data calls log(logCount: 10, num1: 1, num2: 2, num3: 3, num4: 4) - const data = hexStringToBytes( - 'aefb4f0a000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004' + const data = prefixedHexStringToBytes( + '0xaefb4f0a000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004' ) const tx3 = LegacyTransaction.fromTxData( { diff --git a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts index c91042bd93..7e81f0b509 100644 --- a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts +++ b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts @@ -12,8 +12,8 @@ import { bytesToPrefixedHexString, commitmentsToVersionedHashes, getBlobs, - hexStringToBytes, initKZG, + prefixedHexStringToBytes, randomBytes, } from '@ethereumjs/util' import kzg from 'c-kzg' @@ -48,7 +48,7 @@ tape(`${method}: call with valid arguments`, async (t) => { // Mainnet EIP-1559 tx const txData = '0x02f90108018001018402625a0094cccccccccccccccccccccccccccccccccccccccc830186a0b8441a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85bf859940000000000000000000000000000000000000101f842a00000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000060a701a0afb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9a0479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64' - const transaction = FeeMarketEIP1559Transaction.fromSerializedTx(hexStringToBytes(txData)) + const transaction = FeeMarketEIP1559Transaction.fromSerializedTx(prefixedHexStringToBytes(txData)) const address = transaction.getSenderAddress() const vm = (client.services.find((s) => s.name === 'eth') as FullEthereumService).execution.vm @@ -83,7 +83,7 @@ tape(`${method}: send local tx with gasprice lower than minimum`, async (t) => { gasLimit: 21000, gasPrice: 0, nonce: 0, - }).sign(hexStringToBytes('42'.repeat(32))) + }).sign(prefixedHexStringToBytes('0x' + '42'.repeat(32))) const txData = bytesToPrefixedHexString(transaction.serialize()) @@ -158,7 +158,7 @@ tape(`${method}: call with unsigned tx`, async (t) => { const txData = '0x02f90108018001018402625a0094cccccccccccccccccccccccccccccccccccccccc830186a0b8441a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85bf859940000000000000000000000000000000000000101f842a00000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000060a701a0afb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9a0479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64' const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const tx = FeeMarketEIP1559Transaction.fromSerializedTx(hexStringToBytes(txData), { + const tx = FeeMarketEIP1559Transaction.fromSerializedTx(prefixedHexStringToBytes(txData), { common, freeze: false, }) @@ -193,7 +193,7 @@ tape(`${method}: call with no peers`, async (t) => { // Mainnet EIP-1559 tx const txData = '0x02f90108018001018402625a0094cccccccccccccccccccccccccccccccccccccccc830186a0b8441a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85bf859940000000000000000000000000000000000000101f842a00000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000060a701a0afb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9a0479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64' - const transaction = FeeMarketEIP1559Transaction.fromSerializedTx(hexStringToBytes(txData)) + const transaction = FeeMarketEIP1559Transaction.fromSerializedTx(prefixedHexStringToBytes(txData)) const address = transaction.getSenderAddress() const vm = (client.services.find((s) => s.name === 'eth') as FullEthereumService).execution.vm diff --git a/packages/client/test/rpc/helpers.ts b/packages/client/test/rpc/helpers.ts index 6cdf442d11..579f9fb42c 100644 --- a/packages/client/test/rpc/helpers.ts +++ b/packages/client/test/rpc/helpers.ts @@ -1,7 +1,12 @@ import { BlockHeader } from '@ethereumjs/block' import { Blockchain } from '@ethereumjs/blockchain' import { Chain as ChainEnum, Common, parseGethGenesis } from '@ethereumjs/common' -import { Address, KECCAK256_RLP, hexStringToBytes, parseGethGenesisState } from '@ethereumjs/util' +import { + Address, + KECCAK256_RLP, + parseGethGenesisState, + prefixedHexStringToBytes, +} from '@ethereumjs/util' import { Server as RPCServer } from 'jayson/promise' import { MemoryLevel } from 'memory-level' @@ -312,6 +317,8 @@ export function gethGenesisStartLondon(gethGenesis: any) { * This address has preallocated balance in file `testdata/geth-genesis/pow.json` */ export const dummy = { - addr: new Address(hexStringToBytes('0xcde098d93535445768e8a2345a2f869139f45641')), - privKey: hexStringToBytes('5831aac354d13ff96a0c051af0d44c0931c2a20bdacee034ffbaa2354d84f5f8'), + addr: new Address(prefixedHexStringToBytes('0xcde098d93535445768e8a2345a2f869139f45641')), + privKey: prefixedHexStringToBytes( + '0x5831aac354d13ff96a0c051af0d44c0931c2a20bdacee034ffbaa2354d84f5f8' + ), } diff --git a/packages/client/test/service/fullethereumservice.spec.ts b/packages/client/test/service/fullethereumservice.spec.ts index d6304cf484..ea63d66c14 100644 --- a/packages/client/test/service/fullethereumservice.spec.ts +++ b/packages/client/test/service/fullethereumservice.spec.ts @@ -1,6 +1,6 @@ import { Common, Hardfork } from '@ethereumjs/common' import { TransactionFactory, TransactionType } from '@ethereumjs/tx' -import { hexStringToBytes, randomBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes, randomBytes } from '@ethereumjs/util' import { equalsBytes, hexToBytes } from 'ethereum-cryptography/utils' import tape from 'tape' import td from 'testdouble' @@ -294,7 +294,7 @@ tape('[FullEthereumService]', async (t) => { const chain = await Chain.create({ config }) const service = new FullEthereumService({ config, chain }) service.txPool.handleAnnouncedTxHashes = async (msg, _peer, _pool) => { - st.deepEqual(msg[0], hexStringToBytes('0xabcd'), 'handled NewPooledTransactionhashes') + st.deepEqual(msg[0], prefixedHexStringToBytes('0xabcd'), 'handled NewPooledTransactionhashes') st.end() } diff --git a/packages/client/test/sim/4844devnet5.spec.ts b/packages/client/test/sim/4844devnet5.spec.ts index 5e3af870e3..273ab87740 100644 --- a/packages/client/test/sim/4844devnet5.spec.ts +++ b/packages/client/test/sim/4844devnet5.spec.ts @@ -1,5 +1,9 @@ import { Common } from '@ethereumjs/common' -import { bytesToPrefixedHexString, hexStringToBytes, privateToAddress } from '@ethereumjs/util' +import { + bytesToPrefixedHexString, + prefixedHexStringToBytes, + privateToAddress, +} from '@ethereumjs/util' import { Client } from 'jayson/promise' import { randomBytes } from 'node:crypto' import tape from 'tape' @@ -13,8 +17,8 @@ import { waitForELStart, } from './simutils' -const pkey = hexStringToBytes( - process.env.PRIVATE_KEY ?? 'ae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' +const pkey = prefixedHexStringToBytes( + process.env.PRIVATE_KEY ?? '0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' ) const sender = bytesToPrefixedHexString(privateToAddress(pkey)) const rpcUrl = diff --git a/packages/client/test/sim/eof.spec.ts b/packages/client/test/sim/eof.spec.ts index 0ff5be4a74..fc14510c8f 100644 --- a/packages/client/test/sim/eof.spec.ts +++ b/packages/client/test/sim/eof.spec.ts @@ -1,5 +1,9 @@ import { Common } from '@ethereumjs/common' -import { bytesToPrefixedHexString, hexStringToBytes, privateToAddress } from '@ethereumjs/util' +import { + bytesToPrefixedHexString, + prefixedHexStringToBytes, + privateToAddress, +} from '@ethereumjs/util' import { Client } from 'jayson/promise' import tape from 'tape' @@ -11,7 +15,9 @@ import { waitForELStart, } from './simutils' -const pkey = hexStringToBytes('ae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e') +const pkey = prefixedHexStringToBytes( + '0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' +) const sender = bytesToPrefixedHexString(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) diff --git a/packages/client/test/sim/mainnet.spec.ts b/packages/client/test/sim/mainnet.spec.ts index 63d36fd1d9..ebd8783c82 100644 --- a/packages/client/test/sim/mainnet.spec.ts +++ b/packages/client/test/sim/mainnet.spec.ts @@ -1,5 +1,9 @@ import { Common } from '@ethereumjs/common' -import { bytesToPrefixedHexString, hexStringToBytes, privateToAddress } from '@ethereumjs/util' +import { + bytesToPrefixedHexString, + prefixedHexStringToBytes, + privateToAddress, +} from '@ethereumjs/util' import { Client } from 'jayson/promise' import tape from 'tape' @@ -12,7 +16,9 @@ import { waitForELStart, } from './simutils' -const pkey = hexStringToBytes('ae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e') +const pkey = prefixedHexStringToBytes( + '0xae557af4ceefda559c924516cabf029bedc36b68109bf8d6183fe96e04121f4e' +) const sender = bytesToPrefixedHexString(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) diff --git a/packages/client/test/sim/sharding.spec.ts b/packages/client/test/sim/sharding.spec.ts index 75e944f56f..ff7f3df0f6 100644 --- a/packages/client/test/sim/sharding.spec.ts +++ b/packages/client/test/sim/sharding.spec.ts @@ -1,6 +1,10 @@ import { Common } from '@ethereumjs/common' import { TransactionFactory } from '@ethereumjs/tx' -import { bytesToPrefixedHexString, hexStringToBytes, privateToAddress } from '@ethereumjs/util' +import { + bytesToPrefixedHexString, + prefixedHexStringToBytes, + privateToAddress, +} from '@ethereumjs/util' import { Client } from 'jayson/promise' import { randomBytes } from 'node:crypto' import tape from 'tape' @@ -16,7 +20,9 @@ import { waitForELStart, } from './simutils' -const pkey = hexStringToBytes('45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') +const pkey = prefixedHexStringToBytes( + '0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8' +) const sender = bytesToPrefixedHexString(privateToAddress(pkey)) const client = Client.http({ port: 8545 }) @@ -162,8 +168,8 @@ tape('sharding/eip4844 hardfork tests', async (t) => { */ const txData = { - data: hexStringToBytes( - 'f9031103830186a0830f42408080b902c0608060405234801561001057600080fd5b50604051610260380380610260833981810160405281019061003291906101ca565b60008060c0835160145afa61004657600080fd5b50610213565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6100b38261006a565b810181811067ffffffffffffffff821117156100d2576100d161007b565b5b80604052505050565b60006100e561004c565b90506100f182826100aa565b919050565b600067ffffffffffffffff8211156101115761011061007b565b5b61011a8261006a565b9050602081019050919050565b60005b8381101561014557808201518184015260208101905061012a565b83811115610154576000848401525b50505050565b600061016d610168846100f6565b6100db565b90508281526020810184848401111561018957610188610065565b5b610194848285610127565b509392505050565b600082601f8301126101b1576101b0610060565b5b81516101c184826020860161015a565b91505092915050565b6000602082840312156101e0576101df610056565b5b600082015167ffffffffffffffff8111156101fe576101fd61005b565b5b61020a8482850161019c565b91505092915050565b603f806102216000396000f3fe6080604052600080fdfea2646970667358221220cbb964afe0f584a89b887bf992e18697c0ebd77a40a102c121f54213f23d4d9464736f6c634300080f00330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000212340000000000000000000000000000000000000000000000000000000000001ba002e89a44a4e4da739fed1ed658079a75dbcb59eebbd8ea0cb11f88a41d611dfaa025fe1645a1d3c9828be471fac5cd3e4be59c90ea304c94d774ff88c84349d8db' + data: prefixedHexStringToBytes( + '0xf9031103830186a0830f42408080b902c0608060405234801561001057600080fd5b50604051610260380380610260833981810160405281019061003291906101ca565b60008060c0835160145afa61004657600080fd5b50610213565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6100b38261006a565b810181811067ffffffffffffffff821117156100d2576100d161007b565b5b80604052505050565b60006100e561004c565b90506100f182826100aa565b919050565b600067ffffffffffffffff8211156101115761011061007b565b5b61011a8261006a565b9050602081019050919050565b60005b8381101561014557808201518184015260208101905061012a565b83811115610154576000848401525b50505050565b600061016d610168846100f6565b6100db565b90508281526020810184848401111561018957610188610065565b5b610194848285610127565b509392505050565b600082601f8301126101b1576101b0610060565b5b81516101c184826020860161015a565b91505092915050565b6000602082840312156101e0576101df610056565b5b600082015167ffffffffffffffff8111156101fe576101fd61005b565b5b61020a8482850161019c565b91505092915050565b603f806102216000396000f3fe6080604052600080fdfea2646970667358221220cbb964afe0f584a89b887bf992e18697c0ebd77a40a102c121f54213f23d4d9464736f6c634300080f00330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000212340000000000000000000000000000000000000000000000000000000000001ba002e89a44a4e4da739fed1ed658079a75dbcb59eebbd8ea0cb11f88a41d611dfaa025fe1645a1d3c9828be471fac5cd3e4be59c90ea304c94d774ff88c84349d8db' ), nonce: BigInt(nonce.result), gasLimit: 0xffffff, diff --git a/packages/client/test/sim/txGenerator.ts b/packages/client/test/sim/txGenerator.ts index 8964b43353..1bda9c8b0f 100644 --- a/packages/client/test/sim/txGenerator.ts +++ b/packages/client/test/sim/txGenerator.ts @@ -5,8 +5,8 @@ import { blobsToCommitments, bytesToPrefixedHexString, commitmentsToVersionedHashes, - hexStringToBytes, initKZG, + prefixedHexStringToBytes, randomBytes, } from '@ethereumjs/util' import kzg from 'c-kzg' @@ -24,7 +24,9 @@ const MAX_USEFUL_BYTES_PER_TX = USEFUL_BYTES_PER_BLOB * MAX_BLOBS_PER_TX - 1 const BLOB_SIZE = BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_BLOB initKZG(kzg, __dirname + '/../../src/trustedSetup/devnet4.txt') -const pkey = hexStringToBytes('45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') +const pkey = prefixedHexStringToBytes( + '0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8' +) const sender = Address.fromPrivateKey(pkey) function get_padded(data: any, blobs_len: number) { @@ -49,7 +51,7 @@ function get_blob(data: any) { // ref: https://github.com/asn-d6/blobbers/blob/packing_benchmarks/src/packer_naive.rs function get_blobs(data: any) { - data = hexStringToBytes(data) + data = prefixedHexStringToBytes(data) const len = (data as Uint8Array).byteLength if (len === 0) { throw Error('invalid blob data') diff --git a/packages/client/test/sync/fetcher/accountfetcher.spec.ts b/packages/client/test/sync/fetcher/accountfetcher.spec.ts index 0d3098978b..11aa0725bb 100644 --- a/packages/client/test/sync/fetcher/accountfetcher.spec.ts +++ b/packages/client/test/sync/fetcher/accountfetcher.spec.ts @@ -1,5 +1,5 @@ import { RLP } from '@ethereumjs/rlp' -import { bytesToBigInt, hexStringToBytes } from '@ethereumjs/util' +import { bytesToBigInt, prefixedHexStringToBytes } from '@ethereumjs/util' import tape from 'tape' import td from 'testdouble' @@ -175,18 +175,24 @@ tape('[AccountFetcher]', async (t) => { const fetcher = new AccountFetcher({ config, pool, - root: hexStringToBytes('39ed8daab7679c0b1b7cf3667c50108185d4d9d1431c24a1c35f696a58277f8f'), + root: prefixedHexStringToBytes( + '0x39ed8daab7679c0b1b7cf3667c50108185d4d9d1431c24a1c35f696a58277f8f' + ), first: bytesToBigInt( - hexStringToBytes('0000000000000000000000000000000000000000000000000000000000000001') + prefixedHexStringToBytes( + '0x0000000000000000000000000000000000000000000000000000000000000001' + ) ), count: bytesToBigInt( - hexStringToBytes('000010c6f7a0b5ed8d36b4c7f34938583621fafc8b0079a2834d26fa3fcc9ea9') + prefixedHexStringToBytes( + '0x000010c6f7a0b5ed8d36b4c7f34938583621fafc8b0079a2834d26fa3fcc9ea9' + ) ), }) t.ok(fetcher.storageFetcher !== undefined, 'storageFetcher should be created') const task = { count: 3, first: BigInt(1) } - const resData = RLP.decode(hexStringToBytes(_accountRangeRLP)) + const resData = RLP.decode(prefixedHexStringToBytes('0x' + _accountRangeRLP)) const { accounts, proof } = p.decode( p.messages.filter((message) => message.name === 'AccountRange')[0], resData diff --git a/packages/client/test/sync/txpool.spec.ts b/packages/client/test/sync/txpool.spec.ts index ba08e24818..c4598a8643 100644 --- a/packages/client/test/sync/txpool.spec.ts +++ b/packages/client/test/sync/txpool.spec.ts @@ -6,7 +6,7 @@ import { Account, bytesToHex, concatBytes, - hexStringToBytes, + prefixedHexStringToBytes, privateToAddress, } from '@ethereumjs/util' import tape from 'tape' @@ -98,16 +98,16 @@ tape('[TxPool]', async (t) => { DefaultStateManager.prototype.setStateRoot = (): any => {} const A = { - address: hexStringToBytes('0b90087d864e82a284dca15923f3776de6bb016f'), - privateKey: hexStringToBytes( - '64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' + address: prefixedHexStringToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f'), + privateKey: prefixedHexStringToBytes( + '0x64bf9cc30328b0e42387b3c82c614e6386259136235e20c1357bd11cdee86993' ), } const B = { - address: hexStringToBytes('6f62d8382bf2587361db73ceca28be91b2acb6df'), - privateKey: hexStringToBytes( - '2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6' + address: prefixedHexStringToBytes('0x6f62d8382bf2587361db73ceca28be91b2acb6df'), + privateKey: prefixedHexStringToBytes( + '0x2a6e9ad5a6a8e4f17149b8bc7128bf090566a11dbd63c30e5a0ee9f161309cd6' ), } @@ -254,7 +254,7 @@ tape('[TxPool]', async (t) => { const hashes = [] for (let i = 1; i <= TX_RETRIEVAL_LIMIT + 1; i++) { // One more than TX_RETRIEVAL_LIMIT - hashes.push(hexStringToBytes(i.toString().padStart(64, '0'))) // '0000000000000000000000000000000000000000000000000000000000000001',... + hashes.push(prefixedHexStringToBytes('0x' + i.toString().padStart(64, '0'))) // '0000000000000000000000000000000000000000000000000000000000000001',... } await pool.handleAnnouncedTxHashes(hashes, peer as any, peerPool) @@ -404,8 +404,8 @@ tape('[TxPool]', async (t) => { const txs = [] for (let account = 0; account < 51; account++) { const pkey = concatBytes( - hexStringToBytes('aa'.repeat(31)), - hexStringToBytes(account.toString(16).padStart(2, '0')) + prefixedHexStringToBytes('0x' + 'aa'.repeat(31)), + prefixedHexStringToBytes('0x' + account.toString(16).padStart(2, '0')) ) const from = { address: privateToAddress(pkey), diff --git a/packages/common/src/common.ts b/packages/common/src/common.ts index 81b8b2d928..4de2b490ab 100644 --- a/packages/common/src/common.ts +++ b/packages/common/src/common.ts @@ -2,8 +2,8 @@ import { TypeOutput, bytesToHex, concatBytes, - hexStringToBytes, intToBytes, + prefixedHexStringToBytes, toType, } from '@ethereumjs/util' import crc from 'crc/crc32' @@ -33,7 +33,7 @@ import type { HardforkByOpts, HardforkConfig, } from './types.js' -import type { BigIntLike } from '@ethereumjs/util' +import type { BigIntLike, PrefixedHexString } from '@ethereumjs/util' type HardforkSpecKeys = keyof typeof HARDFORK_SPECS type HardforkSpecValues = typeof HARDFORK_SPECS[HardforkSpecKeys] @@ -750,7 +750,7 @@ export class Common extends EventEmitter { * @param genesisHash Genesis block hash of the chain * @returns Fork hash as hex string */ - _calcForkHash(hardfork: string | Hardfork, genesisHash: Uint8Array) { + _calcForkHash(hardfork: string | Hardfork, genesisHash: Uint8Array): PrefixedHexString { let hfBytes = new Uint8Array(0) let prevBlockOrTime = 0 for (const hf of this.hardforks()) { @@ -769,7 +769,9 @@ export class Common extends EventEmitter { blockOrTime !== prevBlockOrTime && name !== Hardfork.Paris ) { - const hfBlockBytes = hexStringToBytes(blockOrTime.toString(16).padStart(16, '0')) + const hfBlockBytes = prefixedHexStringToBytes( + '0x' + blockOrTime.toString(16).padStart(16, '0') + ) hfBytes = concatBytes(hfBytes, hfBlockBytes) prevBlockOrTime = blockOrTime } @@ -789,7 +791,7 @@ export class Common extends EventEmitter { * @param hardfork Hardfork name, optional if HF set * @param genesisHash Genesis block hash of the chain, optional if already defined and not needed to be calculated */ - forkHash(hardfork?: string | Hardfork, genesisHash?: Uint8Array): string { + forkHash(hardfork?: string | Hardfork, genesisHash?: Uint8Array): PrefixedHexString { hardfork = hardfork ?? this._hardfork const data = this._getHardfork(hardfork) if ( diff --git a/packages/common/test/hardforks.spec.ts b/packages/common/test/hardforks.spec.ts index 7c7fefb56c..686ec9993c 100644 --- a/packages/common/test/hardforks.spec.ts +++ b/packages/common/test/hardforks.spec.ts @@ -1,4 +1,4 @@ -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Chain, Common, ConsensusAlgorithm, ConsensusType, Hardfork } from '../src/index.js' @@ -203,15 +203,21 @@ describe('[Common]: Hardfork logic', () => { const chains: [Chain, Uint8Array][] = [ [ Chain.Mainnet, - hexStringToBytes('d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'), + prefixedHexStringToBytes( + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' + ), ], [ Chain.Goerli, - hexStringToBytes('bf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a'), + prefixedHexStringToBytes( + '0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a' + ), ], [ Chain.Sepolia, - hexStringToBytes('25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9'), + prefixedHexStringToBytes( + '0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9' + ), ], ] @@ -244,8 +250,8 @@ describe('[Common]: Hardfork logic', () => { msg = 'should provide correct forkHash for HF provided' assert.equal(c.forkHash(Hardfork.SpuriousDragon), '0x3edd5b10', msg) - const genesisHash = hexStringToBytes( - 'd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' + const genesisHash = prefixedHexStringToBytes( + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' ) assert.equal(c.forkHash(Hardfork.SpuriousDragon, genesisHash), '0x3edd5b10', msg) diff --git a/packages/common/test/timestamp.spec.ts b/packages/common/test/timestamp.spec.ts index 343f1c20c1..d78466d463 100644 --- a/packages/common/test/timestamp.spec.ts +++ b/packages/common/test/timestamp.spec.ts @@ -1,4 +1,4 @@ -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Chain, Common, Hardfork } from '../src/index.js' @@ -94,8 +94,8 @@ describe('[Common]: Timestamp Hardfork logic', () => { ]) const c = Common.custom({ hardforks }, { baseChain: Chain.Mainnet }) - const mainnetGenesisHash = hexStringToBytes( - 'd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' + const mainnetGenesisHash = prefixedHexStringToBytes( + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' ) for (const hf of c.hardforks()) { if (typeof hf.forkHash === 'string') { @@ -135,8 +135,8 @@ describe('[Common]: Timestamp Hardfork logic', () => { ]) const c = Common.custom({ hardforks }, { baseChain: Chain.Mainnet }) - const mainnetGenesisHash = hexStringToBytes( - 'd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' + const mainnetGenesisHash = prefixedHexStringToBytes( + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' ) let noForkHashes = c.hardforks().reduce((acc, hf) => { diff --git a/packages/common/test/utils.spec.ts b/packages/common/test/utils.spec.ts index 399b250ee4..8b3a553c7f 100644 --- a/packages/common/test/utils.spec.ts +++ b/packages/common/test/utils.spec.ts @@ -1,4 +1,4 @@ -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Common } from '../src/common' @@ -59,8 +59,8 @@ describe('[Utils/Parse]', () => { it('should successfully parse kiln genesis and set forkhash', async () => { const common = Common.fromGethGenesis(gethGenesisKilnJSON, { chain: 'customChain', - genesisHash: hexStringToBytes( - '51c7fe41be669f69c45c33a56982cbde405313342d9e2b00d7c91a7b284dd4f8' + genesisHash: prefixedHexStringToBytes( + '0x51c7fe41be669f69c45c33a56982cbde405313342d9e2b00d7c91a7b284dd4f8' ), mergeForkIdPostMerge: false, }) diff --git a/packages/evm/test/eips/eip-5656.spec.ts b/packages/evm/test/eips/eip-5656.spec.ts index adc2712277..251656feb0 100644 --- a/packages/evm/test/eips/eip-5656.spec.ts +++ b/packages/evm/test/eips/eip-5656.spec.ts @@ -1,6 +1,6 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' -import { bytesToHex, hexStringToBytes } from '@ethereumjs/util' +import { bytesToHex, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { EVM } from '../../src' @@ -61,7 +61,7 @@ describe('should test mcopy', () => { for (const situation of situations) { it('should produce correct output', async () => { // create bytecode - let bytecode = '' + let bytecode = '0x' // prepare the memory for (let i = 0; i < situation.pre.length / 2; i++) { const start = i * 2 @@ -98,7 +98,7 @@ describe('should test mcopy', () => { }) await evm.runCall({ - data: hexStringToBytes(bytecode), + data: prefixedHexStringToBytes(bytecode), gasLimit: BigInt(0xffffff), }) diff --git a/packages/statemanager/src/cache/storage.ts b/packages/statemanager/src/cache/storage.ts index 200665bdd8..b7877b7b9c 100644 --- a/packages/statemanager/src/cache/storage.ts +++ b/packages/statemanager/src/cache/storage.ts @@ -1,4 +1,4 @@ -import { bytesToHex, hexStringToBytes } from '@ethereumjs/util' +import { bytesToHex, prefixedHexStringToBytes } from '@ethereumjs/util' import { debug as createDebugLogger } from 'debug' import { OrderedMap } from 'js-sdsl' import { LRUCache } from 'lru-cache' @@ -116,7 +116,7 @@ export class StorageCache extends Cache { /** * Returns the queried slot as the RLP encoded storage value - * hexStringToBytes('80'): slot is known to be empty + * prefixedHexStringToBytes('0x80'): slot is known to be empty * undefined: slot is not in cache * @param address - Address of account * @param key - Storage key @@ -159,14 +159,14 @@ export class StorageCache extends Cache { if (!storageMap) { storageMap = new Map() } - storageMap.set(keyHex, hexStringToBytes('80')) + storageMap.set(keyHex, prefixedHexStringToBytes('0x80')) this._lruCache!.set(addressHex, storageMap) } else { let storageMap = this._orderedMapCache!.getElementByKey(addressHex) if (!storageMap) { storageMap = new Map() } - storageMap.set(keyHex, hexStringToBytes('80')) + storageMap.set(keyHex, prefixedHexStringToBytes('0x80')) this._orderedMapCache!.setElement(addressHex, storageMap) } diff --git a/packages/statemanager/src/stateManager.ts b/packages/statemanager/src/stateManager.ts index be35a24c67..26a6b99dd5 100644 --- a/packages/statemanager/src/stateManager.ts +++ b/packages/statemanager/src/stateManager.ts @@ -13,7 +13,7 @@ import { bytesToPrefixedHexString, concatBytes, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, setLengthLeft, short, toBytes, @@ -408,7 +408,7 @@ export class DefaultStateManager implements EVMStateManagerInterface { const trie = await this._getStorageTrie(address, account) const value = await trie.get(key) if (!this._storageCacheSettings.deactivate) { - this._storageCache?.put(address, key, value ?? hexStringToBytes('80')) + this._storageCache?.put(address, key, value ?? prefixedHexStringToBytes('0x80')) } const decoded = RLP.decode(value ?? new Uint8Array(0)) as Uint8Array return decoded @@ -662,10 +662,10 @@ export class DefaultStateManager implements EVMStateManagerInterface { * @param proof the proof to prove */ async verifyProof(proof: Proof): Promise { - const rootHash = keccak256(hexStringToBytes(proof.accountProof[0])) - const key = hexStringToBytes(proof.address) + const rootHash = keccak256(prefixedHexStringToBytes(proof.accountProof[0])) + const key = prefixedHexStringToBytes(proof.address) const accountProof = proof.accountProof.map((rlpString: PrefixedHexString) => - hexStringToBytes(rlpString) + prefixedHexStringToBytes(rlpString) ) // This returns the account if the proof is valid. @@ -676,19 +676,19 @@ export class DefaultStateManager implements EVMStateManagerInterface { // Verify that the account is empty in the proof. const emptyBytes = new Uint8Array(0) const notEmptyErrorMsg = 'Invalid proof provided: account is not empty' - const nonce = unpadBytes(hexStringToBytes(proof.nonce)) + const nonce = unpadBytes(prefixedHexStringToBytes(proof.nonce)) if (!equalsBytes(nonce, emptyBytes)) { throw new Error(`${notEmptyErrorMsg} (nonce is not zero)`) } - const balance = unpadBytes(hexStringToBytes(proof.balance)) + const balance = unpadBytes(prefixedHexStringToBytes(proof.balance)) if (!equalsBytes(balance, emptyBytes)) { throw new Error(`${notEmptyErrorMsg} (balance is not zero)`) } - const storageHash = hexStringToBytes(proof.storageHash) + const storageHash = prefixedHexStringToBytes(proof.storageHash) if (!equalsBytes(storageHash, KECCAK256_RLP)) { throw new Error(`${notEmptyErrorMsg} (storageHash does not equal KECCAK256_RLP)`) } - const codeHash = hexStringToBytes(proof.codeHash) + const codeHash = prefixedHexStringToBytes(proof.codeHash) if (!equalsBytes(codeHash, KECCAK256_NULL)) { throw new Error(`${notEmptyErrorMsg} (codeHash does not equal KECCAK256_NULL)`) } @@ -702,20 +702,22 @@ export class DefaultStateManager implements EVMStateManagerInterface { if (balance !== BigInt(proof.balance)) { throw new Error(`${invalidErrorMsg} balance does not match`) } - if (!equalsBytes(storageRoot, hexStringToBytes(proof.storageHash))) { + if (!equalsBytes(storageRoot, prefixedHexStringToBytes(proof.storageHash))) { throw new Error(`${invalidErrorMsg} storageHash does not match`) } - if (!equalsBytes(codeHash, hexStringToBytes(proof.codeHash))) { + if (!equalsBytes(codeHash, prefixedHexStringToBytes(proof.codeHash))) { throw new Error(`${invalidErrorMsg} codeHash does not match`) } } - const storageRoot = hexStringToBytes(proof.storageHash) + const storageRoot = prefixedHexStringToBytes(proof.storageHash) for (const stProof of proof.storageProof) { - const storageProof = stProof.proof.map((value: PrefixedHexString) => hexStringToBytes(value)) - const storageValue = setLengthLeft(hexStringToBytes(stProof.value), 32) - const storageKey = hexStringToBytes(stProof.key) + const storageProof = stProof.proof.map((value: PrefixedHexString) => + prefixedHexStringToBytes(value) + ) + const storageValue = setLengthLeft(prefixedHexStringToBytes(stProof.value), 32) + const storageKey = prefixedHexStringToBytes(stProof.key) const proofValue = await new Trie({ useKeyHashing: true }).verifyProof( storageRoot, storageKey, diff --git a/packages/statemanager/test/cache/account.spec.ts b/packages/statemanager/test/cache/account.spec.ts index b0fd2457a1..1be6bcefd0 100644 --- a/packages/statemanager/test/cache/account.spec.ts +++ b/packages/statemanager/test/cache/account.spec.ts @@ -1,4 +1,4 @@ -import { Account, Address, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { Account, Address, equalsBytes, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { AccountCache, CacheType } from '../../src/cache/index.js' @@ -18,7 +18,7 @@ describe('Account Cache: put and get account', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new AccountCache({ size: 100, type }) - const addr = new Address(hexStringToBytes('10'.repeat(20))) + const addr = new Address(prefixedHexStringToBytes('0x' + '10'.repeat(20))) const acc: Account = createAccount(BigInt(1), BigInt(0xff11)) const accRLP = acc.serialize() @@ -51,7 +51,7 @@ describe('Account Cache: checkpointing', () => { for (const type of [CacheType.LRU, CacheType.ORDERED_MAP]) { const cache = new AccountCache({ size: 100, type }) - const addr = new Address(hexStringToBytes('10'.repeat(20))) + const addr = new Address(prefixedHexStringToBytes('0x' + '10'.repeat(20))) const acc = createAccount(BigInt(1), BigInt(0xff11)) const accRLP = acc.serialize() diff --git a/packages/statemanager/test/checkpointing.account.spec.ts b/packages/statemanager/test/checkpointing.account.spec.ts index 8ce6290909..d026bae36f 100644 --- a/packages/statemanager/test/checkpointing.account.spec.ts +++ b/packages/statemanager/test/checkpointing.account.spec.ts @@ -1,4 +1,4 @@ -import { Account, Address, hexStringToBytes } from '@ethereumjs/util' +import { Account, Address, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { DefaultStateManager } from '../src/index.js' @@ -26,7 +26,7 @@ const accountEval = async ( type CompareList = [Account | undefined, bigint | undefined] describe('StateManager -> Account Checkpointing', () => { - const address = new Address(hexStringToBytes('11'.repeat(20))) + const address = new Address(prefixedHexStringToBytes('0x' + '11'.repeat(20))) const accountN1: CompareList = [ Account.fromAccountData({ diff --git a/packages/statemanager/test/checkpointing.storage.spec.ts b/packages/statemanager/test/checkpointing.storage.spec.ts index e37bd12755..40d8c96051 100644 --- a/packages/statemanager/test/checkpointing.storage.spec.ts +++ b/packages/statemanager/test/checkpointing.storage.spec.ts @@ -1,4 +1,4 @@ -import { Account, Address, hexStringToBytes } from '@ethereumjs/util' +import { Account, Address, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { DefaultStateManager } from '../src/index.js' @@ -20,29 +20,39 @@ const storageEval = async ( } describe('StateManager -> Storage Checkpointing', () => { - const address = new Address(hexStringToBytes('11'.repeat(20))) + const address = new Address(prefixedHexStringToBytes('0x' + '11'.repeat(20))) const account = new Account() - const key = hexStringToBytes('01'.repeat(32)) + const key = prefixedHexStringToBytes('0x' + '01'.repeat(32)) - const value = hexStringToBytes('01') - const root = hexStringToBytes('561a011235f3fe8a4d292eba6d462e09015bbef9f8c3373dd70760bbc86f9a6c') + const value = prefixedHexStringToBytes('0x01') + const root = prefixedHexStringToBytes( + '0x561a011235f3fe8a4d292eba6d462e09015bbef9f8c3373dd70760bbc86f9a6c' + ) - const value2 = hexStringToBytes('02') - const root2 = hexStringToBytes('38f95e481a23df7b41934aee346cc960becc5388ad4c67e51f60ac03e8687626') + const value2 = prefixedHexStringToBytes('0x02') + const root2 = prefixedHexStringToBytes( + '0x38f95e481a23df7b41934aee346cc960becc5388ad4c67e51f60ac03e8687626' + ) - const value3 = hexStringToBytes('03') - const root3 = hexStringToBytes('dedbee161cad6e3afcc99901dfca9122c16ad48af559d78c4a8b5bec2f5f304b') + const value3 = prefixedHexStringToBytes('0x03') + const root3 = prefixedHexStringToBytes( + '0xdedbee161cad6e3afcc99901dfca9122c16ad48af559d78c4a8b5bec2f5f304b' + ) - const value4 = hexStringToBytes('04') - const root4 = hexStringToBytes('e5ccf4afccb012ac0900d0f64f6567a1bceb89f16ff5050da2a64427da94b618') + const value4 = prefixedHexStringToBytes('0x04') + const root4 = prefixedHexStringToBytes( + '0xe5ccf4afccb012ac0900d0f64f6567a1bceb89f16ff5050da2a64427da94b618' + ) - const value5 = hexStringToBytes('05') - const root5 = hexStringToBytes('b5b5deaf640a41912217f37f6ee338d49c6a476e0912c81188c2954fd1e959f8') + const value5 = prefixedHexStringToBytes('0x05') + const root5 = prefixedHexStringToBytes( + '0xb5b5deaf640a41912217f37f6ee338d49c6a476e0912c81188c2954fd1e959f8' + ) const valueEmpty = new Uint8Array(0) - const rootEmpty = hexStringToBytes( - '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421' + const rootEmpty = prefixedHexStringToBytes( + '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421' ) const storageSets = [ diff --git a/packages/statemanager/test/ethersStateManager.spec.ts b/packages/statemanager/test/ethersStateManager.spec.ts index 1dd886be07..aba2c5cf79 100644 --- a/packages/statemanager/test/ethersStateManager.spec.ts +++ b/packages/statemanager/test/ethersStateManager.spec.ts @@ -6,7 +6,7 @@ import { Address, bigIntToBytes, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, setLengthLeft, utf8ToBytes, } from '@ethereumjs/util' @@ -216,8 +216,8 @@ describe('runTx custom transaction test', () => { const vm = await VM.create({ common, stateManager: state }) // TODO fix the type DefaultStateManager back to StateManagerInterface in VM const vitalikDotEth = Address.fromString('0xd8da6bf26964af9d7eed9e03e53415d37aa96045') - const privateKey = hexStringToBytes( - 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' + const privateKey = prefixedHexStringToBytes( + '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' ) const tx = FeeMarketEIP1559Transaction.fromTxData( { to: vitalikDotEth, value: '0x100', gasLimit: 500000n, maxFeePerGas: 7 }, diff --git a/packages/statemanager/test/proofStateManager.spec.ts b/packages/statemanager/test/proofStateManager.spec.ts index 52de92fa74..988fe8cbbc 100644 --- a/packages/statemanager/test/proofStateManager.spec.ts +++ b/packages/statemanager/test/proofStateManager.spec.ts @@ -3,7 +3,7 @@ import { Account, Address, bytesToHex, - hexStringToBytes, + prefixedHexStringToBytes, randomBytes, zeros, } from '@ethereumjs/util' @@ -20,8 +20,8 @@ describe('ProofStateManager', () => { it(`should get and verify EIP 1178 proofs`, async () => { const address = Address.zero() const key = zeros(32) - const value = hexStringToBytes('0000aabb00') - const code = hexStringToBytes('6000') + const value = prefixedHexStringToBytes('0x0000aabb00') + const code = prefixedHexStringToBytes('0x6000') const stateManager = new DefaultStateManager() await stateManager.checkpoint() await stateManager.putAccount(address, new Account()) @@ -31,7 +31,7 @@ describe('ProofStateManager', () => { account!.balance = BigInt(1) account!.nonce = BigInt(2) await stateManager.putAccount(address, account!) - const address2 = new Address(hexStringToBytes('20'.repeat(20))) + const address2 = new Address(prefixedHexStringToBytes('0x' + '20'.repeat(20))) const account2 = await stateManager.getAccount(address2) account!.nonce = BigInt(2) await stateManager.putAccount(address2, account2!) @@ -59,7 +59,7 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_validAccount.accountProof) { - const bufferData = hexStringToBytes(proofData) + const bufferData = prefixedHexStringToBytes(proofData) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key @@ -84,7 +84,7 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_nonexistentAccount.accountProof) { - const bufferData = hexStringToBytes(proofData) + const bufferData = prefixedHexStringToBytes(proofData) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key @@ -110,7 +110,7 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_contractWithStorage.accountProof) { - const bufferData = hexStringToBytes(proofData) + const bufferData = prefixedHexStringToBytes(proofData) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key @@ -122,14 +122,14 @@ describe('ProofStateManager', () => { const storageTrie = new Trie({ useKeyHashing: true }) const storageKeys: Uint8Array[] = [] for (const storageProofsData of ropsten_contractWithStorage.storageProof) { - storageKeys.push(hexStringToBytes(storageProofsData.key)) + storageKeys.push(prefixedHexStringToBytes(storageProofsData.key)) for (const storageProofData of storageProofsData.proof) { - const key = keccak256(hexStringToBytes(storageProofData)) + const key = keccak256(prefixedHexStringToBytes(storageProofData)) // @ts-expect-error - await storageTrie._db.put(key, hexStringToBytes(storageProofData)) + await storageTrie._db.put(key, prefixedHexStringToBytes(storageProofData)) } } - storageTrie.root(hexStringToBytes(storageRoot)) + storageTrie.root(prefixedHexStringToBytes(storageRoot)) const addressHex = bytesToHex(address.bytes) stateManager._storageTries[addressHex] = storageTrie trie.root(stateRoot!) @@ -150,7 +150,7 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_contractWithStorage.accountProof) { - const bufferData = hexStringToBytes(proofData) + const bufferData = prefixedHexStringToBytes(proofData) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key @@ -162,14 +162,14 @@ describe('ProofStateManager', () => { const storageTrie = new Trie({ useKeyHashing: true }) const storageKeys: Uint8Array[] = [] for (const storageProofsData of ropsten_contractWithStorage.storageProof) { - storageKeys.push(hexStringToBytes(storageProofsData.key)) + storageKeys.push(prefixedHexStringToBytes(storageProofsData.key)) for (const storageProofData of storageProofsData.proof) { - const key = keccak256(hexStringToBytes(storageProofData)) + const key = keccak256(prefixedHexStringToBytes(storageProofData)) // @ts-expect-error - await storageTrie._db.put(key, hexStringToBytes(storageProofData)) + await storageTrie._db.put(key, prefixedHexStringToBytes(storageProofData)) } } - storageTrie.root(hexStringToBytes(storageRoot)) + storageTrie.root(prefixedHexStringToBytes(storageRoot)) const addressHex = bytesToHex(address.bytes) stateManager._storageTries[addressHex] = storageTrie trie.root(stateRoot!) @@ -218,7 +218,7 @@ describe('ProofStateManager', () => { // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined for (const proofData of ropsten_nonexistentAccount.accountProof) { - const bufferData = hexStringToBytes(proofData) + const bufferData = prefixedHexStringToBytes(proofData) const key = keccak256(bufferData) if (stateRoot === undefined) { stateRoot = key @@ -228,7 +228,7 @@ describe('ProofStateManager', () => { } const storageRoot = ropsten_nonexistentAccount.storageHash const storageTrie = new Trie({ useKeyHashing: true }) - storageTrie.root(hexStringToBytes(storageRoot)) + storageTrie.root(prefixedHexStringToBytes(storageRoot)) const addressHex = bytesToHex(address.bytes) stateManager._storageTries[addressHex] = storageTrie trie.root(stateRoot!) diff --git a/packages/statemanager/test/stateManager.account.spec.ts b/packages/statemanager/test/stateManager.account.spec.ts index 7449003c7b..f319fb9a62 100644 --- a/packages/statemanager/test/stateManager.account.spec.ts +++ b/packages/statemanager/test/stateManager.account.spec.ts @@ -1,4 +1,10 @@ -import { Address, KECCAK256_RLP, bytesToHex, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { + Address, + KECCAK256_RLP, + bytesToHex, + equalsBytes, + prefixedHexStringToBytes, +} from '@ethereumjs/util' import { assert, describe, it } from 'vitest' // explicitly import `inherits` to fix karma-typescript issue // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -14,7 +20,9 @@ describe('StateManager -> General/Account', () => { assert.ok(equalsBytes(stateManager._trie.root(), KECCAK256_RLP), 'it has default root') // commit some data to the trie - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount(BigInt(0), BigInt(1000)) await stateManager.checkpoint() await stateManager.putAccount(address, account) @@ -31,7 +39,9 @@ describe('StateManager -> General/Account', () => { it(`should clear the cache when the state root is set`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount() // test account storage cache @@ -52,10 +62,10 @@ describe('StateManager -> General/Account', () => { // test contract storage cache await stateManager.checkpoint() - const key = hexStringToBytes( - '1234567890123456789012345678901234567890123456789012345678901234' + const key = prefixedHexStringToBytes( + '0x1234567890123456789012345678901234567890123456789012345678901234' ) - const value = hexStringToBytes('1234') + const value = prefixedHexStringToBytes('0x1234') await stateManager.putAccount(address, account) await stateManager.putContractStorage(address, key, value) @@ -77,7 +87,9 @@ describe('StateManager -> General/Account', () => { it('should put and get account, and add to the underlying cache if the account is not found', async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) const account = createAccount() - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) await stateManager.putAccount(address, account) @@ -95,7 +107,9 @@ describe('StateManager -> General/Account', () => { it(`should return undefined for a non-existent account`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const res = (await stateManager.getAccount(address)) === undefined @@ -105,7 +119,9 @@ describe('StateManager -> General/Account', () => { it(`should return undefined for an existent account`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) const account = createAccount(BigInt(0x1), BigInt(0x1)) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) await stateManager.putAccount(address, account) @@ -117,7 +133,9 @@ describe('StateManager -> General/Account', () => { it(`should modify account fields correctly`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) const account = createAccount() - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) await stateManager.putAccount(address, account) await stateManager.modifyAccountFields(address, { balance: BigInt(1234) }) @@ -133,11 +151,11 @@ describe('StateManager -> General/Account', () => { assert.equal(res2!.nonce, BigInt(1)) await stateManager.modifyAccountFields(address, { - codeHash: hexStringToBytes( - 'd748bf26ab37599c944babfdbeecf6690801bd61bf2670efb0a34adfc6dca10b' + codeHash: prefixedHexStringToBytes( + '0xd748bf26ab37599c944babfdbeecf6690801bd61bf2670efb0a34adfc6dca10b' ), - storageRoot: hexStringToBytes( - 'cafd881ab193703b83816c49ff6c2bf6ba6f464a1be560c42106128c8dbc35e7' + storageRoot: prefixedHexStringToBytes( + '0xcafd881ab193703b83816c49ff6c2bf6ba6f464a1be560c42106128c8dbc35e7' ), }) diff --git a/packages/statemanager/test/stateManager.code.spec.ts b/packages/statemanager/test/stateManager.code.spec.ts index ceb2bf61c9..7e268bc0e1 100644 --- a/packages/statemanager/test/stateManager.code.spec.ts +++ b/packages/statemanager/test/stateManager.code.spec.ts @@ -1,4 +1,4 @@ -import { Account, Address, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { Account, Address, equalsBytes, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' // explicitly import `inherits` to fix karma-typescript issue // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -23,10 +23,12 @@ describe('StateManager -> Code', () => { // Setup const stateManager = new DefaultStateManager({ accountCacheOpts }) const codeStateManager = new DefaultStateManager({ accountCacheOpts }) - const address1 = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address1 = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount() - const key1 = hexStringToBytes('00'.repeat(32)) - const key2 = hexStringToBytes('00'.repeat(31) + '01') + const key1 = prefixedHexStringToBytes('0x' + '00'.repeat(32)) + const key2 = prefixedHexStringToBytes('0x' + '00'.repeat(31) + '01') await stateManager.putAccount(address1, account) await stateManager.putContractStorage(address1, key1, key2) @@ -79,9 +81,11 @@ describe('StateManager -> Code', () => { it(`should set and get code`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) - const code = hexStringToBytes( - '73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157' + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) + const code = prefixedHexStringToBytes( + '0x73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157' ) const raw = { nonce: '0x0', @@ -98,7 +102,9 @@ describe('StateManager -> Code', () => { it(`should not get code if is not contract`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const raw = { nonce: '0x0', balance: '0x03e7', @@ -111,7 +117,9 @@ describe('StateManager -> Code', () => { it(`should set empty code`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const raw = { nonce: '0x0', balance: '0x03e7', @@ -126,8 +134,10 @@ describe('StateManager -> Code', () => { it(`should prefix codehashes by default`, async () => { const stateManager = new DefaultStateManager({ accountCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) - const code = hexStringToBytes('80') + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) + const code = prefixedHexStringToBytes('0x80') await stateManager.putContractCode(address, code) const codeRetrieved = await stateManager.getContractCode(address) assert.ok(equalsBytes(codeRetrieved, code)) @@ -137,8 +147,10 @@ describe('StateManager -> Code', () => { const stateManager = new DefaultStateManager({ prefixCodeHashes: false, }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) - const code = hexStringToBytes('80') + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) + const code = prefixedHexStringToBytes('0x80') try { await stateManager.putContractCode(address, code) assert.fail('should throw') diff --git a/packages/statemanager/test/stateManager.storage.spec.ts b/packages/statemanager/test/stateManager.storage.spec.ts index 58c1f6b6d6..900ed049cc 100644 --- a/packages/statemanager/test/stateManager.storage.spec.ts +++ b/packages/statemanager/test/stateManager.storage.spec.ts @@ -1,4 +1,4 @@ -import { Address, hexStringToBytes, unpadBytes, zeros } from '@ethereumjs/util' +import { Address, prefixedHexStringToBytes, unpadBytes, zeros } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak.js' import { bytesToHex, concatBytes, equalsBytes } from 'ethereum-cryptography/utils.js' import { assert, describe, it } from 'vitest' @@ -13,15 +13,17 @@ describe('StateManager -> Storage', () => { for (const storageCacheOpts of [{ deactivate: false }, { deactivate: true }]) { it(`should dump storage`, async () => { const stateManager = new DefaultStateManager({ storageCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount() await stateManager.putAccount(address, account) - const key = hexStringToBytes( - '1234567890123456789012345678901234567890123456789012345678901234' + const key = prefixedHexStringToBytes( + '0x1234567890123456789012345678901234567890123456789012345678901234' ) - const value = hexStringToBytes('0a') // We used this value as its RLP encoding is also 0a + const value = prefixedHexStringToBytes('0x0a') // We used this value as its RLP encoding is also 0a await stateManager.putContractStorage(address, key, value) const data = await stateManager.dumpStorage(address) @@ -31,12 +33,18 @@ describe('StateManager -> Storage', () => { it("should validate the key's length when modifying a contract's storage", async () => { const stateManager = new DefaultStateManager({ storageCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount() await stateManager.putAccount(address, account) try { - await stateManager.putContractStorage(address, new Uint8Array(12), hexStringToBytes('1231')) + await stateManager.putContractStorage( + address, + new Uint8Array(12), + prefixedHexStringToBytes('0x1231') + ) } catch (e: any) { assert.equal(e.message, 'Storage key must be 32 bytes long') return @@ -47,7 +55,9 @@ describe('StateManager -> Storage', () => { it("should validate the key's length when reading a contract's storage", async () => { const stateManager = new DefaultStateManager({ storageCacheOpts }) - const address = new Address(hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b')) + const address = new Address( + prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') + ) const account = createAccount() await stateManager.putAccount(address, account) @@ -68,7 +78,7 @@ describe('StateManager -> Storage', () => { await stateManager.putAccount(address, account) const key = zeros(32) - const value = hexStringToBytes('aa'.repeat(33)) + const value = prefixedHexStringToBytes('0x' + 'aa'.repeat(33)) try { await stateManager.putContractStorage(address, key, value) assert.fail('did not throw') @@ -84,14 +94,14 @@ describe('StateManager -> Storage', () => { await stateManager.putAccount(address, account) const key0 = zeros(32) - const value0 = hexStringToBytes('00' + 'aa'.repeat(30)) // put a value of 31-bytes length with a leading zero byte + const value0 = prefixedHexStringToBytes('0x' + '00' + 'aa'.repeat(30)) // put a value of 31-bytes length with a leading zero byte const expect0 = unpadBytes(value0) await stateManager.putContractStorage(address, key0, value0) const slot0 = await stateManager.getContractStorage(address, key0) assert.ok(equalsBytes(slot0, expect0), 'value of 31 bytes padded correctly') - const key1 = concatBytes(zeros(31), hexStringToBytes('01')) - const value1 = hexStringToBytes('0000' + 'aa'.repeat(1)) // put a value of 1-byte length with two leading zero bytes + const key1 = concatBytes(zeros(31), prefixedHexStringToBytes('0x01')) + const value1 = prefixedHexStringToBytes('0x' + '0000' + 'aa'.repeat(1)) // put a value of 1-byte length with two leading zero bytes const expect1 = unpadBytes(value1) await stateManager.putContractStorage(address, key1, value1) const slot1 = await stateManager.getContractStorage(address, key1) @@ -103,7 +113,7 @@ describe('StateManager -> Storage', () => { const address = Address.zero() const key = zeros(32) - const startValue = hexStringToBytes('01') + const startValue = prefixedHexStringToBytes('0x01') const zeroLengths = [0, 1, 31, 32] // checks for arbitrary-length zeros @@ -134,8 +144,8 @@ describe('StateManager -> Storage', () => { await stateManager.putAccount(address, account) const key = zeros(32) - const value = hexStringToBytes('0000aabb00') - const expect = hexStringToBytes('aabb00') + const value = prefixedHexStringToBytes('0x0000aabb00') + const expect = prefixedHexStringToBytes('0xaabb00') await stateManager.putContractStorage(address, key, value) const contractValue = await stateManager.getContractStorage(address, key) diff --git a/packages/trie/src/db/checkpoint.ts b/packages/trie/src/db/checkpoint.ts index 6b8a9a9bbd..305aa2750a 100644 --- a/packages/trie/src/db/checkpoint.ts +++ b/packages/trie/src/db/checkpoint.ts @@ -1,10 +1,30 @@ -import { KeyEncoding, ValueEncoding, bytesToHex, hexStringToBytes } from '@ethereumjs/util' +import { KeyEncoding, ValueEncoding, bytesToHex, padToEven } from '@ethereumjs/util' import { hexToBytes } from 'ethereum-cryptography/utils.js' import { LRUCache } from 'lru-cache' import type { Checkpoint, CheckpointDBOpts } from '../types.js' import type { BatchDBOp, DB, DelBatch, PutBatch } from '@ethereumjs/util' +/** + * In order to not-prefix the key/values in the DB each time (this copies the key/values each time: expensive) + * Use this "private" method (see `prefixedHexStringToBytes` from @ethereumjs/util for reference) + * @param hex + * @returns + */ +function _nonPrefixedHexStringToBytes(hex: string) { + if (hex.length % 2 !== 0) { + hex = padToEven(hex) + } + + const byteLen = hex.length / 2 + const bytes = new Uint8Array(byteLen) + for (let i = 0; i < byteLen; i++) { + const byte = parseInt(hex.slice(i * 2, (i + 1) * 2), 16) + bytes[i] = byte + } + return bytes +} + /** * DB is a thin wrapper around the underlying levelup db, * which validates inputs and sets encoding type. @@ -99,12 +119,12 @@ export class CheckpointDB implements DB { if (value === undefined) { batchOp.push({ type: 'del', - key: hexStringToBytes(key), + key: _nonPrefixedHexStringToBytes(key), }) } else { batchOp.push({ type: 'put', - key: hexStringToBytes(key), + key: _nonPrefixedHexStringToBytes(key), value, }) } diff --git a/packages/trie/test/db/checkpoint.spec.ts b/packages/trie/test/db/checkpoint.spec.ts index af45e2ee63..3191571da6 100644 --- a/packages/trie/test/db/checkpoint.spec.ts +++ b/packages/trie/test/db/checkpoint.spec.ts @@ -1,4 +1,4 @@ -import { MapDB, hexStringToBytes, utf8ToBytes } from '@ethereumjs/util' +import { MapDB, prefixedHexStringToBytes, utf8ToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { CheckpointDB } from '../../src/index.js' @@ -13,7 +13,7 @@ describe('DB tests', () => { it('Checkpointing: revert -> put (add)', async () => { const db = new CheckpointDB({ db: new MapDB() }) - db.checkpoint(hexStringToBytes('01')) + db.checkpoint(prefixedHexStringToBytes('0x01')) await db.put(k, v) assert.deepEqual(await db.get(k), v, 'before revert: v1') await db.revert() @@ -24,7 +24,7 @@ describe('DB tests', () => { const db = new CheckpointDB({ db: new MapDB() }) await db.put(k, v) assert.deepEqual(await db.get(k), v, 'before CP: v1') - db.checkpoint(hexStringToBytes('01')) + db.checkpoint(prefixedHexStringToBytes('0x01')) await db.put(k, v2) await db.put(k, v3) await db.revert() @@ -35,7 +35,7 @@ describe('DB tests', () => { const db = new CheckpointDB({ db: new MapDB() }) await db.put(k, v) assert.deepEqual(await db.get(k), v, 'before CP: v1') - db.checkpoint(hexStringToBytes('01')) + db.checkpoint(prefixedHexStringToBytes('0x01')) const ops = [ { type: 'put', key: k, value: v2 }, { type: 'put', key: k, value: v3 }, @@ -49,7 +49,7 @@ describe('DB tests', () => { const db = new CheckpointDB({ db: new MapDB() }) await db.put(k, v) assert.deepEqual(await db.get(k), v, 'before CP: v1') - db.checkpoint(hexStringToBytes('01')) + db.checkpoint(prefixedHexStringToBytes('0x01')) await db.del(k) assert.deepEqual(await db.get(k), undefined, 'before revert: undefined') await db.revert() @@ -61,9 +61,9 @@ describe('DB tests', () => { await db.put(k, v) assert.deepEqual(await db.get(k), v, 'before CP: v1') - db.checkpoint(hexStringToBytes('01')) + db.checkpoint(prefixedHexStringToBytes('0x01')) await db.put(k, v2) - db.checkpoint(hexStringToBytes('02')) + db.checkpoint(prefixedHexStringToBytes('0x02')) await db.put(k, v3) await db.commit() assert.deepEqual(await db.get(k), v3, 'after commit (second CP): v3') diff --git a/packages/trie/test/encoding.spec.ts b/packages/trie/test/encoding.spec.ts index 6f6a9af01d..02142dc609 100644 --- a/packages/trie/test/encoding.spec.ts +++ b/packages/trie/test/encoding.spec.ts @@ -1,4 +1,4 @@ -import { bytesToHex, hexStringToBytes, toBytes, utf8ToBytes } from '@ethereumjs/util' +import { bytesToHex, prefixedHexStringToBytes, toBytes, utf8ToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Trie } from '../src/index.js' @@ -9,7 +9,7 @@ const hex = 'FF44A3B3' describe('encoding hex prefixes', () => { it('should work', async () => { - await trie.put(hexStringToBytes(hex), utf8ToBytes('test')) + await trie.put(prefixedHexStringToBytes('0x' + hex), utf8ToBytes('test')) await trie2.put(toBytes(`0x${hex}`), utf8ToBytes('test')) assert.equal(bytesToHex(trie.root()), bytesToHex(trie2.root())) }) diff --git a/packages/trie/test/index.spec.ts b/packages/trie/test/index.spec.ts index edd055c81d..c3151a8556 100644 --- a/packages/trie/test/index.spec.ts +++ b/packages/trie/test/index.spec.ts @@ -3,7 +3,7 @@ import { KECCAK256_NULL, KECCAK256_RLP_S, bytesToHex, - hexStringToBytes, + prefixedHexStringToBytes, utf8ToBytes, } from '@ethereumjs/util' import { blake2b } from 'ethereum-cryptography/blake2b.js' @@ -19,8 +19,8 @@ import type { HashKeysFunction } from '../src/index.js' for (const cacheSize of [0, 100]) { describe('simple save and retrieve', () => { it('should not crash if given a non-existent root', async () => { - const root = hexStringToBytes( - '3f4399b08efe68945c1cf90ffe85bbe3ce978959da753f9e649f034015b8817d' + const root = prefixedHexStringToBytes( + '0x3f4399b08efe68945c1cf90ffe85bbe3ce978959da753f9e649f034015b8817d' ) const trie = new Trie({ root }) @@ -243,10 +243,10 @@ for (const cacheSize of [0, 100]) { it('should work', async () => { const trie4 = new Trie({ cacheSize }) - const g = hexStringToBytes('8a40bfaa73256b60764c1bf40675a99083efb075') - const j = hexStringToBytes('e6716f9544a56c530d868e4bfbacb172315bdead') - const v = hexStringToBytes('1e12515ce3e0f817a4ddef9ca55788a1d66bd2df') - const a = hexStringToBytes('1a26338f0d905e295fccb71fa9ea849ffa12aaf4') + const g = prefixedHexStringToBytes('0x8a40bfaa73256b60764c1bf40675a99083efb075') + const j = prefixedHexStringToBytes('0xe6716f9544a56c530d868e4bfbacb172315bdead') + const v = prefixedHexStringToBytes('0x1e12515ce3e0f817a4ddef9ca55788a1d66bd2df') + const a = prefixedHexStringToBytes('0x1a26338f0d905e295fccb71fa9ea849ffa12aaf4') const storageRoot = new Uint8Array(32) storageRoot.fill(0) @@ -283,8 +283,8 @@ for (const cacheSize of [0, 100]) { const k2 = utf8ToBytes('2') const v2 = utf8ToBytes('this-is-some-longer-value-to-test-the-delete-operation-value2') - const rootAfterK1 = hexStringToBytes( - '809e75931f394603657e113eb7244794f35b8d326cff99407111d600722e9425' + const rootAfterK1 = prefixedHexStringToBytes( + '0x809e75931f394603657e113eb7244794f35b8d326cff99407111d600722e9425' ) const trieSetup = { diff --git a/packages/trie/test/official.spec.ts b/packages/trie/test/official.spec.ts index b706b3545d..c70fc269d5 100644 --- a/packages/trie/test/official.spec.ts +++ b/packages/trie/test/official.spec.ts @@ -1,4 +1,4 @@ -import { bytesToPrefixedHexString, hexStringToBytes, utf8ToBytes } from '@ethereumjs/util' +import { bytesToPrefixedHexString, prefixedHexStringToBytes, utf8ToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { Trie } from '../src/index.js' @@ -17,7 +17,7 @@ describe('official tests', () => { for (const input of inputs) { for (let i = 0; i < 2; i++) { if (typeof input[i] === 'string' && input[i].slice(0, 2) === '0x') { - input[i] = hexStringToBytes(input[i]) + input[i] = prefixedHexStringToBytes(input[i]) } else if (typeof input[i] === 'string') { input[i] = utf8ToBytes(input[i]) } @@ -42,13 +42,13 @@ describe('official tests any order', async () => { let val = test.in[key] if (typeof key === 'string' && key.slice(0, 2) === '0x') { - key = hexStringToBytes(key) + key = prefixedHexStringToBytes(key) } else if (typeof key === 'string') { key = utf8ToBytes(key) } if (typeof val === 'string' && val.slice(0, 2) === '0x') { - val = hexStringToBytes(val) + val = prefixedHexStringToBytes(val) } else if (typeof val === 'string') { val = utf8ToBytes(val) } diff --git a/packages/trie/test/proof/range.spec.ts b/packages/trie/test/proof/range.spec.ts index 6d3782238d..830833096c 100644 --- a/packages/trie/test/proof/range.spec.ts +++ b/packages/trie/test/proof/range.spec.ts @@ -2,7 +2,7 @@ import { MapDB, compareBytes, concatBytes, - hexStringToBytes, + prefixedHexStringToBytes, setLengthLeft, toBytes, } from '@ethereumjs/util' @@ -141,8 +141,8 @@ describe('simple merkle range proofs generation and verification', () => { } // Special case, two edge proofs for two edge key. - const startKey = hexStringToBytes('00'.repeat(32)) - const endKey = hexStringToBytes('ff'.repeat(32)) + const startKey = prefixedHexStringToBytes('0x' + '00'.repeat(32)) + const endKey = prefixedHexStringToBytes('0x' + 'ff'.repeat(32)) assert.equal(await verify(trie, entries, 0, entries.length - 1, startKey, endKey), false) }) @@ -205,7 +205,7 @@ describe('simple merkle range proofs generation and verification', () => { ] await tinyTrie.put(tinyEntries[0][0], tinyEntries[0][1]) - const tinyStartKey = hexStringToBytes('00'.repeat(32)) + const tinyStartKey = prefixedHexStringToBytes('0x' + '00'.repeat(32)) assert.equal(await verify(tinyTrie, tinyEntries, 0, 0, tinyStartKey), false) }) @@ -234,15 +234,15 @@ describe('simple merkle range proofs generation and verification', () => { entries, 0, entries.length - 1, - hexStringToBytes('00'.repeat(32)), - hexStringToBytes('ff'.repeat(32)) + prefixedHexStringToBytes('0x' + '00'.repeat(32)), + prefixedHexStringToBytes('0x' + 'ff'.repeat(32)) ), false ) }) it('create a single side range proof and verify it', async () => { - const startKey = hexStringToBytes('00'.repeat(32)) + const startKey = prefixedHexStringToBytes('0x' + '00'.repeat(32)) const { trie, entries } = await randomTrie(new MapDB(), false) const cases = [0, 1, 200, entries.length - 1] @@ -252,7 +252,7 @@ describe('simple merkle range proofs generation and verification', () => { }) it('create a revert single side range proof and verify it', async () => { - const endKey = hexStringToBytes('ff'.repeat(32)) + const endKey = prefixedHexStringToBytes('0x' + 'ff'.repeat(32)) const { trie, entries } = await randomTrie(new MapDB(), false) const cases = [0, 1, 200, entries.length - 1] @@ -455,14 +455,14 @@ describe('simple merkle range proofs generation and verification', () => { if (start === -1) { start = 0 - startKey = hexStringToBytes('00'.repeat(32)) + startKey = prefixedHexStringToBytes('0x' + '00'.repeat(32)) } else { startKey = entries[start][0] } if (end === -1) { end = entries.length - 1 - endKey = hexStringToBytes('ff'.repeat(32)) + endKey = prefixedHexStringToBytes('0x' + 'ff'.repeat(32)) } else { endKey = entries[end][0] } diff --git a/packages/trie/test/trie/prune.spec.ts b/packages/trie/test/trie/prune.spec.ts index 1cdf8269c5..08fe091b98 100644 --- a/packages/trie/test/trie/prune.spec.ts +++ b/packages/trie/test/trie/prune.spec.ts @@ -1,7 +1,7 @@ import { KECCAK256_RLP, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, randomBytes, utf8ToBytes, } from '@ethereumjs/util' @@ -56,7 +56,10 @@ describe('Pruned trie tests', () => { const values = ['00', '02', '03', '04', '05'] for (let i = 0; i < keys.length; i++) { - await trie.put(hexStringToBytes(keys[i]), hexStringToBytes(values[i])) + await trie.put( + prefixedHexStringToBytes('0x' + keys[i]), + prefixedHexStringToBytes('0x' + values[i]) + ) } }) @@ -161,9 +164,9 @@ describe('Pruned trie tests', () => { // Create empty Trie (is pruned) let trie = new Trie() // Create a new value (still is pruned) - await trie.put(hexStringToBytes('aa'), hexStringToBytes('bb')) + await trie.put(prefixedHexStringToBytes('0xaa'), prefixedHexStringToBytes('0xbb')) // Overwrite this value (trie is now not pruned anymore) - await trie.put(hexStringToBytes('aa'), hexStringToBytes('aa')) + await trie.put(prefixedHexStringToBytes('0xaa'), prefixedHexStringToBytes('0xaa')) assert.ok(!(await trie.verifyPrunedIntegrity()), 'trie is not pruned') // Create new empty Trie (is pruned) diff --git a/packages/trie/test/trie/secure.spec.ts b/packages/trie/test/trie/secure.spec.ts index 4cfcbbd46a..fdade32021 100644 --- a/packages/trie/test/trie/secure.spec.ts +++ b/packages/trie/test/trie/secure.spec.ts @@ -3,7 +3,7 @@ import { bytesToPrefixedHexString, bytesToUtf8, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, utf8ToBytes, } from '@ethereumjs/util' import { createHash } from 'crypto' @@ -73,9 +73,9 @@ describe('secure tests', () => { for (const row of secureTrieTests.tests.jeff.in) { let val = row[1] if (val !== undefined && val !== null) { - val = hexStringToBytes(row[1].slice(2)) + val = prefixedHexStringToBytes(row[1].slice(2)) } - await trie.put(hexStringToBytes(row[0].slice(2)), val) + await trie.put(prefixedHexStringToBytes(row[0].slice(2)), val) } assert.equal(bytesToPrefixedHexString(trie.root()), secureTrieTests.tests.jeff.root) })*/ @@ -94,38 +94,38 @@ describe('secure tests', () => { }) const trie = new Trie({ useKeyHashing: true, db: new MapDB() }) -const a = hexStringToBytes( - 'f8448080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' +const a = prefixedHexStringToBytes( + '0xf8448080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' ) -const ak = hexStringToBytes('095e7baea6a6c7c4c2dfeb977efac326af552d87') -const b = hexStringToBytes( - 'f844802ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0db94dc4aab9b6a1a11956906ea34f3252f394576aece12199b23b269bb2738ab' +const ak = prefixedHexStringToBytes('0x095e7baea6a6c7c4c2dfeb977efac326af552d87') +const b = prefixedHexStringToBytes( + '0xf844802ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0db94dc4aab9b6a1a11956906ea34f3252f394576aece12199b23b269bb2738ab' ) -const bk = hexStringToBytes('945304eb96065b2a98b57a48a06ae28d285a71b5') -const c = hexStringToBytes( - 'f84c80880de0b6b3a7640000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' +const bk = prefixedHexStringToBytes('0x945304eb96065b2a98b57a48a06ae28d285a71b5') +const c = prefixedHexStringToBytes( + '0xf84c80880de0b6b3a7640000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' ) -const ck = hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b') +const ck = prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') // checkpoint // checkpoint // commit -const d = hexStringToBytes( - 'f8488084535500b1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' +const d = prefixedHexStringToBytes( + '0xf8488084535500b1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' ) -const dk = hexStringToBytes('095e7baea6a6c7c4c2dfeb977efac326af552d87') -const e = hexStringToBytes( - 'f8478083010851a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0db94dc4aab9b6a1a11956906ea34f3252f394576aece12199b23b269bb2738ab' +const dk = prefixedHexStringToBytes('0x095e7baea6a6c7c4c2dfeb977efac326af552d87') +const e = prefixedHexStringToBytes( + '0xf8478083010851a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0db94dc4aab9b6a1a11956906ea34f3252f394576aece12199b23b269bb2738ab' ) -const ek = hexStringToBytes('945304eb96065b2a98b57a48a06ae28d285a71b5') -const f = hexStringToBytes( - 'f84c01880de0b6b3540df72ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' +const ek = prefixedHexStringToBytes('0x945304eb96065b2a98b57a48a06ae28d285a71b5') +const f = prefixedHexStringToBytes( + '0xf84c01880de0b6b3540df72ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' ) -const fk = hexStringToBytes('a94f5374fce5edbc8e2a8697c15331677e6ebf0b') +const fk = prefixedHexStringToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b') // commit -const g = hexStringToBytes( - 'f8488084535500b1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' +const g = prefixedHexStringToBytes( + '0xf8488084535500b1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0a155280bc3c09fd31b0adebbdd4ef3d5128172c0d2008be964dc9e10e0f0fedf' ) -const gk = hexStringToBytes('095e7baea6a6c7c4c2dfeb977efac326af552d87') +const gk = prefixedHexStringToBytes('0x095e7baea6a6c7c4c2dfeb977efac326af552d87') describe('secure tests should not crash', () => { it('should work', async () => { diff --git a/packages/tx/src/eip1559Transaction.ts b/packages/tx/src/eip1559Transaction.ts index 3f25da4f06..64fe2f7788 100644 --- a/packages/tx/src/eip1559Transaction.ts +++ b/packages/tx/src/eip1559Transaction.ts @@ -8,7 +8,7 @@ import { concatBytes, ecrecover, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, toBytes, validateNoLeadingZeroes, } from '@ethereumjs/util' @@ -31,8 +31,8 @@ import type { Common } from '@ethereumjs/common' type TxData = AllTypesTxData[TransactionType.FeeMarketEIP1559] type TxValuesArray = AllTypesTxValuesArray[TransactionType.FeeMarketEIP1559] -const TRANSACTION_TYPE_BYTES = hexStringToBytes( - TransactionType.FeeMarketEIP1559.toString(16).padStart(2, '0') +const TRANSACTION_TYPE_BYTES = prefixedHexStringToBytes( + '0x' + TransactionType.FeeMarketEIP1559.toString(16).padStart(2, '0') ) /** diff --git a/packages/tx/src/eip2930Transaction.ts b/packages/tx/src/eip2930Transaction.ts index 995f24acba..357bc9e687 100644 --- a/packages/tx/src/eip2930Transaction.ts +++ b/packages/tx/src/eip2930Transaction.ts @@ -8,7 +8,7 @@ import { concatBytes, ecrecover, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, toBytes, validateNoLeadingZeroes, } from '@ethereumjs/util' @@ -31,8 +31,8 @@ import type { Common } from '@ethereumjs/common' type TxData = AllTypesTxData[TransactionType.AccessListEIP2930] type TxValuesArray = AllTypesTxValuesArray[TransactionType.AccessListEIP2930] -const TRANSACTION_TYPE_BYTES = hexStringToBytes( - TransactionType.AccessListEIP2930.toString(16).padStart(2, '0') +const TRANSACTION_TYPE_BYTES = prefixedHexStringToBytes( + '0x' + TransactionType.AccessListEIP2930.toString(16).padStart(2, '0') ) /** diff --git a/packages/tx/src/eip4844Transaction.ts b/packages/tx/src/eip4844Transaction.ts index 699e7dc736..e984f61488 100644 --- a/packages/tx/src/eip4844Transaction.ts +++ b/packages/tx/src/eip4844Transaction.ts @@ -14,8 +14,8 @@ import { ecrecover, equalsBytes, getBlobs, - hexStringToBytes, kzg, + prefixedHexStringToBytes, toBytes, validateNoLeadingZeroes, } from '@ethereumjs/util' @@ -40,8 +40,8 @@ import type { Common } from '@ethereumjs/common' type TxData = AllTypesTxData[TransactionType.BlobEIP4844] type TxValuesArray = AllTypesTxValuesArray[TransactionType.BlobEIP4844] -const TRANSACTION_TYPE_BYTES = hexStringToBytes( - TransactionType.BlobEIP4844.toString(16).padStart(2, '0') +const TRANSACTION_TYPE_BYTES = prefixedHexStringToBytes( + '0x' + TransactionType.BlobEIP4844.toString(16).padStart(2, '0') ) const validateBlobTransactionNetworkWrapper = ( diff --git a/packages/tx/src/util.ts b/packages/tx/src/util.ts index 93506337f0..a172d0c0e8 100644 --- a/packages/tx/src/util.ts +++ b/packages/tx/src/util.ts @@ -1,4 +1,4 @@ -import { bytesToPrefixedHexString, hexStringToBytes, setLengthLeft } from '@ethereumjs/util' +import { bytesToPrefixedHexString, prefixedHexStringToBytes, setLengthLeft } from '@ethereumjs/util' import { isAccessList } from './types.js' @@ -27,10 +27,10 @@ export class AccessLists { for (let i = 0; i < accessList.length; i++) { const item: AccessListItem = accessList[i] - const addressBytes = hexStringToBytes(item.address) + const addressBytes = prefixedHexStringToBytes(item.address) const storageItems: Uint8Array[] = [] for (let index = 0; index < item.storageKeys.length; index++) { - storageItems.push(hexStringToBytes(item.storageKeys[index])) + storageItems.push(prefixedHexStringToBytes(item.storageKeys[index])) } newAccessList.push([addressBytes, storageItems]) } diff --git a/packages/tx/test/base.spec.ts b/packages/tx/test/base.spec.ts index aacd631982..fef684f54b 100644 --- a/packages/tx/test/base.spec.ts +++ b/packages/tx/test/base.spec.ts @@ -5,7 +5,7 @@ import { SECP256K1_ORDER, bytesToBigInt, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, privateToPublic, toBytes, utf8ToBytes, @@ -274,7 +274,10 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - assert.ok(tx.sign(hexStringToBytes(privateKey)), `${txType.name}: should sign tx`) + assert.ok( + tx.sign(prefixedHexStringToBytes('0x' + privateKey)), + `${txType.name}: should sign tx` + ) } assert.throws( @@ -316,7 +319,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey, sendersAddress } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexStringToBytes(privateKey)) + const signedTx = tx.sign(prefixedHexStringToBytes('0x' + privateKey)) assert.equal( signedTx.getSenderAddress().toString(), `0x${sendersAddress}`, @@ -332,9 +335,9 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexStringToBytes(privateKey)) + const signedTx = tx.sign(prefixedHexStringToBytes('0x' + privateKey)) const txPubKey = signedTx.getSenderPublicKey() - const pubKeyFromPriv = privateToPublic(hexStringToBytes(privateKey)) + const pubKeyFromPriv = privateToPublic(prefixedHexStringToBytes('0x' + privateKey)) assert.ok( equalsBytes(txPubKey, pubKeyFromPriv), `${txType.name}: should get sender's public key after signing it` @@ -351,7 +354,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - let signedTx = tx.sign(hexStringToBytes(privateKey)) + let signedTx = tx.sign(prefixedHexStringToBytes('0x' + privateKey)) signedTx = JSON.parse(JSON.stringify(signedTx)) // deep clone ;(signedTx as any).s = SECP256K1_ORDER + BigInt(1) assert.throws( @@ -372,7 +375,7 @@ describe('[BaseTransaction]', () => { for (const [i, tx] of txType.txs.entries()) { const { privateKey } = txType.fixtures[i] if (privateKey !== undefined) { - const signedTx = tx.sign(hexStringToBytes(privateKey)) + const signedTx = tx.sign(prefixedHexStringToBytes('0x' + privateKey)) assert.ok(signedTx.verifySignature(), `${txType.name}: should verify signing it`) } } diff --git a/packages/tx/test/eip1559.spec.ts b/packages/tx/test/eip1559.spec.ts index 8eb76bc8fd..c61c18b0eb 100644 --- a/packages/tx/test/eip1559.spec.ts +++ b/packages/tx/test/eip1559.spec.ts @@ -1,6 +1,6 @@ import { Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' -import { TWO_POW256, equalsBytes, hexStringToBytes } from '@ethereumjs/util' +import { TWO_POW256, equalsBytes, prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { FeeMarketEIP1559Transaction } from '../src/index.js' @@ -10,8 +10,8 @@ import testdata from './json/eip1559.json' // Source: Besu const common = Common.custom({ chainId: 4 }) common.setHardfork(Hardfork.London) -const validAddress = hexStringToBytes('01'.repeat(20)) -const validSlot = hexStringToBytes('01'.repeat(32)) +const validAddress = prefixedHexStringToBytes('0x' + '01'.repeat(20)) +const validSlot = prefixedHexStringToBytes('0x' + '01'.repeat(32)) const chainId = BigInt(4) describe('[FeeMarketEIP1559Transaction]', () => { @@ -88,12 +88,12 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('sign()', () => { for (let index = 0; index < testdata.length; index++) { const data = testdata[index] - const pkey = hexStringToBytes(data.privateKey) + const pkey = prefixedHexStringToBytes(data.privateKey) const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) const signed = txn.sign(pkey) const rlpSerialized = RLP.encode(Uint8Array.from(signed.serialize())) assert.ok( - equalsBytes(rlpSerialized, hexStringToBytes(data.signedTransactionRLP)), + equalsBytes(rlpSerialized, prefixedHexStringToBytes(data.signedTransactionRLP)), 'Should sign txs correctly' ) } @@ -101,11 +101,11 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('hash()', () => { const data = testdata[0] - const pkey = hexStringToBytes(data.privateKey) + const pkey = prefixedHexStringToBytes(data.privateKey) let txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) let signed = txn.sign(pkey) - const expectedHash = hexStringToBytes( - '2e564c87eb4b40e7f469b2eec5aa5d18b0b46a24e8bf0919439cfb0e8fcae446' + const expectedHash = prefixedHexStringToBytes( + '0x2e564c87eb4b40e7f469b2eec5aa5d18b0b46a24e8bf0919439cfb0e8fcae446' ) assert.ok( equalsBytes(signed.hash(), expectedHash), @@ -121,7 +121,7 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('freeze property propagates from unsigned tx to signed tx', () => { const data = testdata[0] - const pkey = hexStringToBytes(data.privateKey) + const pkey = prefixedHexStringToBytes(data.privateKey) const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common, freeze: false }) assert.notOk(Object.isFrozen(txn), 'tx object is not frozen') const signedTxn = txn.sign(pkey) @@ -130,7 +130,7 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('common propagates from the common of tx, not the common in TxOptions', () => { const data = testdata[0] - const pkey = hexStringToBytes(data.privateKey) + const pkey = prefixedHexStringToBytes(data.privateKey) const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common, freeze: false }) const newCommon = Common.custom({ chainId: 4 }) @@ -150,20 +150,20 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('unsigned tx -> getMessageToSign()/getHashedMessageToSign()', () => { const unsignedTx = FeeMarketEIP1559Transaction.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), to: validAddress, accessList: [[validAddress, [validSlot]]], chainId, }, { common } ) - const expectedHash = hexStringToBytes( - 'fa81814f7dd57bad435657a05eabdba2815f41e3f15ddd6139027e7db56b0dea' + const expectedHash = prefixedHexStringToBytes( + '0xfa81814f7dd57bad435657a05eabdba2815f41e3f15ddd6139027e7db56b0dea' ) assert.deepEqual(unsignedTx.getHashedMessageToSign(), expectedHash), 'correct hashed version' - const expectedSerialization = hexStringToBytes( - '02f85904808080809401010101010101010101010101010101010101018083010200f838f7940101010101010101010101010101010101010101e1a00101010101010101010101010101010101010101010101010101010101010101' + const expectedSerialization = prefixedHexStringToBytes( + '0x02f85904808080809401010101010101010101010101010101010101018083010200f838f7940101010101010101010101010101010101010101e1a00101010101010101010101010101010101010101010101010101010101010101' ) assert.deepEqual( unsignedTx.getMessageToSign(), @@ -174,7 +174,7 @@ describe('[FeeMarketEIP1559Transaction]', () => { it('toJSON()', () => { const data = testdata[0] - const pkey = hexStringToBytes(data.privateKey) + const pkey = prefixedHexStringToBytes(data.privateKey) const txn = FeeMarketEIP1559Transaction.fromTxData(data, { common }) const signed = txn.sign(pkey) diff --git a/packages/tx/test/eip4844.spec.ts b/packages/tx/test/eip4844.spec.ts index afa1abe72a..0f87b69bf1 100644 --- a/packages/tx/test/eip4844.spec.ts +++ b/packages/tx/test/eip4844.spec.ts @@ -7,8 +7,8 @@ import { concatBytes, equalsBytes, getBlobs, - hexStringToBytes, initKZG, + prefixedHexStringToBytes, } from '@ethereumjs/util' import * as kzg from 'c-kzg' import { randomBytes } from 'crypto' @@ -449,7 +449,9 @@ describe('hash() and signature verification', () => { 'produced the correct transaction hash' ) const signedTx = unsignedTx.sign( - hexStringToBytes('45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') + prefixedHexStringToBytes( + '0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8' + ) ) assert.equal( diff --git a/packages/tx/test/inputValue.spec.ts b/packages/tx/test/inputValue.spec.ts index b379a0eeab..d7c620189b 100644 --- a/packages/tx/test/inputValue.spec.ts +++ b/packages/tx/test/inputValue.spec.ts @@ -1,5 +1,5 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { Address, hexStringToBytes, toBytes } from '@ethereumjs/util' +import { Address, prefixedHexStringToBytes, toBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { @@ -153,7 +153,7 @@ describe('[Invalid Array Input values]', () => { for (const txType of txTypes) { let tx = TransactionFactory.fromTxData({ type: txType }) if (signed) { - tx = tx.sign(hexStringToBytes('42'.repeat(32))) + tx = tx.sign(prefixedHexStringToBytes('0x' + '42'.repeat(32))) } const rawValues = tx.raw() for (let x = 0; x < rawValues.length; x++) { @@ -222,14 +222,14 @@ describe('[Invalid Access Lists]', () => { accessList: invalidAccessListItem, }) if (signed) { - tx = tx.sign(hexStringToBytes('42'.repeat(32))) + tx = tx.sign(prefixedHexStringToBytes('0x' + '42'.repeat(32))) } assert.fail('did not fail on `fromTxData`') } catch (e: any) { assert.ok(true, 'failed ok on decoding in `fromTxData`') tx = TransactionFactory.fromTxData({ type: txType }) if (signed) { - tx = tx.sign(hexStringToBytes('42'.repeat(32))) + tx = tx.sign(prefixedHexStringToBytes('0x' + '42'.repeat(32))) } } const rawValues = tx!.raw() diff --git a/packages/tx/test/legacy.spec.ts b/packages/tx/test/legacy.spec.ts index 4506c68f4b..60a5bdc9c0 100644 --- a/packages/tx/test/legacy.spec.ts +++ b/packages/tx/test/legacy.spec.ts @@ -5,8 +5,8 @@ import { bytesToHex, bytesToPrefixedHexString, equalsBytes, - hexStringToBytes, intToBytes, + prefixedHexStringToBytes, toBytes, unpadBytes, } from '@ethereumjs/util' @@ -121,7 +121,7 @@ describe('[Transaction]', () => { let common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Petersburg }) let tx = LegacyTransaction.fromTxData({}, { common }) assert.equal(tx.common.chainId(), BigInt(5)) - const privKey = hexStringToBytes(txFixtures[0].privateKey) + const privKey = prefixedHexStringToBytes('0x' + txFixtures[0].privateKey) tx = tx.sign(privKey) const serialized = tx.serialize() common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Petersburg }) @@ -233,16 +233,16 @@ describe('[Transaction]', () => { }) assert.deepEqual( tx.hash(), - hexStringToBytes('375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa') + prefixedHexStringToBytes('0x375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa') ) assert.deepEqual( tx.getHashedMessageToSign(), - hexStringToBytes('61e1ec33764304dddb55348e7883d4437426f44ab3ef65e6da1e025734c03ff0') + prefixedHexStringToBytes('0x61e1ec33764304dddb55348e7883d4437426f44ab3ef65e6da1e025734c03ff0') ) assert.equal(tx.getMessageToSign().length, 6) assert.deepEqual( tx.hash(), - hexStringToBytes('375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa') + prefixedHexStringToBytes('0x375a8983c9fc56d7cfd118254a80a8d7403d590a6c9e105532b67aca1efb97aa') ) }) @@ -281,8 +281,8 @@ describe('[Transaction]', () => { '0x0de0b6b3a7640000', '0x', ] - const privateKey = hexStringToBytes( - '4646464646464646464646464646464646464646464646464646464646464646' + const privateKey = prefixedHexStringToBytes( + '0x4646464646464646464646464646464646464646464646464646464646464646' ) const pt = LegacyTransaction.fromValuesArray(txRaw.map(toBytes)) @@ -311,7 +311,7 @@ describe('[Transaction]', () => { common, }) - const privKey = hexStringToBytes(txData.privateKey) + const privKey = prefixedHexStringToBytes('0x' + txData.privateKey) const txSigned = tx.sign(privKey) assert.equal( @@ -331,8 +331,8 @@ describe('[Transaction]', () => { '0x0de0b6b3a7640000', '0x', ] - const privateKey = hexStringToBytes( - 'DE3128752F183E8930D7F00A2AAA302DCB5E700B2CBA2D8CA5795660F07DEFD5' + const privateKey = prefixedHexStringToBytes( + '0xDE3128752F183E8930D7F00A2AAA302DCB5E700B2CBA2D8CA5795660F07DEFD5' ) const common = Common.custom({ chainId: 3 }) const tx = LegacyTransaction.fromValuesArray(txRaw.map(toBytes), { common }) @@ -353,8 +353,8 @@ describe('[Transaction]', () => { value: '0x0', } - const privateKey = hexStringToBytes( - '4646464646464646464646464646464646464646464646464646464646464646' + const privateKey = prefixedHexStringToBytes( + '0x4646464646464646464646464646464646464646464646464646464646464646' ) const common = new Common({ @@ -423,7 +423,7 @@ describe('[Transaction]', () => { let tx = LegacyTransaction.fromTxData({}, { common }) assert.equal(tx.common.chainId(), BigInt(5)) - const privKey = hexStringToBytes(txFixtures[0].privateKey) + const privKey = prefixedHexStringToBytes('0x' + txFixtures[0].privateKey) tx = tx.sign(privKey) const serialized = tx.serialize() @@ -436,14 +436,14 @@ describe('[Transaction]', () => { it('freeze property propagates from unsigned tx to signed tx', () => { const tx = LegacyTransaction.fromTxData({}, { freeze: false }) assert.notOk(Object.isFrozen(tx), 'tx object is not frozen') - const privKey = hexStringToBytes(txFixtures[0].privateKey) + const privKey = prefixedHexStringToBytes('0x' + txFixtures[0].privateKey) const signedTxn = tx.sign(privKey) assert.notOk(Object.isFrozen(signedTxn), 'tx object is not frozen') }) it('common propagates from the common of tx, not the common in TxOptions', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const pkey = hexStringToBytes(txFixtures[0].privateKey) + const pkey = prefixedHexStringToBytes('0x' + txFixtures[0].privateKey) const txn = LegacyTransaction.fromTxData({}, { common, freeze: false }) const newCommon = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London, eips: [2537] }) assert.notDeepEqual(newCommon, common, 'new common is different than original common') @@ -468,8 +468,8 @@ describe('[Transaction]', () => { to: '0xd9024df085d09398ec76fbed18cac0e1149f50dc', value: '0x0', } - const privateKey = hexStringToBytes( - '4646464646464646464646464646464646464646464646464646464646464646' + const privateKey = prefixedHexStringToBytes( + '0x4646464646464646464646464646464646464646464646464646464646464646' ) tx = LegacyTransaction.fromTxData(txData) assert.notOk(tx.isSigned()) diff --git a/packages/tx/test/transactionFactory.spec.ts b/packages/tx/test/transactionFactory.spec.ts index 632bd6aaba..a209bcb097 100644 --- a/packages/tx/test/transactionFactory.spec.ts +++ b/packages/tx/test/transactionFactory.spec.ts @@ -1,5 +1,5 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { hexStringToBytes } from '@ethereumjs/util' +import { prefixedHexStringToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' import { @@ -15,7 +15,9 @@ const common = new Common({ hardfork: Hardfork.London, }) -const pKey = hexStringToBytes('4646464646464646464646464646464646464646464646464646464646464646') +const pKey = prefixedHexStringToBytes( + '0x4646464646464646464646464646464646464646464646464646464646464646' +) const unsignedLegacyTx = LegacyTransaction.fromTxData({}) const signedLegacyTx = unsignedLegacyTx.sign(pKey) diff --git a/packages/tx/test/typedTxsAndEIP2930.spec.ts b/packages/tx/test/typedTxsAndEIP2930.spec.ts index 2889900b09..1e8cdb9c1f 100644 --- a/packages/tx/test/typedTxsAndEIP2930.spec.ts +++ b/packages/tx/test/typedTxsAndEIP2930.spec.ts @@ -8,7 +8,7 @@ import { bytesToPrefixedHexString, concatBytes, equalsBytes, - hexStringToBytes, + prefixedHexStringToBytes, privateToAddress, } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -21,7 +21,9 @@ import { import type { AccessList, AccessListBytesItem } from '../src/index.js' -const pKey = hexStringToBytes('4646464646464646464646464646464646464646464646464646464646464646') +const pKey = prefixedHexStringToBytes( + '0x4646464646464646464646464646464646464646464646464646464646464646' +) const address = privateToAddress(pKey) const common = new Common({ @@ -42,8 +44,8 @@ const txTypes = [ }, ] -const validAddress = hexStringToBytes('01'.repeat(20)) -const validSlot = hexStringToBytes('01'.repeat(32)) +const validAddress = prefixedHexStringToBytes('0x' + '01'.repeat(20)) +const validSlot = prefixedHexStringToBytes('0x' + '01'.repeat(32)) const chainId = BigInt(Chain.Mainnet) describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-2930 Compatibility', () => { @@ -171,7 +173,10 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 try { // Correct tx type + RLP-encoded empty list - const serialized = concatBytes(new Uint8Array([txType.type]), hexStringToBytes('c0')) + const serialized = concatBytes( + new Uint8Array([txType.type]), + prefixedHexStringToBytes('0xc0') + ) txType.class.fromSerializedTx(serialized, {}) } catch (e: any) { assert.ok( @@ -228,7 +233,7 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 for (const txType of txTypes) { let accessList: any[] = [ [ - hexStringToBytes('01'.repeat(21)), // Address of 21 bytes instead of 20 + prefixedHexStringToBytes('0x' + '01'.repeat(21)), // Address of 21 bytes instead of 20 [], ], ] @@ -246,7 +251,7 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 [ validAddress, [ - hexStringToBytes('01'.repeat(31)), // Slot of 31 bytes instead of 32 + prefixedHexStringToBytes('0x' + '01'.repeat(31)), // Slot of 31 bytes instead of 32 ], ], ] @@ -310,7 +315,7 @@ describe('[AccessListEIP2930Transaction / FeeMarketEIP1559Transaction] -> EIP-29 for (const txType of txTypes) { let tx = txType.class.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), to: validAddress, accessList: [[validAddress, [validSlot]]], chainId, @@ -388,13 +393,13 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { 'should initialize correctly from its own data' ) - const validAddress = hexStringToBytes('01'.repeat(20)) - const validSlot = hexStringToBytes('01'.repeat(32)) + const validAddress = prefixedHexStringToBytes('0x' + '01'.repeat(20)) + const validSlot = prefixedHexStringToBytes('0x' + '01'.repeat(32)) const chainId = BigInt(1) try { AccessListEIP2930Transaction.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), to: validAddress, accessList: [[validAddress, [validSlot]]], chainId, @@ -430,7 +435,7 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { it(`should return right upfront cost`, () => { let tx = AccessListEIP2930Transaction.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), to: validAddress, accessList: [[validAddress, [validSlot]]], chainId, @@ -462,7 +467,7 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { // In this Tx, `to` is `undefined`, so we should charge homestead creation gas. tx = AccessListEIP2930Transaction.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), accessList: [[validAddress, [validSlot]]], chainId, }, @@ -514,20 +519,20 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { it('unsigned tx -> getHashedMessageToSign()/getMessageToSign()', () => { const unsignedTx = AccessListEIP2930Transaction.fromTxData( { - data: hexStringToBytes('010200'), + data: prefixedHexStringToBytes('0x010200'), to: validAddress, accessList: [[validAddress, [validSlot]]], chainId, }, { common } ) - const expectedHash = hexStringToBytes( - '78528e2724aa359c58c13e43a7c467eb721ce8d410c2a12ee62943a3aaefb60b' + const expectedHash = prefixedHexStringToBytes( + '0x78528e2724aa359c58c13e43a7c467eb721ce8d410c2a12ee62943a3aaefb60b' ) assert.deepEqual(unsignedTx.getHashedMessageToSign(), expectedHash), 'correct hashed version' - const expectedSerialization = hexStringToBytes( - '01f858018080809401010101010101010101010101010101010101018083010200f838f7940101010101010101010101010101010101010101e1a00101010101010101010101010101010101010101010101010101010101010101' + const expectedSerialization = prefixedHexStringToBytes( + '0x01f858018080809401010101010101010101010101010101010101018083010200f838f7940101010101010101010101010101010101010101e1a00101010101010101010101010101010101010101010101010101010101010101' ) assert.deepEqual( unsignedTx.getMessageToSign(), @@ -540,18 +545,18 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { // https://github.com/INFURA/go-ethlibs/blob/75b2a52a39d353ed8206cffaf68d09bd1b154aae/eth/transaction_signing_test.go#L87 it('should sign transaction correctly and return expected JSON', () => { - const address = hexStringToBytes('0000000000000000000000000000000000001337') - const slot1 = hexStringToBytes( - '0000000000000000000000000000000000000000000000000000000000000000' + const address = prefixedHexStringToBytes('0x0000000000000000000000000000000000001337') + const slot1 = prefixedHexStringToBytes( + '0x0000000000000000000000000000000000000000000000000000000000000000' ) const txData = { - data: hexStringToBytes(''), + data: prefixedHexStringToBytes('0x'), gasLimit: 0x62d4, gasPrice: 0x3b9aca00, nonce: 0x00, - to: new Address(hexStringToBytes('df0a88b2b68c673713a8ec826003676f272e3573')), + to: new Address(prefixedHexStringToBytes('0xdf0a88b2b68c673713a8ec826003676f272e3573')), value: 0x01, - chainId: bytesToBigInt(hexStringToBytes('796f6c6f763378')), + chainId: bytesToBigInt(prefixedHexStringToBytes('0x796f6c6f763378')), accessList: [[address, [slot1]]], } @@ -566,24 +571,24 @@ describe('[AccessListEIP2930Transaction] -> Class Specific Tests', () => { }) usedCommon.setEIPs([2718, 2929, 2930]) - const expectedUnsignedRaw = hexStringToBytes( - '01f86587796f6c6f76337880843b9aca008262d494df0a88b2b68c673713a8ec826003676f272e35730180f838f7940000000000000000000000000000000000001337e1a00000000000000000000000000000000000000000000000000000000000000000808080' + const expectedUnsignedRaw = prefixedHexStringToBytes( + '0x01f86587796f6c6f76337880843b9aca008262d494df0a88b2b68c673713a8ec826003676f272e35730180f838f7940000000000000000000000000000000000001337e1a00000000000000000000000000000000000000000000000000000000000000000808080' ) - const pkey = hexStringToBytes( - 'fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19' + const pkey = prefixedHexStringToBytes( + '0xfad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19' ) - const expectedSigned = hexStringToBytes( - '01f8a587796f6c6f76337880843b9aca008262d494df0a88b2b68c673713a8ec826003676f272e35730180f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938da00be950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d' + const expectedSigned = prefixedHexStringToBytes( + '0x01f8a587796f6c6f76337880843b9aca008262d494df0a88b2b68c673713a8ec826003676f272e35730180f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938da00be950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d' ) - const expectedHash = hexStringToBytes( - 'bbd570a3c6acc9bb7da0d5c0322fe4ea2a300db80226f7df4fef39b2d6649eec' + const expectedHash = prefixedHexStringToBytes( + '0xbbd570a3c6acc9bb7da0d5c0322fe4ea2a300db80226f7df4fef39b2d6649eec' ) const v = BigInt(0) const r = bytesToBigInt( - hexStringToBytes('294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938d') + prefixedHexStringToBytes('0x294ac94077b35057971e6b4b06dfdf55a6fbed819133a6c1d31e187f1bca938d') ) const s = bytesToBigInt( - hexStringToBytes('0be950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d') + prefixedHexStringToBytes('0x0be950468ba1c25a5cb50e9f6d8aa13c8cd21f24ba909402775b262ac76d374d') ) const unsignedTx = AccessListEIP2930Transaction.fromTxData(txData, { common: usedCommon }) diff --git a/packages/util/examples/browser.html b/packages/util/examples/browser.html index a2f3362953..73bd2f6756 100644 --- a/packages/util/examples/browser.html +++ b/packages/util/examples/browser.html @@ -4,9 +4,9 @@ EthereumJS Browser Examples