Socket
Socket
Sign inDemoInstall

@ethereumjs/common

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereumjs/common - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0-rc.1

dist/cjs/chains/goerli.json

27

package.json
{
"name": "@ethereumjs/common",
"version": "3.2.0",
"version": "4.0.0-rc.1",
"description": "Resources common to all Ethereum implementations",

@@ -29,4 +29,11 @@ "keywords": [

],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "commonjs",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"files": [

@@ -39,4 +46,5 @@ "dist",

"clean": "../../config/cli/clean-package.sh",
"coverage": "../../config/cli/coverage.sh",
"docs:build": "typedoc --options typedoc.js",
"coverage": "npx vitest run --coverage.enabled --coverage.reporter=lcov",
"docs:build": "typedoc --options typedoc.cjs",
"examples": "ts-node ../../scripts/examples-runner.ts -- common",
"lint": "../../config/cli/lint.sh",

@@ -46,12 +54,11 @@ "lint:diff": "../../config/cli/lint-diff.sh",

"prepublishOnly": "../../config/cli/prepublish.sh",
"tape": "tape -r ts-node/register",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js",
"test:node": "npm run tape -- ./test/*.spec.ts",
"test:browser": "npx vitest run --browser.name=chrome --browser.headless",
"test:node": "npx vitest run",
"tsc": "../../config/cli/ts-compile.sh"
},
"dependencies": {
"@ethereumjs/util": "^8.1.0",
"crc-32": "^1.2.0"
"@ethereumjs/util": "9.0.0-rc.1",
"crc": "^4.3.2"
}
}

@@ -9,2 +9,4 @@ # @ethereumjs/common

Note: this README has been updated containing the changes from our next breaking release round [UNRELEASED] targeted for Summer 2023. See the README files from the [maintenance-v6](https://github.com/ethereumjs/ethereumjs-monorepo/tree/maintenance-v6/) branch for documentation matching our latest releases.
| Resources common to all EthereumJS implementations. |

@@ -30,3 +32,3 @@ | --------------------------------------------------- |

```typescript
import { Chain, Common, Hardfork } from '@ethereumjs/common
import { Chain, Common, Hardfork } from '@ethereumjs/common'
```

@@ -40,3 +42,3 @@

## Parameters
### Parameters

@@ -55,3 +57,3 @@ All parameters can be accessed through the `Common` class, instantiated with an object containing either the `chain` (e.g. 'Chain.Mainnet') or the `chain` together with a specific `hardfork` provided:

Current `DEFAULT_HARDFORK`: `Hardfork.Merge`
Current `DEFAULT_HARDFORK`: `Hardfork.Shanghai`

@@ -62,7 +64,7 @@ Here are some simple usage examples:

// Instantiate with the chain (and the default hardfork)
let c = new Common({ chain: Chain.Ropsten })
let c = new Common({ chain: Chain.Mainnet })
c.param('gasPrices', 'ecAddGas') // 500
// Chain and hardfork provided
c = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.Byzantium })
c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium })
c.param('pow', 'minerReward') // 3000000000000000000

@@ -74,7 +76,13 @@

// Instantiate with an EIP activated
c = new Common({ chain: Chain.Mainnet, eips: [2537] })
c = new Common({ chain: Chain.Mainnet, eips: [4844] })
```
# API
## Browser
With the breaking release round in Summer 2023 we have added hybrid ESM/CJS builds for all our libraries (see section below) and have eliminated many of the caveats which had previously prevented a frictionless browser usage.
It is now easily possible to run a browser build of one of the EthereumJS libraries within a modern browser using the provided ESM build. For a setup example see [./examples/browser.html](./examples/browser.html).
## API
### Docs

@@ -89,2 +97,26 @@

### Hybrid CJS/ESM Builds
With the breaking releases from Summer 2023 we have started to ship our libraries with both CommonJS (`cjs` folder) and ESM builds (`esm` folder), see `package.json` for the detailed setup.
If you use an ES6-style `import` in your code files from the ESM build will be used:
```typescript
import { EthereumJSClass } from '@ethereumjs/[PACKAGE_NAME]'
```
If you use Node.js specific `require` the CJS build will be used:
```typescript
const { EthereumJSClass } = require('@ethereumjs/[PACKAGE_NAME]')
```
Using ESM will give you additional advantages over CJS beyond browser usage like static code analysis / Tree Shaking which CJS can not provide.
### Buffer -> Uint8Array
With the breaking releases from Summer 2023 we have removed all Node.js specific `Buffer` usages from our libraries and replace these with [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) representations, which are available both in Node.js and the browser (`Buffer` is a subclass of `Uint8Array`).
We have converted existing Buffer conversion methods to Uint8Array conversion methods in the [@ethereumjs/util](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util) `bytes` module, see the respective README section for guidance.
### BigInt Support

@@ -98,4 +130,3 @@

The `Common` class is implemented as an `EventEmitter` and is emitting the following events
on which you can react within your code:
The `Common` class has a public property `events` which contains an `EventEmitter`. Following events are emitted on which you can react within your code:

@@ -113,3 +144,3 @@ | Event | Description |

```typescript
const c = new Common({ chain: Chain.Ropsten })
const c = new Common({ chain: Chain.Mainnet })
```

@@ -120,4 +151,2 @@

- `mainnet` (`Chain.Mainnet`)
- `ropsten` (`Chain.Ropsten`)
- `rinkeby` (`Chain.Rinkeby`)
- `goerli` (`Chain.Goerli`)

@@ -231,3 +260,3 @@ - `sepolia` (`Chain.Sepolia`) (`v2.6.1`+)

const c = new Common({ chain: Chain.Ropsten, hardfork: Hardfork.Byzantium })
const c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Byzantium })
```

@@ -254,6 +283,7 @@

- `shanghai` (`Hardfork.Shanghai`) (since `v3.1.0`)
- `cancun` (`Hardfork.Cancun`) (since `v4.0.0`)
### Future Hardforks
The next upcoming HF `Hardfork.Cancun` is currently not yet supported by this library.
The next upcoming HF `Hardfork.Prague` is currently not yet supported by this library.

@@ -284,3 +314,3 @@ ### Parameter Access

```typescript
const c = new Common({ chain: Chain.Mainnet, eips: [2537] })
const c = new Common({ chain: Chain.Mainnet, eips: [4844] })
```

@@ -290,23 +320,29 @@

- [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559): Fee market change for ETH 1.0 chain
- [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315): Simple subroutines for the EVM (`experimental`)
- [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537): BLS precompiles
- [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565): ModExp gas cost
- [EIP-2718](https://eips.ethereum.org/EIPS/eip-2565): Transaction Types
- [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929): gas cost increases for state access opcodes
- [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930): Optional access list tx type
- [EIP-3198](https://eips.ethereum.org/EIPS/eip-3198): Base fee Opcode
- [EIP-3529](https://eips.ethereum.org/EIPS/eip-3529): Reduction in refunds
- [EIP-3540](https://eips.ethereum.org/EIPS/eip-3541) - EVM Object Format (EOF) v1 (`experimental`)
- [EIP-3541](https://eips.ethereum.org/EIPS/eip-3541): Reject new contracts starting with the 0xEF byte
- [EIP-3554](https://eips.ethereum.org/EIPS/eip-3554): Difficulty Bomb Delay to December 2021 (only PoW networks)
- [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607): Reject transactions from senders with deployed code
- [EIP-3651](https://eips.ethereum.org/EIPS/eip-3651): Warm COINBASE (Shanghai)
- [EIP-3670](https://eips.ethereum.org/EIPS/eip-3670): EOF - Code Validation (`experimental`)
- [EIP-3675](https://eips.ethereum.org/EIPS/eip-3675): Upgrade consensus to Proof-of-Stake
- [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855): Push0 opcode (Shanghai)
- [EIP-3860](https://eips.ethereum.org/EIPS/eip-3860): Limit and meter initcode (Shanghai)
- [EIP-4345](https://eips.ethereum.org/EIPS/eip-4345): Difficulty Bomb Delay to June 2022
- [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399): Supplant DIFFICULTY opcode with PREVRANDAO (Merge) (`experimental`)
- [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895): Beacon chain push withdrawals as operations (Shanghai)
- [EIP-1153](https://eips.ethereum.org/EIPS/eip-1153) - Transient storage opcodes (Cancun)
- [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) - Fee market change for ETH 1.0 chain
- [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315) - Simple subroutines for the EVM (`outdated`)
- [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - BLS precompiles (removed in v4.0.0, see latest v3 release)
- [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565) - ModExp gas cost
- [EIP-2718](https://eips.ethereum.org/EIPS/eip-2565) - Transaction Types
- [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929) - gas cost increases for state access opcodes
- [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) - Optional access list tx type
- [EIP-3074](https://eips.ethereum.org/EIPS/eip-3074) - AUTH and AUTHCALL opcodes
- [EIP-3198](https://eips.ethereum.org/EIPS/eip-3198) - Base fee Opcode
- [EIP-3529](https://eips.ethereum.org/EIPS/eip-3529) - Reduction in refunds
- [EIP-3540](https://eips.ethereum.org/EIPS/eip-3541) - EVM Object Format (EOF) v1 (`outdated`)
- [EIP-3541](https://eips.ethereum.org/EIPS/eip-3541) - Reject new contracts starting with the 0xEF byte
- [EIP-3554](https://eips.ethereum.org/EIPS/eip-3554) - Difficulty Bomb Delay to December 2021 (only PoW networks)
- [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607) - Reject transactions from senders with deployed code
- [EIP-3651](https://eips.ethereum.org/EIPS/eip-3651) - Warm COINBASE (Shanghai)
- [EIP-3670](https://eips.ethereum.org/EIPS/eip-3670) - EOF - Code Validation (`outdated`)
- [EIP-3675](https://eips.ethereum.org/EIPS/eip-3675) - Upgrade consensus to Proof-of-Stake
- [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) - Push0 opcode (Shanghai)
- [EIP-3860](https://eips.ethereum.org/EIPS/eip-3860) - Limit and meter initcode (Shanghai)
- [EIP-4345](https://eips.ethereum.org/EIPS/eip-4345) - Difficulty Bomb Delay to June 2022
- [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399) - Supplant DIFFICULTY opcode with PREVRANDAO (Merge)
- [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) - Beacon block root in the EVM (Cancun)
- [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) - Shard Blob Transactions (Cancun) (`experimental`)
- [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895) - Beacon chain push withdrawals as operations (Shanghai)
- [EIP-5656](https://eips.ethereum.org/EIPS/eip-5656) - MCOPY - Memory copying instruction (Cancun)
- [EIP-6780](https://eips.ethereum.org/EIPS/eip-6780) - SELFDESTRUCT only in same transaction (Cancun)

@@ -313,0 +349,0 @@ ### Bootstrap Nodes

@@ -5,3 +5,3 @@ {

"networkId": 5,
"defaultHardfork": "merge",
"defaultHardfork": "shanghai",
"consensus": {

@@ -77,3 +77,3 @@ "type": "poa",

"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge, terminal block: https://goerli.etherscan.io/block/7382818",
"name": "merge",
"name": "paris",
"ttd": "10790000",

@@ -93,2 +93,7 @@ "block": 7382819,

"forkHash": "0xf9843abf"
},
{
"name": "cancun",
"block": null,
"forkHash": null
}

@@ -95,0 +100,0 @@ ],

@@ -5,3 +5,3 @@ {

"networkId": 1,
"defaultHardfork": "merge",
"defaultHardfork": "shanghai",
"consensus": {

@@ -93,3 +93,3 @@ "type": "pow",

"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge, terminal block: https://etherscan.io/block/15537393",
"name": "merge",
"name": "paris",
"ttd": "58750000000000000000000",

@@ -109,2 +109,7 @@ "block": 15537394,

"forkHash": "0xdce96c2d"
},
{
"name": "cancun",
"block": null,
"forkHash": null
}

@@ -111,0 +116,0 @@ ],

@@ -5,3 +5,3 @@ {

"networkId": 11155111,
"defaultHardfork": "merge",
"defaultHardfork": "shanghai",
"consensus": {

@@ -79,3 +79,3 @@ "type": "pow",

"//_comment": "The forkHash will remain same as mergeForkIdTransition is post merge, terminal block: https://sepolia.etherscan.io/block/1450408",
"name": "merge",
"name": "paris",
"ttd": "17000000000000000",

@@ -95,2 +95,7 @@ "block": 1450409,

"forkHash": "0xf7f9bc08"
},
{
"name": "cancun",
"block": null,
"forkHash": null
}

@@ -97,0 +102,0 @@ ],

@@ -1,3 +0,10 @@

import { TypeOutput, intToBuffer, toType } from '@ethereumjs/util'
import { buf as crc32Buffer } from 'crc-32'
import {
TypeOutput,
bytesToHex,
concatBytes,
hexToBytes,
intToBytes,
toType,
} from '@ethereumjs/util'
import { crc32 as crc } from 'crc'
import { EventEmitter } from 'events'

@@ -7,11 +14,9 @@

import * as mainnet from './chains/mainnet.json'
import * as rinkeby from './chains/rinkeby.json'
import * as ropsten from './chains/ropsten.json'
import * as sepolia from './chains/sepolia.json'
import { EIPs } from './eips'
import { Chain, CustomChain, Hardfork } from './enums'
import { hardforks as HARDFORK_SPECS } from './hardforks'
import { parseGethGenesis } from './utils'
import { EIPs } from './eips/index.js'
import { Chain, CustomChain, Hardfork } from './enums.js'
import { hardforks as HARDFORK_SPECS } from './hardforks/index.js'
import { parseGethGenesis } from './utils.js'
import type { ConsensusAlgorithm, ConsensusType } from './enums'
import type { ConsensusAlgorithm, ConsensusType } from './enums.js'
import type {

@@ -29,5 +34,6 @@ BootstrapNodeConfig,

GethConfigOpts,
HardforkByOpts,
HardforkConfig,
} from './types'
import type { BigIntLike } from '@ethereumjs/util'
} from './types.js'
import type { BigIntLike, PrefixedHexString } from '@ethereumjs/util'

@@ -44,3 +50,3 @@ type HardforkSpecKeys = keyof typeof HARDFORK_SPECS

*/
export class Common extends EventEmitter {
export class Common {
readonly DEFAULT_HARDFORK: string | Hardfork

@@ -55,2 +61,4 @@

public events: EventEmitter
/**

@@ -117,12 +125,2 @@ * Creates a {@link Common} object for a custom chain, based on a standard one.

}
if (chainParamsOrName === CustomChain.ArbitrumRinkebyTestnet) {
return Common.custom(
{
name: CustomChain.ArbitrumRinkebyTestnet,
chainId: 421611,
networkId: 421611,
},
opts
)
}
if (chainParamsOrName === CustomChain.ArbitrumOne) {

@@ -205,3 +203,3 @@ return Common.custom(

static isSupportedChainId(chainId: bigint): boolean {
const initializedChains = this._getInitializedChains()
const initializedChains = this.getInitializedChains()
return Boolean((initializedChains['names'] as ChainName)[chainId.toString()])

@@ -214,3 +212,3 @@ }

): ChainConfig {
const initializedChains = this._getInitializedChains(customChains)
const initializedChains = this.getInitializedChains(customChains)
if (typeof chain === 'number' || typeof chain === 'bigint') {

@@ -235,6 +233,7 @@ chain = chain.toString()

constructor(opts: CommonOpts) {
super()
this.events = new EventEmitter()
this._customChains = opts.customChains ?? []
this._chainParams = this.setChain(opts.chain)
this.DEFAULT_HARDFORK = this._chainParams.defaultHardfork ?? Hardfork.Merge
this.DEFAULT_HARDFORK = this._chainParams.defaultHardfork ?? Hardfork.Shanghai
// Assign hardfork changes in the sequence of the applied hardforks

@@ -297,3 +296,3 @@ this.HARDFORK_CHANGES = this.hardforks().map((hf) => [

this._hardfork = hardfork
this.emit('hardforkChanged', hardfork)
this.events.emit('hardforkChanged', hardfork)
}

@@ -309,4 +308,4 @@ existing = true

/**
* Returns the hardfork based on the block number or an optional
* total difficulty (Merge HF) provided.
* Returns the hardfork either based on block numer (older HFs) or
* timestamp (Shanghai upwards).
*

@@ -317,15 +316,11 @@ * An optional TD takes precedence in case the corresponding HF block

*
* @param blockNumber
* @param td : total difficulty of the parent block (for block hf) OR of the chain latest (for chain hf)
* @param timestamp: timestamp in seconds at which block was/is to be minted
* @param Opts Block number, timestamp or TD (all optional)
* @returns The name of the HF
*/
getHardforkByBlockNumber(
blockNumber: BigIntLike,
td?: BigIntLike,
timestamp?: BigIntLike
): string {
getHardforkBy(opts: HardforkByOpts): string {
let { blockNumber, timestamp, td } = opts
blockNumber = toType(blockNumber, TypeOutput.BigInt)
td = toType(td, TypeOutput.BigInt)
timestamp = toType(timestamp, TypeOutput.Number)
timestamp = toType(timestamp, TypeOutput.BigInt)

@@ -351,4 +346,6 @@ // Filter out hardforks with no block number, no ttd or no timestamp (i.e. unapplied hardforks)

(hf) =>
(hf.block !== null && hf.block > blockNumber) ||
(timestamp !== undefined && Number(hf.timestamp) > timestamp)
(blockNumber !== undefined &&
hf.block !== null &&
BigInt(hf.block) > (blockNumber as bigint)) ||
(timestamp !== undefined && hf.timestamp !== undefined && hf.timestamp > timestamp)
)

@@ -407,3 +404,3 @@

if (timestamp) {
if (timestamp !== undefined) {
const minTimeStamp = hfs

@@ -420,3 +417,3 @@ .slice(0, hfStartIndex)

(acc: number, hf: HardforkConfig) => Math.min(Number(hf.timestamp ?? timestamp), acc),
timestamp
Number(timestamp)
)

@@ -432,4 +429,4 @@ if (maxTimeStamp < timestamp) {

/**
* Sets a new hardfork based on the block number or an optional
* total difficulty (Merge HF) provided.
* Sets a new hardfork either based on block numer (older HFs) or
* timestamp (Shanghai upwards).
*

@@ -440,13 +437,7 @@ * An optional TD takes precedence in case the corresponding HF block

*
* @param blockNumber
* @param td
* @param timestamp
* @param Opts Block number, timestamp or TD (all optional)
* @returns The name of the HF set
*/
setHardforkByBlockNumber(
blockNumber: BigIntLike,
td?: BigIntLike,
timestamp?: BigIntLike
): string {
const hardfork = this.getHardforkByBlockNumber(blockNumber, td, timestamp)
setHardforkBy(opts: HardforkByOpts): string {
const hardfork = this.getHardforkBy(opts)
this.setHardfork(hardfork)

@@ -461,3 +452,3 @@ return hardfork

*/
_getHardfork(hardfork: string | Hardfork): HardforkConfig | null {
private _getHardfork(hardfork: string | Hardfork): HardforkConfig | null {
const hfs = this.hardforks()

@@ -537,7 +528,7 @@ for (const hf of hfs) {

} else {
if (hfChanges[1][topic] === undefined) {
if ((hfChanges[1] as any)[topic] === undefined) {
throw new Error(`Topic ${topic} not defined`)
}
if (hfChanges[1][topic][name] !== undefined) {
value = hfChanges[1][topic][name].v
if ((hfChanges[1] as any)[topic][name] !== undefined) {
value = (hfChanges[1] as any)[topic][name].v
}

@@ -589,3 +580,3 @@ }

): bigint {
const hardfork = this.getHardforkByBlockNumber(blockNumber, td, timestamp)
const hardfork = this.getHardforkBy({ blockNumber, td, timestamp })
return this.paramByHardfork(topic, name, hardfork)

@@ -707,3 +698,3 @@ }

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (hf['eips'].includes(eip)) {
if ((hf['eips'] as any).includes(eip)) {
return this.hardforkBlock(hfChanges[0])

@@ -731,16 +722,2 @@ }

/**
* True if block number provided is the hardfork (given or set) change block
* @param blockNumber Number of the block to check
* @param hardfork Hardfork name, optional if HF set
* @returns True if blockNumber is HF block
* @deprecated
*/
isHardforkBlock(blockNumber: BigIntLike, hardfork?: string | Hardfork): boolean {
blockNumber = toType(blockNumber, TypeOutput.BigInt)
hardfork = hardfork ?? this._hardfork
const block = this.hardforkBlock(hardfork)
return typeof block === 'bigint' && block !== BigInt(0) ? block === blockNumber : false
}
/**
* Returns the change block for the next hardfork after the hardfork provided or set

@@ -756,3 +733,3 @@ * @param hardfork Hardfork name, optional if HF set

// calcs even if the merge hf block is set
if (hardfork === Hardfork.Merge) {
if (hardfork === Hardfork.Paris) {
hfIndex -= 1

@@ -776,3 +753,3 @@ }

return (
hf.name !== Hardfork.Merge &&
hf.name !== Hardfork.Paris &&
hfTimeOrBlock !== null &&

@@ -797,54 +774,2 @@ hfTimeOrBlock !== undefined &&

/**
* Returns the change block for the next hardfork after the hardfork provided or set
* @param hardfork Hardfork name, optional if HF set
* @returns Block number or null if not available
* @deprecated
*/
nextHardforkBlock(hardfork?: string | Hardfork): bigint | null {
hardfork = hardfork ?? this._hardfork
let hfBlock = this.hardforkBlock(hardfork)
// If this is a merge hardfork with block not set, then we fallback to previous hardfork
// to find the nextHardforkBlock
if (hfBlock === null && hardfork === Hardfork.Merge) {
const hfs = this.hardforks()
const mergeIndex = hfs.findIndex((hf) => hf.ttd !== null && hf.ttd !== undefined)
if (mergeIndex < 0) {
throw Error(`Merge hardfork should have been found`)
}
hfBlock = this.hardforkBlock(hfs[mergeIndex - 1].name)
}
if (hfBlock === null) {
return null
}
// Next fork block number or null if none available
// Logic: if accumulator is still null and on the first occurrence of
// a block greater than the current hfBlock set the accumulator,
// pass on the accumulator as the final result from this time on
const nextHfBlock = this.hardforks().reduce((acc: bigint | null, hf: HardforkConfig) => {
// We need to ignore the merge block in our next hardfork calc
const block = BigInt(
hf.block === null || (hf.ttd !== undefined && hf.ttd !== null) ? 0 : hf.block
)
// Typescript can't seem to follow that the hfBlock is not null at this point
return block > hfBlock! && acc === null ? block : acc
}, null)
return nextHfBlock
}
/**
* True if block number provided is the hardfork change block following the hardfork given or set
* @param blockNumber Number of the block to check
* @param hardfork Hardfork name, optional if HF set
* @returns True if blockNumber is HF block
* @deprecated
*/
isNextHardforkBlock(blockNumber: BigIntLike, hardfork?: string | Hardfork): boolean {
blockNumber = toType(blockNumber, TypeOutput.BigInt)
hardfork = hardfork ?? this._hardfork
const nextHardforkBlock = this.nextHardforkBlock(hardfork)
return nextHardforkBlock === null ? false : nextHardforkBlock === blockNumber
}
/**
* Internal helper function to calculate a fork hash

@@ -855,4 +780,4 @@ * @param hardfork Hardfork name

*/
_calcForkHash(hardfork: string | Hardfork, genesisHash: Buffer) {
let hfBuffer = Buffer.alloc(0)
private _calcForkHash(hardfork: string | Hardfork, genesisHash: Uint8Array): PrefixedHexString {
let hfBytes = new Uint8Array(0)
let prevBlockOrTime = 0

@@ -873,6 +798,6 @@ for (const hf of this.hardforks()) {

blockOrTime !== prevBlockOrTime &&
name !== Hardfork.Merge
name !== Hardfork.Paris
) {
const hfBlockBuffer = Buffer.from(blockOrTime.toString(16).padStart(16, '0'), 'hex')
hfBuffer = Buffer.concat([hfBuffer, hfBlockBuffer])
const hfBlockBytes = hexToBytes('0x' + blockOrTime.toString(16).padStart(16, '0'))
hfBytes = concatBytes(hfBytes, hfBlockBytes)
prevBlockOrTime = blockOrTime

@@ -883,8 +808,8 @@ }

}
const inputBuffer = Buffer.concat([genesisHash, hfBuffer])
const inputBytes = concatBytes(genesisHash, hfBytes)
// CRC32 delivers result as signed (negative) 32-bit integer,
// convert to hex string
const forkhash = intToBuffer(crc32Buffer(inputBuffer) >>> 0).toString('hex')
return `0x${forkhash}`
const forkhash = bytesToHex(intToBytes(crc(inputBytes) >>> 0))
return forkhash
}

@@ -897,3 +822,3 @@

*/
forkHash(hardfork?: string | Hardfork, genesisHash?: Buffer): string {
forkHash(hardfork?: string | Hardfork, genesisHash?: Uint8Array): PrefixedHexString {
hardfork = hardfork ?? this._hardfork

@@ -932,3 +857,3 @@ const data = this._getHardfork(hardfork)

*/
setForkHashes(genesisHash: Buffer) {
setForkHashes(genesisHash: Uint8Array) {
for (const hf of this.hardforks()) {

@@ -1078,3 +1003,3 @@ const blockOrTime = hf.timestamp ?? hf.block

// The config parameter is named after the respective consensus algorithm
value = hfChanges[1]['consensus'][hfChanges[1]['consensus']['algorithm']]
value = (hfChanges[1] as any)['consensus'][hfChanges[1]['consensus']['algorithm']]
}

@@ -1093,7 +1018,7 @@ if (hfChanges[0] === hardfork) break

const copy = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
copy.removeAllListeners()
copy.events = new EventEmitter()
return copy
}
static _getInitializedChains(customChains?: ChainConfig[]): ChainsConfig {
static getInitializedChains(customChains?: ChainConfig[]): ChainsConfig {
const names: ChainName = {}

@@ -1103,3 +1028,3 @@ for (const [name, id] of Object.entries(Chain)) {

}
const chains = { mainnet, ropsten, rinkeby, goerli, sepolia } as ChainsConfig
const chains = { mainnet, goerli, sepolia } as ChainsConfig
if (customChains) {

@@ -1106,0 +1031,0 @@ for (const chain of customChains) {

{
"name": "EIP-1153",
"number": 1153,
"comment": "Transient Storage",
"comment": "Transient storage opcodes",
"url": "https://eips.ethereum.org/EIPS/eip-1153",

@@ -6,0 +6,0 @@ "status": "Review",

@@ -10,5 +10,10 @@ {

"gasConfig": {},
"gasPrices": {},
"gasPrices": {
"prevrandao": {
"v": 2,
"d": "Base fee of the PREVRANDAO opcode (previously DIFFICULTY)"
}
},
"vm": {},
"pow": {}
}

@@ -7,3 +7,3 @@ {

"status": "Draft",
"minimumHardfork": "merge",
"minimumHardfork": "paris",
"requiredEIPs": [1559, 2718, 2930, 4895],

@@ -16,11 +16,11 @@ "gasConfig": {

"targetDataGasPerBlock": {
"v": 262144,
"v": 393216,
"d": "The target data gas consumed per block"
},
"maxDataGasPerBlock": {
"v": 524288,
"v": 786432,
"d": "The max data gas allowable per block"
},
"dataGasPriceUpdateFraction": {
"v": 2225652,
"v": 3338477,
"d": "The denominator used in the exponential when calculating a data gas price"

@@ -42,5 +42,5 @@ }

},
"datahash": {
"blobhash": {
"v": 3,
"d": "Base fee of the DATAHASH opcode"
"d": "Base fee of the BLOBHASH opcode"
}

@@ -47,0 +47,0 @@ },

@@ -7,3 +7,3 @@ {

"status": "Review",
"minimumHardfork": "merge",
"minimumHardfork": "paris",
"requiredEIPs": [],

@@ -10,0 +10,0 @@ "gasConfig": {},

@@ -0,27 +1,57 @@

import * as eip1153 from './1153.json'
import * as eip1559 from './1559.json'
import * as eip2315 from './2315.json'
import * as eip2565 from './2565.json'
import * as eip2718 from './2718.json'
import * as eip2929 from './2929.json'
import * as eip2930 from './2930.json'
import * as eip3074 from './3074.json'
import * as eip3198 from './3198.json'
import * as eip3529 from './3529.json'
import * as eip3540 from './3540.json'
import * as eip3541 from './3541.json'
import * as eip3554 from './3554.json'
import * as eip3607 from './3607.json'
import * as eip3651 from './3651.json'
import * as eip3670 from './3670.json'
import * as eip3675 from './3675.json'
import * as eip3855 from './3855.json'
import * as eip3860 from './3860.json'
import * as eip4345 from './4345.json'
import * as eip4399 from './4399.json'
import * as eip4788 from './4788.json'
import * as eip4844 from './4844.json'
import * as eip4895 from './4895.json'
import * as eip5133 from './5133.json'
import * as eip5656 from './5656.json'
import * as eip6780 from './6780.json'
export const EIPs: { [key: number]: any } = {
1153: require('./1153.json'),
1559: require('./1559.json'),
2315: require('./2315.json'),
2537: require('./2537.json'),
2565: require('./2565.json'),
2718: require('./2718.json'),
2929: require('./2929.json'),
2930: require('./2930.json'),
3074: require('./3074.json'),
3198: require('./3198.json'),
3529: require('./3529.json'),
3540: require('./3540.json'),
3541: require('./3541.json'),
3554: require('./3554.json'),
3607: require('./3607.json'),
3651: require('./3651.json'),
3670: require('./3670.json'),
3675: require('./3675.json'),
3855: require('./3855.json'),
3860: require('./3860.json'),
4345: require('./4345.json'),
4399: require('./4399.json'),
4844: require('./4844.json'),
4895: require('./4895.json'),
5133: require('./5133.json'),
1153: eip1153,
1559: eip1559,
2315: eip2315,
2565: eip2565,
2718: eip2718,
2929: eip2929,
2930: eip2930,
3074: eip3074,
3198: eip3198,
3529: eip3529,
3540: eip3540,
3541: eip3541,
3554: eip3554,
3607: eip3607,
3651: eip3651,
3670: eip3670,
3675: eip3675,
3855: eip3855,
3860: eip3860,
4345: eip4345,
4399: eip4399,
4788: eip4788,
4844: eip4844,
4895: eip4895,
5133: eip5133,
5656: eip5656,
6780: eip6780,
}

@@ -0,5 +1,5 @@

import { hexToBytes } from '@ethereumjs/util'
export enum Chain {
Mainnet = 1,
Ropsten = 3,
Rinkeby = 4,
Goerli = 5,

@@ -9,2 +9,31 @@ Sepolia = 11155111,

/**
* Genesis state meta info which is decoupled from common's genesis params
*/
type GenesisState = {
/* blockNumber that can be used to update and track the regenesis marker */
blockNumber: bigint
/* stateRoot of the chain at the blockNumber */
stateRoot: Uint8Array
}
// Having this info as record will force typescript to make sure no chain is missed
/**
* GenesisState info about well known ethereum chains
*/
export const ChainGenesis: Record<Chain, GenesisState> = {
[Chain.Mainnet]: {
blockNumber: BigInt(0),
stateRoot: hexToBytes('0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544'),
},
[Chain.Goerli]: {
blockNumber: BigInt(0),
stateRoot: hexToBytes('0x5d6cded585e73c4e322c30c2f782a336316f17dd85a4863b9d838d2d4b8b3008'),
},
[Chain.Sepolia]: {
blockNumber: BigInt(0),
stateRoot: hexToBytes('0x5eb6e371a698b8d68f665192350ffcecbbbf322916f4b51bd79bb6887da3f494'),
},
}
export enum Hardfork {

@@ -26,5 +55,5 @@ Chainstart = 'chainstart',

MergeForkIdTransition = 'mergeForkIdTransition',
Merge = 'merge',
Paris = 'paris',
Shanghai = 'shanghai',
ShardingForkDev = 'shardingFork',
Cancun = 'cancun',
}

@@ -60,9 +89,2 @@

/**
* Arbitrum Rinkeby Testnet
*
* - [Documentation](https://developer.offchainlabs.com/docs/public_testnet)
*/
ArbitrumRinkebyTestnet = 'arbitrum-rinkeby-testnet',
/**
* Arbitrum One - mainnet for Arbitrum roll-up

@@ -69,0 +91,0 @@ *

@@ -37,7 +37,7 @@ {

},
"sha3": {
"keccak256": {
"v": 30,
"d": "Base fee of the SHA3 opcode"
},
"sha3Word": {
"keccak256Word": {
"v": 6,

@@ -44,0 +44,0 @@ "d": "Once per word of the SHA3 operation's data"

@@ -0,20 +1,39 @@

import * as arrowGlacier from './arrowGlacier.json'
import * as berlin from './berlin.json'
import * as byzantium from './byzantium.json'
import * as cancun from './cancun.json'
import * as chainstart from './chainstart.json'
import * as constantinople from './constantinople.json'
import * as dao from './dao.json'
import * as grayGlacier from './grayGlacier.json'
import * as homestead from './homestead.json'
import * as istanbul from './istanbul.json'
import * as london from './london.json'
import * as mergeForkIdTransition from './mergeForkIdTransition.json'
import * as muirGlacier from './muirGlacier.json'
import * as paris from './paris.json'
import * as petersburg from './petersburg.json'
import * as shanghai from './shanghai.json'
import * as spuriousDragon from './spuriousDragon.json'
import * as tangerineWhistle from './tangerineWhistle.json'
export const hardforks = {
chainstart: require('./chainstart.json'),
homestead: require('./homestead.json'),
dao: require('./dao.json'),
tangerineWhistle: require('./tangerineWhistle.json'),
spuriousDragon: require('./spuriousDragon.json'),
byzantium: require('./byzantium.json'),
constantinople: require('./constantinople.json'),
petersburg: require('./petersburg.json'),
istanbul: require('./istanbul.json'),
muirGlacier: require('./muirGlacier.json'),
berlin: require('./berlin.json'),
london: require('./london.json'),
shanghai: require('./shanghai.json'),
arrowGlacier: require('./arrowGlacier.json'),
grayGlacier: require('./grayGlacier.json'),
mergeForkIdTransition: require('./mergeForkIdTransition.json'),
merge: require('./merge.json'),
shardingFork: require('./sharding.json'),
chainstart,
homestead,
dao,
tangerineWhistle,
spuriousDragon,
byzantium,
constantinople,
petersburg,
istanbul,
muirGlacier,
berlin,
london,
shanghai,
arrowGlacier,
grayGlacier,
mergeForkIdTransition,
paris,
cancun,
}

@@ -1,4 +0,5 @@

export * from './common'
export * from './enums'
export * from './types'
export * from './utils'
export * from './common.js'
export * from './enums.js'
export * from './interfaces.js'
export * from './types.js'
export * from './utils.js'

@@ -1,2 +0,3 @@

import type { Chain, ConsensusAlgorithm, ConsensusType, Hardfork } from './enums'
import type { Chain, ConsensusAlgorithm, ConsensusType, Hardfork } from './enums.js'
import type { BigIntLike } from '@ethereumjs/util'

@@ -40,7 +41,8 @@ export interface ChainName {

timestamp?: string
gasLimit: number
difficulty: number
gasLimit: number | string
difficulty: number | string
nonce: string
extraData: string
baseFeePerGas?: string
excessDataGas?: string
}

@@ -75,7 +77,3 @@

* Selected EIPs which can be activated, please use an array for instantiation
* (e.g. `eips: [ 2537, ]`)
*
* Currently supported:
*
* - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - BLS12-381 precompiles
* (e.g. `eips: [ 1559, 3860 ]`)
*/

@@ -122,4 +120,10 @@ eips?: number[]

chain?: string
genesisHash?: Buffer
genesisHash?: Uint8Array
mergeForkIdPostMerge?: boolean
}
export interface HardforkByOpts {
blockNumber?: BigIntLike
timestamp?: BigIntLike
td?: BigIntLike
}
import { intToHex, isHexPrefixed, stripHexPrefix } from '@ethereumjs/util'
import { Hardfork } from './enums'
import { Hardfork } from './enums.js'

@@ -40,2 +40,3 @@ type ConfigHardfork =

baseFeePerGas,
excessDataGas,
}: {

@@ -49,2 +50,3 @@ name: string

baseFeePerGas: string
excessDataGas: string
} = json

@@ -83,4 +85,4 @@ let { extraData, timestamp, nonce }: { extraData: string; timestamp: string; nonce: string } =

timestamp,
gasLimit: parseInt(gasLimit), // geth gasLimit and difficulty are hex strings while ours are `number`s
difficulty: parseInt(difficulty),
gasLimit,
difficulty,
nonce,

@@ -91,2 +93,3 @@ extraData,

baseFeePerGas,
excessDataGas,
},

@@ -130,3 +133,3 @@ hardfork: undefined as string | undefined,

[Hardfork.Shanghai]: { name: 'shanghaiTime', postMerge: true, isTimestamp: true },
[Hardfork.ShardingForkDev]: { name: 'shardingForkTime', postMerge: true, isTimestamp: true },
[Hardfork.Cancun]: { name: 'cancunTime', postMerge: true, isTimestamp: true },
}

@@ -172,3 +175,3 @@

const mergeConfig = {
name: Hardfork.Merge,
name: Hardfork.Paris,
ttd: config.terminalTotalDifficulty,

@@ -175,0 +178,0 @@ block: null,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc