Skip to content

Commit

Permalink
EIP-7840: Add blob schedule to EL config files (#13443)
Browse files Browse the repository at this point in the history
See also https://eips.ethereum.org/EIPS/eip-7840

---------

Co-authored-by: Somnath Banerjee <snb895@outlook.com>
  • Loading branch information
yperbasis and somnathb1 authored Jan 24, 2025
1 parent 81e91e5 commit 2700d76
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 92 deletions.
6 changes: 0 additions & 6 deletions core/types/blob_tx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,6 @@ func (txw *BlobTxWrapper) ValidateBlobTransactionWrapper() error {
if l1 != l2 || l1 != l3 || l1 != l4 {
return fmt.Errorf("lengths don't match %v %v %v %v", l1, l2, l3, l4)
}
// the following check isn't strictly necessary as it would be caught by blob gas processing
// (and hence it is not explicitly in the spec for this function), but it doesn't hurt to fail
// early in case we are getting spammed with too many blobs or there is a bug somewhere:
if uint64(l1) > fixedgas.DefaultMaxBlobsPerBlock {
return fmt.Errorf("number of blobs exceeds max: %v", l1)
}
kzgCtx := libkzg.Ctx()
err := kzgCtx.VerifyBlobKZGProofBatch(toBlobs(txw.Blobs), toComms(txw.Commitments), toProofs(txw.Proofs))
if err != nil {
Expand Down
109 changes: 67 additions & 42 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,9 @@ type Config struct {
PragueTime *big.Int `json:"pragueTime,omitempty"`
OsakaTime *big.Int `json:"osakaTime,omitempty"`

// Optional EIP-4844 parameters
MinBlobGasPrice *uint64 `json:"minBlobGasPrice,omitempty"`
MaxBlobGasPerBlock *uint64 `json:"maxBlobGasPerBlock,omitempty"`
TargetBlobGasPerBlock *uint64 `json:"targetBlobGasPerBlock,omitempty"`
BlobGasPriceUpdateFraction *uint64 `json:"blobGasPriceUpdateFraction,omitempty"`

// EIP-7691
MaxBlobGasPerBlockPrague *uint64 `json:"maxBlobGasPerBlockPrague,omitempty"`
TargetBlobGasPerBlockPrague *uint64 `json:"targetBlobGasPerBlockPrague,omitempty"`
BlobGasPriceUpdateFractionPrague *uint64 `json:"blobGasPriceUpdateFractionPrague,omitempty"`
// Optional EIP-4844 parameters (see also EIP-7691 & EIP-7840)
MinBlobGasPrice *uint64 `json:"minBlobGasPrice,omitempty"`
BlobSchedule *BlobSchedule `json:"blobSchedule,omitempty"`

// (Optional) governance contract where EIP-1559 fees will be sent to, which otherwise would be burnt since the London fork.
// A key corresponds to the block number, starting from which the fees are sent to the address (map value).
Expand All @@ -100,6 +93,57 @@ type Config struct {
BorJSON json.RawMessage `json:"bor,omitempty"`
}

type BlobConfig struct {
Target uint64 `json:"target"`
Max uint64 `json:"max"`
BaseFeeUpdateFraction uint64 `json:"baseFeeUpdateFraction"`
}

// See EIP-7840: Add blob schedule to EL config files
type BlobSchedule struct {
Cancun *BlobConfig `json:"cancun,omitempty"`
Prague *BlobConfig `json:"prague,omitempty"`
}

func (b *BlobSchedule) TargetBlobsPerBlock(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil {
return b.Prague.Target
}
return 6 // EIP-7691
}
if b != nil && b.Cancun != nil {
return b.Cancun.Target
}
return 3 // EIP-4844
}

func (b *BlobSchedule) MaxBlobsPerBlock(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil {
return b.Prague.Max
}
return 9 // EIP-7691
}
if b != nil && b.Cancun != nil {
return b.Cancun.Max
}
return 6 // EIP-4844
}

func (b *BlobSchedule) BaseFeeUpdateFraction(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil {
return b.Prague.BaseFeeUpdateFraction
}
return 5007716 // EIP-7691
}
if b != nil && b.Cancun != nil {
return b.Cancun.BaseFeeUpdateFraction
}
return 3338477 // EIP-4844
}

type BorConfig interface {
fmt.Stringer
IsAgra(num uint64) bool
Expand Down Expand Up @@ -276,50 +320,31 @@ func (c *Config) GetMinBlobGasPrice() uint64 {
}

func (c *Config) GetMaxBlobGasPerBlock(t uint64) uint64 {
return c.GetMaxBlobsPerBlock(t) * fixedgas.BlobGasPerBlob
}

func (c *Config) GetMaxBlobsPerBlock(time uint64) uint64 {
var b *BlobSchedule
if c != nil {
if c.IsPrague(t) {
if c.MaxBlobGasPerBlockPrague != nil {
return *c.MaxBlobGasPerBlockPrague
}
return 1179648 // EIP-7691
} else if c.MaxBlobGasPerBlock != nil {
return *c.MaxBlobGasPerBlock
}
b = c.BlobSchedule
}
return 786432 // MAX_BLOB_GAS_PER_BLOCK (EIP-4844)
return b.MaxBlobsPerBlock(c.IsPrague(time))
}

func (c *Config) GetTargetBlobGasPerBlock(t uint64) uint64 {
var b *BlobSchedule
if c != nil {
if c.IsPrague(t) {
if c.TargetBlobGasPerBlockPrague != nil {
return *c.TargetBlobGasPerBlockPrague
}
return 786432
} else if c.TargetBlobGasPerBlock != nil {
return *c.TargetBlobGasPerBlock
}
b = c.BlobSchedule
}
return 393216 // TARGET_BLOB_GAS_PER_BLOCK (EIP-4844)
return b.TargetBlobsPerBlock(c.IsPrague(t)) * fixedgas.BlobGasPerBlob
}

func (c *Config) GetBlobGasPriceUpdateFraction(t uint64) uint64 {
var b *BlobSchedule
if c != nil {
if c.IsPrague(t) {
if c.BlobGasPriceUpdateFractionPrague != nil {
return *c.BlobGasPriceUpdateFractionPrague
}
return 5007716

} else if c.BlobGasPriceUpdateFraction != nil {
return *c.BlobGasPriceUpdateFraction
}
b = c.BlobSchedule
}
return 3338477 // BLOB_GASPRICE_UPDATE_FRACTION (EIP-4844)
}

func (c *Config) GetMaxBlobsPerBlock(time uint64) uint64 {
return c.GetMaxBlobGasPerBlock(time) / fixedgas.BlobGasPerBlob
return b.BaseFeeUpdateFraction(c.IsPrague(t))
}

func (c *Config) SecondsPerSlot() uint64 {
Expand Down
16 changes: 16 additions & 0 deletions erigon-lib/chain/chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@ func TestConfigValueLookup(t *testing.T) {
assert.Equal(t, ConfigValueLookup(burntContract, 41874000), address2)
assert.Equal(t, ConfigValueLookup(burntContract, 41874000+1), address2)
}

func TestNilBlobSchedule(t *testing.T) {
var b *BlobSchedule

// Original EIP-4844 values
isPrague := false
assert.Equal(t, uint64(3), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(6), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(3338477), b.BaseFeeUpdateFraction(isPrague))

// EIP-7691: Blob throughput increase
isPrague = true
assert.Equal(t, uint64(6), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(9), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(5007716), b.BaseFeeUpdateFraction(isPrague))
}
7 changes: 3 additions & 4 deletions erigon-lib/common/fixedgas/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ const (
InitCodeWordGas = 2

// EIP-4844: Shard Blob Transactions
FieldElementsPerBlob = 4096 // each field element is 32 bytes
BlobSize = FieldElementsPerBlob * 32
BlobGasPerBlob uint64 = 0x20000
DefaultMaxBlobsPerBlock uint64 = 6 // lower for Gnosis
FieldElementsPerBlob = 4096 // each field element is 32 bytes
BlobSize = FieldElementsPerBlob * 32
BlobGasPerBlob uint64 = 0x20000

// EIP-7702: set code tx
PerEmptyAccountCost = 25000
Expand Down
15 changes: 12 additions & 3 deletions params/chainspecs/chiado.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
"shanghaiTime": 1684934220,
"cancunTime": 1706724940,
"minBlobGasPrice": 1000000000,
"maxBlobGasPerBlock": 262144,
"targetBlobGasPerBlock": 131072,
"blobGasPriceUpdateFraction": 1112826,
"blobSchedule": {
"cancun": {
"target": 1,
"max": 2,
"baseFeeUpdateFraction": 1112826
},
"prague": {
"target": 1,
"max": 2,
"baseFeeUpdateFraction": 1112826
}
},
"burntContract": {
"0": "0x1559000000000000000000000000000000000000"
},
Expand Down
15 changes: 12 additions & 3 deletions params/chainspecs/gnosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
"shanghaiTime": 1690889660,
"cancunTime": 1710181820,
"minBlobGasPrice": 1000000000,
"maxBlobGasPerBlock": 262144,
"targetBlobGasPerBlock": 131072,
"blobGasPriceUpdateFraction": 1112826,
"blobSchedule": {
"cancun": {
"target": 1,
"max": 2,
"baseFeeUpdateFraction": 1112826
},
"prague": {
"target": 1,
"max": 2,
"baseFeeUpdateFraction": 1112826
}
},
"burntContract": {
"19040000": "0x6BBe78ee9e474842Dbd4AB4987b3CeFE88426A92"
},
Expand Down
12 changes: 12 additions & 0 deletions params/chainspecs/holesky.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@
"terminalTotalDifficultyPassed": true,
"shanghaiTime": 1696000704,
"cancunTime": 1707305664,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"depositContractAddress": "0x4242424242424242424242424242424242424242"
}
12 changes: 12 additions & 0 deletions params/chainspecs/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
"terminalTotalDifficultyPassed": true,
"shanghaiTime": 1681338455,
"cancunTime": 1710338135,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"depositContractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa",
"ethash": {}
}
12 changes: 12 additions & 0 deletions params/chainspecs/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
"mergeNetsplitBlock": 1735371,
"shanghaiTime": 1677557088,
"cancunTime": 1706655072,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"depositContractAddress": "0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D",
"ethash": {}
}
36 changes: 36 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,39 @@ func TestGetBurntContract(t *testing.T) {
require.NotNil(t, addr)
assert.Equal(t, common.HexToAddress("0x000000000000000000000000000000000000dead"), *addr)
}

func TestMainnetBlobSchedule(t *testing.T) {
// Original EIP-4844 values
assert.Equal(t, uint64(6), MainnetChainConfig.GetMaxBlobsPerBlock(0))
assert.Equal(t, uint64(786432), MainnetChainConfig.GetMaxBlobGasPerBlock(0))
assert.Equal(t, uint64(393216), MainnetChainConfig.GetTargetBlobGasPerBlock(0))
assert.Equal(t, uint64(3338477), MainnetChainConfig.GetBlobGasPriceUpdateFraction(0))

b := MainnetChainConfig.BlobSchedule
isPrague := false
assert.Equal(t, uint64(3), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(6), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(3338477), b.BaseFeeUpdateFraction(isPrague))

// EIP-7691: Blob throughput increase
isPrague = true
assert.Equal(t, uint64(6), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(9), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(5007716), b.BaseFeeUpdateFraction(isPrague))
}

func TestGnosisBlobSchedule(t *testing.T) {
b := GnosisChainConfig.BlobSchedule

// Cancun values
isPrague := false
assert.Equal(t, uint64(1), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(2), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(1112826), b.BaseFeeUpdateFraction(isPrague))

// should remain the same in Pectra for Gnosis
isPrague = true
assert.Equal(t, uint64(1), b.TargetBlobsPerBlock(isPrague))
assert.Equal(t, uint64(2), b.MaxBlobsPerBlock(isPrague))
assert.Equal(t, uint64(1112826), b.BaseFeeUpdateFraction(isPrague))
}
6 changes: 1 addition & 5 deletions txnprovider/txpool/assemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package txpool
import (
"context"
"math/big"
"time"

"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -56,7 +55,6 @@ func Assemble(
}

chainID, _ := uint256.FromBig(chainConfig.ChainID)
maxBlobsPerBlock := chainConfig.GetMaxBlobsPerBlock(uint64(time.Now().Second()))

shanghaiTime := chainConfig.ShanghaiTime
var agraBlock *big.Int
Expand All @@ -68,7 +66,6 @@ func Assemble(
if cfg.OverridePragueTime != nil {
pragueTime = cfg.OverridePragueTime
}
maxBlobsPerBlockPrague := chainConfig.MaxBlobGasPerBlockPrague

newTxns := make(chan Announcements, 1024)
newSlotsStreams := &NewSlotsStreams{}
Expand All @@ -84,8 +81,7 @@ func Assemble(
agraBlock,
cancunTime,
pragueTime,
maxBlobsPerBlock,
maxBlobsPerBlockPrague,
chainConfig.BlobSchedule,
sentryClients,
stateChangesClient,
builderNotifyNewTxns,
Expand Down
Loading

0 comments on commit 2700d76

Please sign in to comment.