Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EIP-4803 #3827

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 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 Expand Up @@ -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)
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
Loading