@@ -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+ }
0 commit comments