diff --git a/.changeset/neat-cars-explain.md b/.changeset/neat-cars-explain.md new file mode 100644 index 0000000000..466b9af019 --- /dev/null +++ b/.changeset/neat-cars-explain.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +fix hex of odd length for eth_getStorageAt call when forking arbitrum diff --git a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts index 509d390b4b..f008700f5c 100644 --- a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts +++ b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts @@ -80,12 +80,20 @@ export function rpcQuantityToBN(quantity: string): BN { } export function numberToRpcQuantity(n: number | BN): string { + return numberToRpcQuantityWithLeadingZeros(n, false); +} + +export function numberToRpcQuantityWithLeadingZeros( + n: number | BN, + leadingZeros: boolean +): string { assertHardhatInvariant( typeof n === "number" || BN.isBN(n), "Expected number" ); - return `0x${n.toString(16)}`; + const s = n.toString(16); + return leadingZeros ? `0x${s.length % 2 ? "0" : ""}${s}` : `0x${s}`; } /** diff --git a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts index c69000a083..a5d9842921 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts @@ -4,7 +4,8 @@ import * as t from "io-ts"; import path from "path"; import { - numberToRpcQuantity, + numberToRpcQuantity, + numberToRpcQuantityWithLeadingZeros, rpcData, rpcQuantity, } from "../../core/jsonrpc/types/base-types"; @@ -56,7 +57,7 @@ export class JsonRpcClient { "eth_getStorageAt", [ address.toString(), - numberToRpcQuantity(position), + numberToRpcQuantityWithLeadingZeros(position, true), numberToRpcQuantity(blockNumber), ], rpcData,