Skip to content
Merged
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
9 changes: 0 additions & 9 deletions packages/devp2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@ Events emitted:
| message | Message received |
| status | Status info received |

### Reference

- [Light client protocol](https://ethereum.org/en/developers/docs/nodes-and-clients/#light-node)

## Debugging

### Introduction
Expand Down Expand Up @@ -453,11 +449,6 @@ The following is a list of major implementations of the `devp2p` stack in other

- Python: [pydevp2p](https://github.com/ethereum/pydevp2p)
- Go: [Go Ethereum](https://github.com/ethereum/go-ethereum/tree/master/p2p)
- Elixir: [Exthereum](https://github.com/exthereum/exth_crypto) <!-- cspell:disable-line --->

### Links

- [Blog article series](https://ocalog.com/post/10/) on implementing Ethereum protocol stack

## EthereumJS

Expand Down
36 changes: 18 additions & 18 deletions packages/era/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ npm install @ethereumjs/era
All helpers are re-exported from the root level and deep imports are not necessary. So an import can be done like this:

```ts
import { formatEntry } from "@ethereumjs/era";
import { formatEntry } from "@ethereumjs/era"
```

### Export History as Era1

Export history in epochs of 8192 blocks as Era1 files

```ts
import { exportEpochAsEra1 } from "@ethereumjs/era";
import { exportEpochAsEra1 } from "@ethereumjs/era"

const dataDir = PATH_TO_ETHEREUMJS_CLIENT_DB;
const epoch = 0;
const dataDir = PATH_TO_ETHEREUMJS_CLIENT_DB
const epoch = 0

// generates ${dataDir}/era1/epoch-0.era1
await exportEpochAsEra1(epoch, dataDir);
await exportEpochAsEra1(epoch, dataDir)
```

### Read Era1 file
Expand All @@ -52,37 +52,37 @@ import {
blockFromTuple,
getHeaderRecords,
EpochAccumulator,
} from "@ethereumjs/era";
} from "@ethereumjs/era"

const era1File = readBinaryFile(PATH_TO_ERA1_FILE);
const era1File = readBinaryFile(PATH_TO_ERA1_FILE)

// validate era1 file
const isValid = validateERA1(era1File);
const isValid = validateERA1(era1File)

// read blocks from era1 file
const blocks = readERA1(era1File);
const blocks = readERA1(era1File)

for await (const blockTuple of blocks) {
const { header, body, receipts } = await parseBlockTuple(blockTuple);
const block = blockFromTuple({ header, body });
console.log(block.header.number);
const { header, body, receipts } = await parseBlockTuple(blockTuple)
const block = blockFromTuple({ header, body })
console.log(block.header.number)
}

// reconstruct epoch accumulator
const headerRecords = await getHeaderRecords(era1File);
const epochAccumulator = EpochAccumulator.encode(headerRecords);
const epochAccumulatorRoot = EpochAccumulator.merkleRoot(headerRecords);
const headerRecords = await getHeaderRecords(era1File)
const epochAccumulator = EpochAccumulator.encode(headerRecords)
const epochAccumulatorRoot = EpochAccumulator.merkleRoot(headerRecords)
```

### Read Era file

```ts
import { readBeaconState } from "@ethereumjs/era";
import { readBeaconState } from "@ethereumjs/era"

const eraFile = readBinaryFile(PATH_TO_ERA_FILE);
const eraFile = readBinaryFile(PATH_TO_ERA_FILE)

// Extract BeaconState
const state = await readBeaconState(eraFile);
const state = await readBeaconState(eraFile)
console.log(state.slot)

// Read Beacon Blocks from era file
Expand Down
45 changes: 11 additions & 34 deletions packages/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ npm install @ethereumjs/evm

This package provides the core Ethereum Virtual Machine (EVM) implementation which is capable of executing EVM-compatible bytecode. The package has been extracted from the [@ethereumjs/vm](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/vm) package along the VM `v6` release.

**Note:** Starting with the Dencun hardfork `EIP-4844` related functionality will become an integrated part of the EVM functionality with the activation of the point evaluation precompile. It is therefore strongly recommended to _always_ run the EVM with a KZG library installed and initialized, see [KZG Setup](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx/README.md#kzg-setup) for instructions.
**Note:** Starting with the Dencun hardfork `EIP-4844` related functionality has become an integrated part of the EVM functionality with the activation of the point evaluation precompile. For this precompile to work a separate installation of the KZG library is necessary (we decided not to bundle due to large bundle sizes), see [KZG Setup](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx/README.md#kzg-setup) for instructions.

## Usage

### Basic

With the v2 release (Summer 2023) the EVM/VM packages have been further decoupled and it now possible to run the EVM package in isolation with reasonable defaults.

The following is the simplest example for an EVM instantiation:
The following is the simplest example for an EVM instantiation with reasonable defaults for state and blockchain information (like blockhashes):

```ts
// ./examples/simple.ts
Expand All @@ -44,8 +42,6 @@ const main = async () => {
void main()
```

Note: with the switch from v2 to v3 the old direct `new EVM()` constructor usage has been deprecated and an `EVM` now has to be instantiated with the async static `EVM.create()` constructor.

### Blockchain, State and Events

If the EVM should run on a certain state an `@ethereumjs/statemanager` is needed. An `@ethereumjs/blockchain` instance can be passed in to provide access to external interface information like a blockhash:
Expand Down Expand Up @@ -139,7 +135,7 @@ void main()

### EIP-2537 BLS Precompiles (Prague)

Starting with `v3.1.0` the EVM support the BLS precompiles introduced with [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537). These precompiles run natively using the [@noble/curves](https://github.com/paulmillr/noble-curves) library (❤️ to `@paulmillr`!).
Starting with `v10` the EVM supports the BLS precompiles introduced with [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) in its final version introduced with the `Prague` hardfork. These precompiles run natively using the [@noble/curves](https://github.com/paulmillr/noble-curves) library (❤️ to `@paulmillr`!).

An alternative WASM implementation (using [bls-wasm](https://github.com/herumi/bls-wasm)) can be optionally used like this if needed for performance reasons:

Expand All @@ -149,17 +145,12 @@ import { EVM, MCLBLS } from '@ethereumjs/evm'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Prague })
await mcl.init(mcl.BLS12_381)
const mclbls = new MCLBLS(mcl)
const evm = await EVM.create({ common, bls })
const evm = await createEVM({ common, bls })
```

## Examples

This projects contain the following examples:

1. [./examples/decode-opcodes](./examples/decode-opcodes.ts): Decodes a binary EVM program into its opcodes.
1. [./examples/runCode](./examples/runCode.ts): Show how to use this library in a browser.

All of the examples have their own `README.md` explaining how to run them.
See the [examples](./examples/) folder for different meaningful examples on how to use the EVM package and invoke certain aspects of it, e.g. running a bytecode snippet, listening to events or activate an EVM with a certain EIP for experimental purposes.

## Browser

Expand Down Expand Up @@ -232,8 +223,9 @@ Currently the following hardfork rules are supported:
- `merge`
- `shanghai` (`v2.0.0`+)
- `cancun` (`v2.0.0`+)
- `prague` (`v10`+)

Default: `shanghai` (taken from `Common.DEFAULT_HARDFORK`)
Default: `prague` (taken from `Common.DEFAULT_HARDFORK`)

A specific hardfork EVM ruleset can be activated by passing in the hardfork
along the `Common` instance to the outer `@ethereumjs/vm` instance.
Expand Down Expand Up @@ -300,24 +292,9 @@ Currently supported EIPs:

This library by default uses JavaScript implementations for the basic standard crypto primitives like hashing or signature verification (for included txs). See `@ethereumjs/common` [README](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/common) for instructions on how to replace with e.g. a more performant WASM implementation by using a shared `common` instance.

### EIP-4844 Shard Blob Transactions Support

This library supports the blob transaction type introduced with [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844).

#### Initialization

To run EVM related EIP-4844 functionality you have to active the EIP in the associated `@ethereumjs/common` library:

```ts
// ./examples/4844.ts

import { Common, Hardfork, Mainnet } from '@ethereumjs/common'

const common = new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai, eips: [4844] })
```
### EIP-4844 Shard Blob Transactions Support (Cancun)

EIP-4844 comes with a new opcode `BLOBHASH` (Attention! Renamed from `DATAHASH`) and adds a new point evaluation precompile at address `0x0a`
(moved from `0x14` at some point along spec updates).
This library supports the blob transaction type introduced with [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844). EIP-4844 comes with a dedicated opcode `BLOBHASH` and has added a new point evaluation precompile at address `0x0a`.

**Note:** Usage of the point evaluation precompile needs a manual KZG library installation and global initialization, see [KZG Setup](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx/README.md#kzg-setup) for instructions.

Expand Down Expand Up @@ -441,9 +418,9 @@ TODO: this section likely needs an update.

## Profiling the EVM

Starting with the `v2.1.0` release the EVM comes with build-in profiling capabilities to detect performance bottlenecks and to generally support the targeted evolution of the JavaScript EVM performance.
The EthereumJS EVM comes with build-in profiling capabilities to detect performance bottlenecks and to generally support the targeted evolution of the JavaScript EVM performance.

While the EVM now has a dedicated `profiler` setting to activate, the profiler can best and most useful be run through the EthereumJS [client](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/client) since this gives the most realistic conditions providing both real-world txs and a meaningful state size.
While the EVM has a dedicated `profiler` setting to activate, the profiler can best and most useful be run through the EthereumJS [client](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/client) since this gives the most realistic conditions providing both real-world txs and a meaningful state size.

To repeatedly run the EVM profiler within the client sync the client on mainnet or a larger testnet to the desired block. Then the profiler should be run without sync (to not distort the results) by using the `--executeBlocks` and the `--vmProfileBlocks` (or `--vmProfileTxs`) flags in conjunction like:

Expand Down
1 change: 1 addition & 0 deletions packages/tx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Hardforks adding features and/or tx types:
| `berlin` | `v3.1.0` |  `EIP-2718` Typed Transactions, Optional Access Lists Tx Type `EIP-2930` |
| `london` | `v3.2.0` | `EIP-1559` Transactions |
| `cancun` | `v5.0.0` | `EIP-4844` Transactions |
| `prague` | `v10.0.0` | `EIP-7702` Transactions |

### WASM Crypto Support

Expand Down
Loading