diff --git a/packages/tx/src/features/util.ts b/packages/tx/src/features/util.ts index 36bd954618..e5f3f990c0 100644 --- a/packages/tx/src/features/util.ts +++ b/packages/tx/src/features/util.ts @@ -2,6 +2,7 @@ import { Common, Mainnet } from '@ethereumjs/common' import { Address, MAX_INTEGER, + MAX_UINT63, MAX_UINT64, bigIntToHex, bytesToBigInt, @@ -32,6 +33,18 @@ export function valueBoundaryCheck( ) { for (const [key, value] of Object.entries(values)) { switch (bits) { + case 63: + if (cannotEqual) { + if (value !== undefined && value >= MAX_UINT63) { + // TODO: error msgs got raised to a error string handler first, now throws "generic" error + throw new Error(`${key} cannot equal or exceed MAX_UINT63 (2^63-1), given ${value}`) + } + } else { + if (value !== undefined && value > MAX_UINT63) { + throw new Error(`${key} cannot exceed MAX_UINT63 (2^63-1), given ${value}`) + } + } + break case 64: if (cannotEqual) { if (value !== undefined && value >= MAX_UINT64) { @@ -108,8 +121,8 @@ export function sharedConstructor( // Validate value/r/s valueBoundaryCheck({ value: tx.value, r: tx.r, s: tx.s }) - // geth limits gasLimit to 2^64-1 - valueBoundaryCheck({ gasLimit: tx.gasLimit }, 64) + // https://eips.ethereum.org/EIPS/eip-4803 + valueBoundaryCheck({ gasLimit: tx.gasLimit }, 63, true) // EIP-2681 limits nonce to 2^64-1 (cannot equal 2^64-1) valueBoundaryCheck({ nonce: tx.nonce }, 64, true) diff --git a/packages/util/src/constants.ts b/packages/util/src/constants.ts index 25eb3f1ee1..7319fc490d 100644 --- a/packages/util/src/constants.ts +++ b/packages/util/src/constants.ts @@ -8,6 +8,11 @@ import { hexToBytes } from './bytes.js' */ export const MAX_UINT64 = BigInt('0xffffffffffffffff') +/** + * 2^63-1 + */ +export const MAX_UINT63 = BigInt(2) ** BigInt(63) - BigInt(1) + /** * The max integer that the evm can handle (2^256-1) */