From 1b43fc18cff09bb9244921a4da78b8f38c036a67 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Sun, 22 Dec 2024 03:25:12 +0100 Subject: [PATCH] implement 2^63-1 check --- packages/tx/src/features/util.ts | 13 +++++++++++++ packages/util/src/constants.ts | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/packages/tx/src/features/util.ts b/packages/tx/src/features/util.ts index 62077deb29..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) { 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) */