Skip to content

Commit

Permalink
implement 2^63-1 check
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Dec 22, 2024
1 parent 1c09746 commit 1b43fc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/tx/src/features/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Common, Mainnet } from '@ethereumjs/common'
import {
Address,
MAX_INTEGER,
MAX_UINT63,
MAX_UINT64,
bigIntToHex,
bytesToBigInt,
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions packages/util/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down

0 comments on commit 1b43fc1

Please sign in to comment.