Skip to content

Commit d207036

Browse files
authored
Merge branch 'ethereum:master' into gethintegration
2 parents bd329c7 + 701df4b commit d207036

File tree

15 files changed

+4237
-27
lines changed

15 files changed

+4237
-27
lines changed

cmd/geth/chaincmd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ func initGenesis(ctx *cli.Context) error {
246246
triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle())
247247
defer triedb.Close()
248248

249-
_, hash, _, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
249+
_, hash, compatErr, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
250250
if err != nil {
251251
utils.Fatalf("Failed to write genesis block: %v", err)
252252
}
253+
if compatErr != nil {
254+
utils.Fatalf("Failed to write chain config: %v", compatErr)
255+
}
253256
log.Info("Successfully wrote genesis state", "database", "chaindata", "hash", hash)
254257

255258
return nil

cmd/utils/flags.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,10 +1854,16 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18541854
if ctx.String(CryptoKZGFlag.Name) != "gokzg" && ctx.String(CryptoKZGFlag.Name) != "ckzg" {
18551855
Fatalf("--%s flag must be 'gokzg' or 'ckzg'", CryptoKZGFlag.Name)
18561856
}
1857-
log.Info("Initializing the KZG library", "backend", ctx.String(CryptoKZGFlag.Name))
1858-
if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil {
1859-
Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err)
1860-
}
1857+
// The initialization of the KZG library can take up to 2 seconds
1858+
// We start this here in parallel, so it should be available
1859+
// once we start executing blocks. It's threadsafe.
1860+
go func() {
1861+
log.Info("Initializing the KZG library", "backend", ctx.String(CryptoKZGFlag.Name))
1862+
if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil {
1863+
Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err)
1864+
}
1865+
}()
1866+
18611867
// VM tracing config.
18621868
if ctx.IsSet(VMTraceFlag.Name) {
18631869
if name := ctx.String(VMTraceFlag.Name); name != "" {

core/blockchain_reader.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
234234
return receipts
235235
}
236236

237+
func (bc *BlockChain) GetRawReceiptsByHash(hash common.Hash) types.Receipts {
238+
number := rawdb.ReadHeaderNumber(bc.db, hash)
239+
if number == nil {
240+
return nil
241+
}
242+
return rawdb.ReadRawReceipts(bc.db, hash, *number)
243+
}
244+
237245
// GetUnclesInChain retrieves all the uncles from a given block backwards until
238246
// a specific distance is reached.
239247
func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header {

core/filtermaps/chain_view.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type blockchain interface {
2929
GetHeader(hash common.Hash, number uint64) *types.Header
3030
GetCanonicalHash(number uint64) common.Hash
3131
GetReceiptsByHash(hash common.Hash) types.Receipts
32+
GetRawReceiptsByHash(hash common.Hash) types.Receipts
3233
}
3334

3435
// ChainView represents an immutable view of a chain with a block id and a set
@@ -102,10 +103,23 @@ func (cv *ChainView) Receipts(number uint64) types.Receipts {
102103
blockHash := cv.BlockHash(number)
103104
if blockHash == (common.Hash{}) {
104105
log.Error("Chain view: block hash unavailable", "number", number, "head", cv.headNumber)
106+
return nil
105107
}
106108
return cv.chain.GetReceiptsByHash(blockHash)
107109
}
108110

111+
// RawReceipts returns the set of receipts belonging to the block at the given
112+
// block number. Does not derive the fields of the receipts, should only be
113+
// used during creation of the filter maps, please use cv.Receipts during querying.
114+
func (cv *ChainView) RawReceipts(number uint64) types.Receipts {
115+
blockHash := cv.BlockHash(number)
116+
if blockHash == (common.Hash{}) {
117+
log.Error("Chain view: block hash unavailable", "number", number, "head", cv.headNumber)
118+
return nil
119+
}
120+
return cv.chain.GetRawReceiptsByHash(blockHash)
121+
}
122+
109123
// SharedRange returns the block range shared by two chain views.
110124
func (cv *ChainView) SharedRange(cv2 *ChainView) common.Range[uint64] {
111125
cv.lock.Lock()

core/filtermaps/indexer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ func (tc *testChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
515515
return tc.receipts[hash]
516516
}
517517

518+
func (tc *testChain) GetRawReceiptsByHash(hash common.Hash) types.Receipts {
519+
tc.lock.RLock()
520+
defer tc.lock.RUnlock()
521+
522+
return tc.receipts[hash]
523+
}
524+
518525
func (tc *testChain) addBlocks(count, maxTxPerBlock, maxLogsPerReceipt, maxTopicsPerLog int, random bool) {
519526
tc.lock.Lock()
520527
blockGen := func(i int, gen *core.BlockGen) {

core/filtermaps/map_renderer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func (f *FilterMaps) newLogIteratorFromMapBoundary(mapIndex uint32, startBlock,
693693
return nil, fmt.Errorf("iterator entry point %d after target chain head block %d", startBlock, f.targetView.HeadNumber())
694694
}
695695
// get block receipts
696-
receipts := f.targetView.Receipts(startBlock)
696+
receipts := f.targetView.RawReceipts(startBlock)
697697
if receipts == nil {
698698
return nil, fmt.Errorf("receipts not found for start block %d", startBlock)
699699
}
@@ -760,7 +760,7 @@ func (l *logIterator) next() error {
760760
if l.delimiter {
761761
l.delimiter = false
762762
l.blockNumber++
763-
l.receipts = l.chainView.Receipts(l.blockNumber)
763+
l.receipts = l.chainView.RawReceipts(l.blockNumber)
764764
if l.receipts == nil {
765765
return fmt.Errorf("receipts not found for block %d", l.blockNumber)
766766
}

crypto/kzg4844/kzg4844.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ func VerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
149149
return gokzgVerifyBlobProof(blob, commitment, proof)
150150
}
151151

152+
// ComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
153+
// the commitment.
154+
//
155+
// This method does not verify that the commitment is correct with respect to blob.
156+
func ComputeCellProofs(blob *Blob) ([]Proof, error) {
157+
if useCKZG.Load() {
158+
return ckzgComputeCellProofs(blob)
159+
}
160+
return gokzgComputeCellProofs(blob)
161+
}
162+
152163
// CalcBlobHashV1 calculates the 'versioned blob hash' of a commitment.
153164
// The given hasher must be a sha256 hash instance, otherwise the result will be invalid!
154165
func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {

crypto/kzg4844/kzg4844_ckzg_cgo.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"errors"
2424
"sync"
2525

26-
gokzg4844 "github.com/crate-crypto/go-kzg-4844"
27-
ckzg4844 "github.com/ethereum/c-kzg-4844/bindings/go"
26+
gokzg4844 "github.com/crate-crypto/go-eth-kzg"
27+
ckzg4844 "github.com/ethereum/c-kzg-4844/v2/bindings/go"
2828
"github.com/ethereum/go-ethereum/common/hexutil"
2929
)
3030

@@ -47,15 +47,21 @@ func ckzgInit() {
4747
if err = gokzg4844.CheckTrustedSetupIsWellFormed(params); err != nil {
4848
panic(err)
4949
}
50-
g1s := make([]byte, len(params.SetupG1Lagrange)*(len(params.SetupG1Lagrange[0])-2)/2)
50+
g1Lag := make([]byte, len(params.SetupG1Lagrange)*(len(params.SetupG1Lagrange[0])-2)/2)
5151
for i, g1 := range params.SetupG1Lagrange {
52+
copy(g1Lag[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
53+
}
54+
g1s := make([]byte, len(params.SetupG1Monomial)*(len(params.SetupG1Monomial[0])-2)/2)
55+
for i, g1 := range params.SetupG1Monomial {
5256
copy(g1s[i*(len(g1)-2)/2:], hexutil.MustDecode(g1))
5357
}
5458
g2s := make([]byte, len(params.SetupG2)*(len(params.SetupG2[0])-2)/2)
5559
for i, g2 := range params.SetupG2 {
5660
copy(g2s[i*(len(g2)-2)/2:], hexutil.MustDecode(g2))
5761
}
58-
if err = ckzg4844.LoadTrustedSetup(g1s, g2s); err != nil {
62+
// The last parameter determines the multiplication table, see https://notes.ethereum.org/@jtraglia/windowed_multiplications
63+
// I think 6 is an decent compromise between size and speed
64+
if err = ckzg4844.LoadTrustedSetup(g1s, g1Lag, g2s, 6); err != nil {
5965
panic(err)
6066
}
6167
}
@@ -125,3 +131,21 @@ func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
125131
}
126132
return nil
127133
}
134+
135+
// ckzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
136+
// the commitment.
137+
//
138+
// This method does not verify that the commitment is correct with respect to blob.
139+
func ckzgComputeCellProofs(blob *Blob) ([]Proof, error) {
140+
ckzgIniter.Do(ckzgInit)
141+
142+
_, proofs, err := ckzg4844.ComputeCellsAndKZGProofs((*ckzg4844.Blob)(blob))
143+
if err != nil {
144+
return []Proof{}, err
145+
}
146+
var p []Proof
147+
for _, proof := range proofs {
148+
p = append(p, (Proof)(proof))
149+
}
150+
return p, nil
151+
}

crypto/kzg4844/kzg4844_ckzg_nocgo.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
6060
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
6161
panic("unsupported platform")
6262
}
63+
64+
// ckzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
65+
// the commitment.
66+
//
67+
// This method does not verify that the commitment is correct with respect to blob.
68+
func ckzgComputeCellProofs(blob *Blob) ([]Proof, error) {
69+
panic("unsupported platform")
70+
}

crypto/kzg4844/kzg4844_gokzg.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"encoding/json"
2121
"sync"
2222

23-
gokzg4844 "github.com/crate-crypto/go-kzg-4844"
23+
gokzg4844 "github.com/crate-crypto/go-eth-kzg"
2424
)
2525

2626
// context is the crypto primitive pre-seeded with the trusted setup parameters.
@@ -96,3 +96,21 @@ func gokzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error
9696

9797
return context.VerifyBlobKZGProof((*gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
9898
}
99+
100+
// gokzgComputeCellProofs returns the KZG cell proofs that are used to verify the blob against
101+
// the commitment.
102+
//
103+
// This method does not verify that the commitment is correct with respect to blob.
104+
func gokzgComputeCellProofs(blob *Blob) ([]Proof, error) {
105+
gokzgIniter.Do(gokzgInit)
106+
107+
_, proofs, err := context.ComputeCellsAndKZGProofs((*gokzg4844.Blob)(blob), 0)
108+
if err != nil {
109+
return []Proof{}, err
110+
}
111+
var p []Proof
112+
for _, proof := range proofs {
113+
p = append(p, (Proof)(proof))
114+
}
115+
return p, nil
116+
}

0 commit comments

Comments
 (0)