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-4844 #2349

Merged
merged 199 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 171 commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
1311730
common: eip4844 scaffolding
acolytec3 Oct 12, 2022
66396f7
tx: blob transaction scaffolding
acolytec3 Oct 12, 2022
fa2108c
common: update min hardfork to merge
acolytec3 Oct 12, 2022
9c24014
SSZ types for blob transactions
acolytec3 Oct 12, 2022
48ac2ab
Add tx serialization methods
acolytec3 Oct 12, 2022
7004b73
Add constructor tests
acolytec3 Oct 13, 2022
b508fdd
Add invalid scenario checks and tests
acolytec3 Oct 13, 2022
d180551
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 9, 2022
f6c05b5
Add hash function
acolytec3 Nov 9, 2022
4ca5fcd
Add network wrapper types
acolytec3 Nov 9, 2022
9ad243e
Fix tests
acolytec3 Nov 9, 2022
b33b6ca
Add signature elements to serialization
acolytec3 Nov 9, 2022
c1f2d64
Rename static constructor
acolytec3 Nov 9, 2022
2bc3c02
Add network and minimal encoding/decoding updates
acolytec3 Nov 10, 2022
f951c1e
Block and common updates
acolytec3 Nov 10, 2022
139e386
Add header tests
acolytec3 Nov 10, 2022
979fefc
blockchain: validate blob transaction fees
acolytec3 Nov 11, 2022
a2fab83
block: address feedback
acolytec3 Nov 11, 2022
1525cb7
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 11, 2022
5242c9f
evm: add HASH opcode and versionedHashes to runstate
acolytec3 Nov 11, 2022
dbce65c
vm: Add tx validity checks to `runTx`
acolytec3 Nov 11, 2022
cf3db99
evm: add scaffolding for precompile
acolytec3 Nov 11, 2022
119feee
Fix test
acolytec3 Nov 11, 2022
e22e68f
Add c-kzg bindings and basic blob generation test
acolytec3 Nov 12, 2022
e519750
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 14, 2022
f93e285
switch c-kzg to npm dependency
acolytec3 Nov 14, 2022
075012a
Fix blob network wrapper test
acolytec3 Nov 14, 2022
ed66733
Correect test description
acolytec3 Nov 14, 2022
a9ca1bb
move stuff around
acolytec3 Nov 14, 2022
7e4bbee
Update precompile to verify versioned hash
acolytec3 Nov 14, 2022
cca637b
Add sharding hardfork
acolytec3 Nov 15, 2022
e6a748c
remove merge changes
acolytec3 Nov 15, 2022
f1d7aae
Fix sharding fork name
acolytec3 Nov 15, 2022
0e6916c
Comment out 4895 stuff
acolytec3 Nov 15, 2022
97abbb4
correctly set hf order
g11tech Nov 15, 2022
35ad864
Disable consensus validation for now
acolytec3 Nov 17, 2022
add2ae2
correctly set hf order
g11tech Nov 15, 2022
dc1c190
test specs
g11tech Nov 17, 2022
2d3db2b
fix the merge hf push condition
g11tech Nov 18, 2022
c7f8162
try placing merge block in better wat
g11tech Nov 18, 2022
a671e21
fix test spec for kiln
g11tech Nov 18, 2022
2a1c0f9
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 21, 2022
422afb6
Merge branch 'g11tech/fix-geth-genesis-parse' into eip4844-tx-changes
acolytec3 Nov 22, 2022
dd753a5
Set hardfork block to 0 to ensure we pick up the correct genesis cons…
acolytec3 Nov 22, 2022
89ad6ba
Set appropriate defaults; fix tests
acolytec3 Nov 22, 2022
103f016
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 22, 2022
0ba1c41
Add stub of getBlobsBundle API
acolytec3 Nov 22, 2022
19d333d
oops
acolytec3 Nov 22, 2022
50e99ff
oops again
acolytec3 Nov 22, 2022
c3a82d0
Add simple tests for getBlobsBundle
acolytec3 Nov 22, 2022
fa6f97c
Fix error messaging
acolytec3 Nov 22, 2022
5dee6a0
Update kzg dep
acolytec3 Nov 23, 2022
0a754ce
Fix vm tests
acolytec3 Nov 23, 2022
bba712a
Fix tx test
acolytec3 Nov 23, 2022
12095e0
Hold on to pending blocks until blobs retrieved
acolytec3 Nov 23, 2022
56e74f3
Fix getBlobsBundle lookup
acolytec3 Nov 23, 2022
71a6f35
Handling for minimal tx representation in blocks
acolytec3 Nov 23, 2022
8551c37
Create and return blob bundles when requested
acolytec3 Nov 23, 2022
3456a5f
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Nov 28, 2022
21cc321
Create blobs bundle when payload initially created
acolytec3 Nov 28, 2022
c27edee
block: add excessDataGas to json typing
acolytec3 Nov 30, 2022
980bb1e
Add sharding to EVM
acolytec3 Nov 30, 2022
3d676f5
Add excessDataGas to various VM/client spots where needed
acolytec3 Nov 30, 2022
7d67916
Add miner deets from interop repo - remove these later
acolytec3 Nov 30, 2022
ecd9df9
Fix blob bundle builder logic
acolytec3 Nov 30, 2022
78ed86d
Add networkwrapper serializer and sendRawTx fixes
acolytec3 Nov 30, 2022
7380500
Add reference on txGenerator script
acolytec3 Nov 30, 2022
f37e659
Fixes for jsonTx output
acolytec3 Nov 30, 2022
ff3df9d
push excessDataGas when creating raw blockheader
acolytec3 Dec 1, 2022
3ca46ca
Update defaults for withdrawals/datagas
acolytec3 Dec 1, 2022
503bd89
add number to estimateGas
acolytec3 Dec 1, 2022
d66af96
Add empty withdrawals field if 4895 is active when computing tx gas
acolytec3 Dec 1, 2022
15c4678
Fix gasLimit deserialization
acolytec3 Dec 1, 2022
aa2dd8e
Include excess data gas in header
acolytec3 Dec 1, 2022
de1df69
Add missing fields to serialization
acolytec3 Dec 1, 2022
ecc5adc
txGenerator hacks
acolytec3 Dec 2, 2022
3e09204
Fix logic bug in txPool.add
acolytec3 Dec 2, 2022
f069636
implement getUpfrontCost
acolytec3 Dec 2, 2022
0cbf970
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Dec 5, 2022
0d83e7a
sharding sim
g11tech Dec 6, 2022
9d6d79b
fix block building for postmerge hfs
g11tech Dec 6, 2022
5dd1c95
add debug for ethereumjs log
g11tech Dec 6, 2022
d065416
Fix nonce ssz type
acolytec3 Dec 6, 2022
bc26a07
Fix constructBlobBundles
acolytec3 Dec 6, 2022
8067e71
Update chain Id
acolytec3 Dec 7, 2022
2668cc6
update precompile to match latest spec
acolytec3 Dec 7, 2022
5d5ba11
add v3 methods for 4844 handling
g11tech Dec 8, 2022
4719957
fix rhe blobs type
g11tech Dec 8, 2022
fc69d81
Fix signed tx container field order
acolytec3 Dec 8, 2022
f374fe7
Fix hash function and renable all tests
acolytec3 Dec 8, 2022
bf7af99
Add hashing test
acolytec3 Dec 8, 2022
eaf27af
Add signature verification tests
acolytec3 Dec 8, 2022
96b75a3
Tweaks
acolytec3 Dec 8, 2022
c92a739
Update trusted setup to match lodestar
acolytec3 Dec 8, 2022
011b422
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Dec 8, 2022
d6ba9df
update txGenerator
acolytec3 Dec 9, 2022
7274965
fix field name
g11tech Dec 9, 2022
1568da5
update kzg lib
g11tech Dec 14, 2022
e1c9310
Update precompile to verify proof
acolytec3 Dec 14, 2022
873de3f
Move BLS_MODULUS to util
acolytec3 Dec 14, 2022
4a03807
Update opcode name to match spec
acolytec3 Dec 14, 2022
73b5f32
Skip blob txns when sending Txns devp2p msg
acolytec3 Dec 14, 2022
5be8fc9
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Dec 14, 2022
5eb3b89
Rename shardingfork
acolytec3 Dec 14, 2022
203f1ab
Enum/hardfork updates
acolytec3 Dec 14, 2022
c8b6cb5
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Dec 15, 2022
ec4ed68
Revert setHardforkByBlocknumber changes
acolytec3 Dec 15, 2022
da01590
Add missing eth methods to engine RPC port
acolytec3 Dec 15, 2022
cbc3dcd
set hardfork by time fixes
g11tech Dec 16, 2022
13add05
further cleanup
g11tech Dec 16, 2022
ea8812d
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Dec 17, 2022
19b2b13
merge fixes
g11tech Dec 17, 2022
3809cc8
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Dec 18, 2022
318c381
sim util for sharding hf
g11tech Dec 18, 2022
b1a6d7c
add sharding spec sim
g11tech Dec 18, 2022
bb92c2f
Add first blob tx test
acolytec3 Dec 19, 2022
34ac192
Fix excess data gas calc logic
acolytec3 Dec 19, 2022
443e890
Reorganize runTx balance checks
acolytec3 Dec 20, 2022
5ff4ab9
Fix excess data gas inclusion in buildBlock
acolytec3 Dec 20, 2022
37c51d3
add datagas fee to tx cost
acolytec3 Dec 20, 2022
6880b9a
Add todo for datagas tests
acolytec3 Dec 20, 2022
e038c8d
Address feedback and fix tests
acolytec3 Dec 20, 2022
933f61a
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Dec 20, 2022
fa53643
Fix common tests
acolytec3 Dec 21, 2022
5e4d836
Fix block blob helper and add tests
acolytec3 Dec 21, 2022
9c81ebd
run with sync peer
g11tech Dec 21, 2022
28451f5
Update EIP constants in common
acolytec3 Dec 21, 2022
28f143d
Add fee market test
acolytec3 Dec 21, 2022
ff3fa82
Remove excess console logs
acolytec3 Dec 21, 2022
053bc35
Fix pooled txn hashes logic
acolytec3 Dec 22, 2022
d0a9766
Cleanup/readme updates
acolytec3 Dec 22, 2022
0683ed6
Various tweaks
acolytec3 Dec 22, 2022
f59e247
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Dec 23, 2022
da7d3ec
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Dec 23, 2022
84999ac
Add point precompile test
acolytec3 Dec 24, 2022
abbe843
add data gas targeting in block builder
acolytec3 Dec 26, 2022
aa68c49
Fix txCost logic bug
acolytec3 Dec 29, 2022
81855f8
Remove unactivated EIPs
acolytec3 Dec 30, 2022
363d21d
Fix shanghai json
acolytec3 Jan 2, 2023
635b09f
Switch kzg to interface and peer dependency
acolytec3 Jan 3, 2023
cc54e33
Merge remote-tracking branch 'origin' into eip4844-tx-changes
g11tech Jan 3, 2023
15960bd
fix the add transaction
g11tech Jan 3, 2023
5a12be0
Fix block tests
acolytec3 Jan 3, 2023
b9093b8
remove tape.only
acolytec3 Jan 3, 2023
32b1356
Test and lint fixes
acolytec3 Jan 3, 2023
1ce7ee4
abstract out kzg object for easy access
g11tech Jan 3, 2023
5cb8230
update package-lock
g11tech Jan 3, 2023
a7c24f7
lint
g11tech Jan 4, 2023
aaa1125
fix tx test
g11tech Jan 4, 2023
2256577
fix block spec test
g11tech Jan 4, 2023
27ae5ee
fix the payload generation
g11tech Jan 4, 2023
fd0e8c2
Fix blobBundle test
acolytec3 Jan 4, 2023
c8a994f
Remove hack in getTransactionCount
acolytec3 Jan 4, 2023
3c20c95
Skip blob tests in browser
acolytec3 Jan 4, 2023
0271a61
Add browser check to block tests
acolytec3 Jan 4, 2023
578ae7d
update hash method to use ssz.serialize
acolytec3 Jan 6, 2023
65e921d
Move trusted setup to initKzg
acolytec3 Jan 6, 2023
ccaddf9
Add some basic docs
acolytec3 Jan 6, 2023
6c6b585
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Jan 6, 2023
9ec5b96
update single-run to make peer2/syncpeer wait
g11tech Jan 6, 2023
0cbebed
add multi peer capabilities
g11tech Jan 6, 2023
b610e93
Address various feedback.
acolytec3 Jan 9, 2023
b3d785e
use internal bytesToHex conversion
acolytec3 Jan 10, 2023
12cc1d2
Remove blob tx capability
acolytec3 Jan 10, 2023
423d19a
validateBlobTxns moved to block with tests
acolytec3 Jan 10, 2023
4432589
Address feedback
acolytec3 Jan 11, 2023
f406afc
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Jan 11, 2023
b4d4e11
Lint fixes
acolytec3 Jan 11, 2023
e8883ac
Address feedback
acolytec3 Jan 11, 2023
322f2ec
Remove text-lcov from general script
acolytec3 Jan 11, 2023
396a990
add prysm <> ethjs interop config
acolytec3 Jan 12, 2023
519c185
address feedback
acolytec3 Jan 12, 2023
dec5a4b
Add check for 4844 EIP activation
acolytec3 Jan 12, 2023
71874f9
Add tests for error conditions
acolytec3 Jan 12, 2023
ce9b56f
Add simple runTx test for blob tx
acolytec3 Jan 12, 2023
44d74b8
Address feedback and fix tests
acolytec3 Jan 13, 2023
ae932d7
Fix tests
acolytec3 Jan 13, 2023
68bc062
revise imports
acolytec3 Jan 13, 2023
2b5947d
Fix busted imports
acolytec3 Jan 13, 2023
6edf8a2
Bump test coverage
acolytec3 Jan 13, 2023
04abddb
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Jan 13, 2023
f40416f
Free, free, free the trusted setup
acolytec3 Jan 13, 2023
09b1aec
Address feedback
acolytec3 Jan 16, 2023
200fec6
Revert broken name change
acolytec3 Jan 16, 2023
8f82b23
Add docs and revise api for calcDataFee
acolytec3 Jan 16, 2023
eba7ab0
lint
acolytec3 Jan 16, 2023
68f90bf
bump coverage
acolytec3 Jan 17, 2023
fce7eec
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
g11tech Jan 17, 2023
fd35ac6
Fix datahash opcode and add tests
acolytec3 Jan 17, 2023
963abd9
Move BLS_MODULUS back to precompile
acolytec3 Jan 17, 2023
da37d60
add negative test for datahash opcode
acolytec3 Jan 17, 2023
13e7673
Add precompile test
acolytec3 Jan 17, 2023
1745e20
Add tests for precompile error conditions
acolytec3 Jan 18, 2023
65192bc
Fix test
acolytec3 Jan 18, 2023
1b84113
remove package lock
acolytec3 Jan 18, 2023
1d3104b
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Jan 18, 2023
d53a50d
update package lock
acolytec3 Jan 18, 2023
23f7503
Merge remote-tracking branch 'origin/master' into eip4844-tx-changes
acolytec3 Jan 19, 2023
24ae6bd
Add shanghai EIPs back
acolytec3 Jan 19, 2023
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
2 changes: 1 addition & 1 deletion config/cli/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
set -o xtrace
exec c8 --all --reporter=lcov --reporter=text --reporter=text-lcov npm run test
exec c8 --all --reporter=lcov --reporter=text npm run test
110 changes: 109 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"ethers": "^5.7.1"
},
"devDependencies": {
"@types/lru-cache": "^5.1.0"
"@types/lru-cache": "^5.1.0",
"c-kzg": "^1.0.8"
},
"engines": {
"node": ">=14"
Expand Down
23 changes: 22 additions & 1 deletion packages/block/src/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConsensusType } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { Trie } from '@ethereumjs/trie'
import { Capability, TransactionFactory } from '@ethereumjs/tx'
import { BlobEIP4844Transaction, Capability, TransactionFactory } from '@ethereumjs/tx'
import {
KECCAK256_RLP,
Withdrawal,
Expand All @@ -17,6 +17,7 @@ import { ethers } from 'ethers'

import { blockFromRpc } from './from-rpc'
import { BlockHeader } from './header'
import { getDataGasPrice } from './helpers'

import type { BlockBuffer, BlockData, BlockOptions, JsonBlock, JsonRpcBlock } from './types'
import type { Common } from '@ethereumjs/common'
Expand Down Expand Up @@ -382,6 +383,7 @@ export class Block {
}
}
}

if (errs.length > 0) {
errors.push(`errors at tx ${i}: ${errs.join(', ')}`)
}
Expand Down Expand Up @@ -427,6 +429,25 @@ export class Block {
}
}

/**
* Validates that data gas fee for each transaction
acolytec3 marked this conversation as resolved.
Show resolved Hide resolved
* @param parentHeader header of parent block
*/
validateBlobTransactions(parentHeader: BlockHeader) {
for (const tx of this.transactions) {
if (tx instanceof BlobEIP4844Transaction) {
const dataGasPrice = getDataGasPrice(parentHeader)
if (tx.maxFeePerDataGas < dataGasPrice) {
throw new Error(
`blob transaction maxFeePerDataGas ${
tx.maxFeePerDataGas
} < than block data gas price ${dataGasPrice} - ${this.errorStr()}`
)
}
}
}
}

/**
* Validates the uncle's hash.
*/
Expand Down
17 changes: 16 additions & 1 deletion packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class BlockHeader {
public readonly nonce: Buffer
public readonly baseFeePerGas?: bigint
public readonly withdrawalsRoot?: Buffer
public readonly excessDataGas?: bigint

public readonly _common: Common

Expand Down Expand Up @@ -138,6 +139,7 @@ export class BlockHeader {
}

const skipValidateConsensusFormat = options.skipConsensusFormatValidation ?? false

const defaults = {
parentHash: zeros(32),
uncleHash: KECCAK256_RLP_ARRAY,
Expand Down Expand Up @@ -188,12 +190,15 @@ export class BlockHeader {
: BigInt(7)
: undefined,
withdrawalsRoot: this._common.isActivatedEIP(4895) ? KECCAK256_RLP : undefined,
excessDataGas: this._common.isActivatedEIP(4844) ? BigInt(0) : undefined,
}

const baseFeePerGas =
toType(headerData.baseFeePerGas, TypeOutput.BigInt) ?? hardforkDefaults.baseFeePerGas
const withdrawalsRoot =
toType(headerData.withdrawalsRoot, TypeOutput.Buffer) ?? hardforkDefaults.withdrawalsRoot
const excessDataGas =
toType(headerData.excessDataGas, TypeOutput.BigInt) ?? hardforkDefaults.excessDataGas

if (!this._common.isActivatedEIP(1559) && baseFeePerGas !== undefined) {
throw new Error('A base fee for a block can only be set with EIP1559 being activated')
Expand All @@ -205,6 +210,10 @@ export class BlockHeader {
)
}

if (!this._common.isActivatedEIP(4844) && headerData.excessDataGas !== undefined) {
throw new Error('excess data gas can only be provided with EIP4844 activated')
}

this.parentHash = parentHash
this.uncleHash = uncleHash
this.coinbase = coinbase
Expand All @@ -222,7 +231,7 @@ export class BlockHeader {
this.nonce = nonce
this.baseFeePerGas = baseFeePerGas
this.withdrawalsRoot = withdrawalsRoot

this.excessDataGas = excessDataGas
this._genericFormatValidation()
this._validateDAOExtraData()

Expand Down Expand Up @@ -534,6 +543,9 @@ export class BlockHeader {
if (this._common.isActivatedEIP(4895) === true) {
rawItems.push(this.withdrawalsRoot!)
}
if (this._common.isActivatedEIP(4844) === true) {
rawItems.push(bigIntToUnpaddedBuffer(this.excessDataGas!))
}

return rawItems
}
Expand Down Expand Up @@ -797,6 +809,9 @@ export class BlockHeader {
if (this._common.isActivatedEIP(1559) === true) {
jsonDict.baseFeePerGas = bigIntToHex(this.baseFeePerGas!)
}
if (this._common.isActivatedEIP(4844) === true) {
jsonDict.excessDataGas = bigIntToHex(this.excessDataGas!)
}
return jsonDict
}

Expand Down
Loading