Skip to content

Commit

Permalink
tx: Update eip4844 txs to decoupled blobs spec (#2567)
Browse files Browse the repository at this point in the history
* `Buffer` to `Uint8Array` conversion (#2566)

* V7 update to master 1 (#2593)

* Added v7 release reference in main README table (#2562)

* common: Schedule shanghai on goerli (#2563)

* common: Schedule shanghai on goerli

* update timestamp

* util/tx: Shift ssz back to case dependency free ES2019 compatible version (#2564)

* util/tx: Shift ssz back to case dependency free ES2019 compatible version

* update package lock

* update karma ecma version

* VM: some optimization on the bnadd/bnmul precompiles to only copy over the necessary 128 bytes as input for the WASM call (#2568)

* EVM: Memory Fix & Other Optimizations (#2570)

* EVM: Rename evm debug logger to evm:evm (one for package, one for class), consistency, also, logger will otherwise be left out when run with evm:*

* VM: Rename message checkpoint to state checkpoint in debug message (there is a dedicated message checkpoint msg along msg logging)

* EVM: CALL/CREATE debug exit msg differentiation

* EVM: avoid buffer copy in memory read (performance)

* EVM: Rewrite runCall() checkpoint/revert conditional for readability/simplification

* EVM: Added EIP check for transient storage checkpointing

* EVM: Precompile Debug Logger Improvements (#2572)

* EVM: Added general precompile debug logger setup, first ECRECOVER exemplary debug logging

* EVM: Added remaining precompile debug loggers

* EVM: added error cases to BLS precompile debug log

* EVM: Added missing precompile return value debug logs

* Small fixes

* tx: ensure eip3860 txs can have more than max_initcode_size data if to field is non-empty (#2575)

* EVM: Avoid memory.read() Memory Copy (#2573)

* EVM: added avoidCopy parameter to memory.read() function, first test on CREATE opcode

* EVM: Add direct memory read to all calling opcodes

* EVM: Copy over memory on IDENTITY precompile

* EVM: remove length checks and return buffer 0-filling in Memory.read() (memory is uncoditionally being extended properly anyhow)

* Some optimizations

* blockchain: fix merge->clique transition (#2571)

* Client: ensure safe/finalized blocks are part of the canonical chain on forkchoiceUpdated (#2577)

* client/engine: ensure finalized/safe blocks are in canonical chain

* client: engine-api: fix finalized block check

* client/tests: fix forkchoice updated test

* client: add fcu tests to check if blocks are part of canonical chain

* client/engine: ensure payload has a valid timestamp forkchoiceUpdated (#2579)

* client/engine: ensure invalid blockhash response matches spec (#2583)

* client/engine: delete invalid skeleton blocks (#2584)

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>

* Setup to dev/test snapsync with sim architecture (#2574)

* Setup to dev/test snapsync with sim architecture

* modfiy single-run to setup a lodestar<>geth node to snapsync from

* setup an ethereumjs inline client and get it to peer with geth

* cleanup setup a bit

* snapsync run spec

* get the snap testdev sim working

* finalize the test infra and update usage doc

* enhance coverage

* Use geth RPC to connect to ethJS

* refac wait for snap sync completion

---------

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>

* client: Add safe and finalized blockoptions to the chain (#2585)

* client: Add safe and finalized blockoptions to the chain

* fix tests

* fix more tests

* fix remaining

* cleanup

* enhance coverage

* unset scheduled goerli timestamp based hfs colliding with test

* Client: Small Debug Helpers and CLI Improvements (#2586)

* Client: new constant MAX_TOLERATED_BLOCK_TIME for execution, added warning for slowly executed blocks

* Client -> Execution: NumBlocksPerIteration (default: 50) as an option

* Client: only restart RLPx server or log peer stats if max peers is set to be greater than 0

* Apply suggestions from code review

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>

* Apply suggestions from code review

---------

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>

* common: Schedule Shanghai on mainnet! (#2591)

* common: Schedule Shanghai on mainnet!

* clear hf timestamp for test

* VM: Diff-based Touched Accounts Checkpointing (#2581)

* VM: Switched to a more efficient diff-based way of touched account checkpointing

* VM: move accessed storage inefficient checkpointing problem to berlin, haha

* EVM: avoid memory copy in MLOAD opcode function

* Remove console.log() in EVM

* vmState: ensure touched accounts delete stack gets properly updated on commit

* vm/eei: save touched height

* vm/vmState: new possible fix for touched accounts

* vm/vmState: another attempt to fix touched accounts journaling

* vm: add journaling

* Check correct journal height on revert

---------

Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>

---------

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
Co-authored-by: g11tech <gajinder@g11.in>
Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>

* First pass - most util changes

* Fix most account stuff

* Fix account test

* Many byte fixes

* util: fix constants tests

* remaining fixes

* Turn off ci jobs

* monorepo: bigIntToUnpaddedBuffer -> bigIntToUnpaddedBytes

* util: update description of bytes exporT

* util: remove unused import

* common: use bytesToHex helper instead of toString('hex')

* trie: refactor non-test files to Uint8Array

* util: add binary string utils

* util: remove extra Uint8Array.from

* util: remove arrToBufArray util

* trie: adjust tests and fix outstanding issues

* util: remove binarystring utils and add compareBytes and randomBytes util

* common: refactor common with Uint8Array

* util: accept 0x-prefixed and non-prefixed hex strings in toBytes

* tx: refactor Buffer -> Uint8Array

* tx: remove unused import

* util: revert toBytes update

* block: refactor Buffer -> uint8array

* block: adjust import

* trie: refactor remaining buffer instances

* move devp2p to uint8Array

* statemanager: refactor buffer -> uint8array

* util: simplify zeros

* util: add concatBytesUnsafe

* ethash: partial migration

* ethash: update examples

* ethash: wip fixes

* ethash: more WIP

* ethash: ensure fnv input is read from mix, not mixView

* blockchain: migrate to uint8array

* ethash: renable all tests

* ethash: fix bytesReverse

* Fix miner tests

* many hexToBytes moves

* most of evm/vm moves

* evm: Fix all tests

* vm: more fixes

* More fixes

* vm: fix receipts encoding

* vm: fix tester

* client: refactor buffer to uint8array

* client: additional uint8 adjustments

* client: fix most tests

* fix remaining client unit tests

* reactivate most CI

* client: fix les test/protocol

* turn client CI on

* util: fix name typo

* lint

* Fix withdrawals

* remove buffarraytoarr

* Remove bufArrtoArr references

* Lint

* fix examples

* Fix difficulty test

* lint

* block: update randomBytes import

* replace randombytes import

* client: fix sim test util

* vm: fix example

* devp2p: update snappy typing and fix tests

* Fix tests

* Remove additional buffer references

* rustbn fixes

* add 0x prefix to precompile address

* Remove `node-ip` dependency and buffer references in devp2p

* Switch slice to subarray

* evm: fix blake2f

* Merge fixes

* more merge commit fixes

* more test fixes

* Address all the feedback

* fix dns test

* Update packages/util/src/bytes.ts

Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>

* Fix return type for baToJSON

* util: instantiate hexByByte array

* Remove baToJson

* rebase fixes

* Fix event typing

* Revert outdated initcode changes

* lint

---------

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
Co-authored-by: g11tech <gajinder@g11.in>
Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
Co-authored-by: Gabriel Rocheleau <contact@rockwaterweb.com>

* Devp2p status fix

* Remove buffer detritus

* Switch db to view

* buffer cleanup

* Correctly parse heads from DB

* Fix encodings

* Cast db values to uint8array

* Fix db bug in ethash

* Remove unused peerId check

* Add pow miner test

* Finish test

* Move pow test to integration tests

* client: lint

* rename test helper

* Add timeout to PoW test

* Update eip4844 txs to decoupled blobs spec

* fix sharding spec and blobtx

* fix the sharding muli client run

* fix args

* fix compatibility with latest lodestar branch

* update test help

* Fix fee market test

* lint

* Move all kzg stuff to util

* Various cleanup

* Update to latest c-kzg

* Fix utils

* Remove outdated kzg references

* Fix client tests

* Update c-kzg dep

* Fix karma, remove Buffer references

---------

Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
Co-authored-by: Gabriel Rocheleau <contact@rockwaterweb.com>
  • Loading branch information
5 people committed Apr 11, 2023
1 parent ec2494c commit 3b0934f
Show file tree
Hide file tree
Showing 32 changed files with 243 additions and 168 deletions.
38 changes: 23 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function (config) {
acornOptions: {
ecmaVersion: 12,
},
ignore: ['c-kzg'],
},
},
concurrency: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@types/lru-cache": "^5.1.0",
"c-kzg": "^1.0.8"
"c-kzg": "^2.0.4"
},
"engines": {
"node": ">=14"
Expand Down
7 changes: 4 additions & 3 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import {
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { randomBytes } from '@ethereumjs/util'
initKZG,
randomBytes,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import * as tape from 'tape'

Expand Down
2 changes: 1 addition & 1 deletion packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Block } from '@ethereumjs/block'
import { Blockchain, parseGethGenesisState } from '@ethereumjs/blockchain'
import { Chain, Common, ConsensusAlgorithm, Hardfork } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { initKZG } from '@ethereumjs/tx'
import {
Address,
bytesToHex,
bytesToPrefixedHexString,
hexStringToBytes,
initKZG,
randomBytes,
short,
toBytes,
Expand Down
10 changes: 7 additions & 3 deletions packages/client/devnets/4844-interop/tools/txGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Adapted from - https://github.com/Inphi/eip4844-interop/blob/master/blob_tx_generator/blob.js
import { Common, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import {
Address,
initKZG,
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { Address, bytesToPrefixedHexString, hexStringToBytes } from '@ethereumjs/util'
bytesToPrefixedHexString,
hexStringToBytes,
} from '@ethereumjs/util'

import * as kzg from 'c-kzg'
import { randomBytes } from '@ethereumjs/util'
import { Client } from 'jayson/promise'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
"@ethereumjs/vm": "6.4.1",
"abstract-level": "^1.0.3",
"body-parser": "^1.19.2",
"c-kzg": "^2.0.4",
"chalk": "^4.1.2",
"connect": "^3.7.0",
"cors": "^2.8.5",
"c-kzg": "^1.0.8",
"debug": "^4.3.3",
"ethereum-cryptography": "^1.1.2",
"fs-extra": "^10.1.0",
Expand Down
20 changes: 8 additions & 12 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Block, BlockHeader } from '@ethereumjs/block'
import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, Transaction, initKZG } from '@ethereumjs/tx'
import {
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { BlobEIP4844Transaction, Transaction } from '@ethereumjs/tx'
import {
Account,
Address,
blobsToCommitments,
bytesToHex,
bytesToPrefixedHexString,
commitmentsToVersionedHashes,
equalsBytes,
getBlobs,
hexStringToBytes,
initKZG,
randomBytes,
} from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
Expand Down Expand Up @@ -260,11 +259,9 @@ tape('[PendingBlock]', async (t) => {

t.test('construct blob bundles', async (st) => {
try {
kzg.freeTrustedSetup()
} catch {
/** ensure kzg is setup */
}
initKZG(kzg, __dirname + '/../../lib/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../lib/trustedSetups/devnet4.txt')
// eslint-disable-next-line
} catch {}
const gethGenesis = require('../../../block/test/testdata/4844-hardfork.json')
const common = Common.fromGethGenesis(gethGenesis, {
chain: 'customChain',
Expand Down Expand Up @@ -297,7 +294,6 @@ tape('[PendingBlock]', async (t) => {
await pendingBlock.build(payloadId)
const pendingBlob = pendingBlock.blobBundles.get(bytesToPrefixedHexString(payloadId))?.blobs[0]
st.ok(pendingBlob !== undefined && equalsBytes(pendingBlob, blobs[0]))
kzg.freeTrustedSetup()
st.end()
})
t.test('should reset td', (st) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/engine/getBlobsBundleV1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hardfork } from '@ethereumjs/common'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import { TransactionFactory, initKZG } from '@ethereumjs/tx'
import { Address, hexStringToBytes } from '@ethereumjs/util'
import { TransactionFactory } from '@ethereumjs/tx'
import { Address, hexStringToBytes, initKZG } from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import * as tape from 'tape'

Expand Down
28 changes: 12 additions & 16 deletions packages/client/test/rpc/eth/sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { BlockHeader } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import {
BlobEIP4844Transaction,
FeeMarketEIP1559Transaction,
Transaction,
initKZG,
} from '@ethereumjs/tx'
import { BlobEIP4844Transaction, FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx'
import {
blobsToCommitments,
bytesToPrefixedHexString,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { bytesToPrefixedHexString, hexStringToBytes, randomBytes } from '@ethereumjs/util'
hexStringToBytes,
initKZG,
randomBytes,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import * as tape from 'tape'

Expand Down Expand Up @@ -213,11 +211,9 @@ tape('blob EIP 4844 transaction', async (t) => {
const consensusFormatValidation = BlockHeader.prototype._consensusFormatValidation
BlockHeader.prototype._consensusFormatValidation = (): any => {}
try {
kzg.freeTrustedSetup()
} catch {
// NOOP - just verifying KZG is ready if not already
}
initKZG(kzg, __dirname + '/../../../lib/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../lib/trustedSetups/devnet4.txt')
// eslint-disable-next-line
} catch {}
const gethGenesis = require('../../../../block/test/testdata/4844-hardfork.json')
const common = Common.fromGethGenesis(gethGenesis, {
chain: 'customChain',
Expand All @@ -232,14 +228,14 @@ tape('blob EIP 4844 transaction', async (t) => {
const blobs = getBlobs('hello world')
const commitments = blobsToCommitments(blobs)
const versionedHashes = commitmentsToVersionedHashes(commitments)
const proof = kzg.computeAggregateKzgProof(blobs.map((blob) => Uint8Array.from(blob)))
const proofs = blobs.map((blob, ctx) => kzg.computeBlobKzgProof(blob, commitments[ctx]))
const pk = randomBytes(32)
const tx = BlobEIP4844Transaction.fromTxData(
{
versionedHashes,
blobs,
kzgCommitments: commitments,
kzgProof: proof,
kzgProofs: proofs,
maxFeePerDataGas: 1000000n,
gasLimit: 0xffffn,
maxFeePerGas: 10000000n,
Expand All @@ -254,7 +250,7 @@ tape('blob EIP 4844 transaction', async (t) => {
versionedHashes,
blobs,
kzgCommitments: commitments,
kzgProof: proof,
kzgProofs: proofs,
maxFeePerDataGas: 1000000n,
gasLimit: 0xfffffn,
maxFeePerGas: 100000000n,
Expand Down
28 changes: 21 additions & 7 deletions packages/client/test/sim/4844.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ Note: All commands should be run from the `client` package directory root (so so

## Running a local devnet

To run a single EthereumJS client <> Lodestar CL client for testing, run the following command:
`NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.EIP4844_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:4844-ae177e DATADIR=path/to/your/data/directory test/sim/./single-run.sh`
Step 1. To run a single EthereumJS client <> Lodestar CL client for testing, run the following command:
`NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:decoupled DATADIR=path/to/your/data/directory test/sim/./single-run.sh`

To run a second EthereumJS <> Lodestar pair, use this command:
`MULTIPEER=syncpeer NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.EIP4844_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:4844-ae177e DATADIR=path/to/your/data/directory test/sim/./single-run.sh`
Step 2. (Optional) To run a second EthereumJS <> Lodestar pair, use this command:
`MULTIPEER=syncpeer NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:decoupled DATADIR=path/to/your/data/directory test/sim/./single-run.sh`

To send a single blob transaction to the network, you can use the `txGenerator.ts` script as follows:
Step 3. To send a single blob transaction to the network, you may just run spec test:
`EXTERNAL_RUN=true npm run tape -- test/sim/sharding.spec.ts`

OR, you can use the `txGenerator.ts` script as follows:

`ts-node test/sim/txGenerator 8545 'hello'`. The first argument is the port number of the EthereumJS client you which to submit the transaction to and the second is any data to include in the blob.

This script was adapted from the [interop repo blob script](https://github.com/Inphi/eip4844-interop/blob/master/blob_tx_generator/blob.js)


## EIP-4844 spec tests

To run the 4844 spec tests contained in `test/sim/sharding.spec.ts`, use the following command:
You don't need to externally start the nodes, the sim tests will do all that for you as well as run the tests against it.

Run Step 1 & 3 together:

`LODE_IMAGE=g11tech/lodestar:decoupled DATADIR=path/to/your/data/directory npm run tape --
test/sim/sharding.spec.ts`


### Run Step 1, 2 & 3 together


`EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.EIP4844_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:4844-ae177e DATADIR=/absolute/path/to/your/data/dir npm run tape -- test/sim/sharding.spec.ts`
`WITH_PEER=syncpeer LODE_IMAGE=g11tech/lodestar:decoupled DATADIR=path/to/your/data/directory npm run tape --
test/sim/sharding.spec.ts`

Note, these tests are adapted from the specification tests contained in the [EIP-4844 Interop repo](https://github.com/Inphi/eip4844-interop)
Loading

0 comments on commit 3b0934f

Please sign in to comment.