Skip to content

Commit 5962bff

Browse files
committed
crypto/kzg4844: update to latest ethereum/go-ethereum#29050
1 parent 964a6c4 commit 5962bff

File tree

11 files changed

+45
-45
lines changed

11 files changed

+45
-45
lines changed

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ func makeSidecar(data ...byte) *types.BlobTxSidecar {
754754
)
755755
for i := range blobs {
756756
blobs[i][0] = data[i]
757-
c, _ := kzg4844.BlobToCommitment(blobs[i])
758-
p, _ := kzg4844.ComputeBlobProof(blobs[i], c)
757+
c, _ := kzg4844.BlobToCommitment(&blobs[i])
758+
p, _ := kzg4844.ComputeBlobProof(&blobs[i], c)
759759
commitments = append(commitments, c)
760760
proofs = append(proofs, p)
761761
}

core/txpool/blobpool/blobpool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
)
4949

5050
var (
51-
emptyBlob = kzg4844.Blob{}
51+
emptyBlob = new(kzg4844.Blob)
5252
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
5353
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
5454
emptyBlobVHash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
@@ -198,7 +198,7 @@ func makeUnsignedTx(nonce uint64, gasTipCap uint64, gasFeeCap uint64, blobFeeCap
198198
BlobHashes: []common.Hash{emptyBlobVHash},
199199
Value: uint256.NewInt(100),
200200
Sidecar: &types.BlobTxSidecar{
201-
Blobs: []kzg4844.Blob{emptyBlob},
201+
Blobs: []kzg4844.Blob{*emptyBlob},
202202
Commitments: []kzg4844.Commitment{emptyBlobCommit},
203203
Proofs: []kzg4844.Proof{emptyBlobProof},
204204
},

core/txpool/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) err
163163
// Blob commitments match with the hashes in the transaction, verify the
164164
// blobs themselves via KZG
165165
for i := range sidecar.Blobs {
166-
if err := kzg4844.VerifyBlobProof(sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
166+
if err := kzg4844.VerifyBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
167167
return fmt.Errorf("invalid blob %d: %v", i, err)
168168
}
169169
}

core/types/tx_blob_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestBlobTxSize(t *testing.T) {
5959
}
6060

6161
var (
62-
emptyBlob = kzg4844.Blob{}
62+
emptyBlob = new(kzg4844.Blob)
6363
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
6464
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
6565
)
@@ -72,7 +72,7 @@ func createEmptyBlobTx(key *ecdsa.PrivateKey, withSidecar bool) *Transaction {
7272

7373
func createEmptyBlobTxInner(withSidecar bool) *BlobTx {
7474
sidecar := &BlobTxSidecar{
75-
Blobs: []kzg4844.Blob{emptyBlob},
75+
Blobs: []kzg4844.Blob{*emptyBlob},
7676
Commitments: []kzg4844.Commitment{emptyBlobCommit},
7777
Proofs: []kzg4844.Proof{emptyBlobProof},
7878
}

crypto/kzg4844/kzg4844.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Claim [32]byte
8585
var useCKZG atomic.Bool
8686

8787
// UseCKZG can be called to switch the default Go implementation of KZG to the C
88-
// library if fo some reason the user wishes to do so (e.g. consensus bug in one
88+
// library if for some reason the user wishes to do so (e.g. consensus bug in one
8989
// or the other).
9090
func UseCKZG(use bool) error {
9191
if use && !ckzgAvailable {
@@ -105,7 +105,7 @@ func UseCKZG(use bool) error {
105105
}
106106

107107
// BlobToCommitment creates a small commitment out of a data blob.
108-
func BlobToCommitment(blob Blob) (Commitment, error) {
108+
func BlobToCommitment(blob *Blob) (Commitment, error) {
109109
if useCKZG.Load() {
110110
return ckzgBlobToCommitment(blob)
111111
}
@@ -114,7 +114,7 @@ func BlobToCommitment(blob Blob) (Commitment, error) {
114114

115115
// ComputeProof computes the KZG proof at the given point for the polynomial
116116
// represented by the blob.
117-
func ComputeProof(blob Blob, point Point) (Proof, Claim, error) {
117+
func ComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
118118
if useCKZG.Load() {
119119
return ckzgComputeProof(blob, point)
120120
}
@@ -134,15 +134,15 @@ func VerifyProof(commitment Commitment, point Point, claim Claim, proof Proof) e
134134
// the commitment.
135135
//
136136
// This method does not verify that the commitment is correct with respect to blob.
137-
func ComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
137+
func ComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
138138
if useCKZG.Load() {
139139
return ckzgComputeBlobProof(blob, commitment)
140140
}
141141
return gokzgComputeBlobProof(blob, commitment)
142142
}
143143

144144
// VerifyBlobProof verifies that the blob data corresponds to the provided commitment.
145-
func VerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
145+
func VerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
146146
if useCKZG.Load() {
147147
return ckzgVerifyBlobProof(blob, commitment, proof)
148148
}

crypto/kzg4844/kzg4844_ckzg_cgo.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ func ckzgInit() {
6161
}
6262

6363
// ckzgBlobToCommitment creates a small commitment out of a data blob.
64-
func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
64+
func ckzgBlobToCommitment(blob *Blob) (Commitment, error) {
6565
ckzgIniter.Do(ckzgInit)
6666

67-
commitment, err := ckzg4844.BlobToKZGCommitment((ckzg4844.Blob)(blob))
67+
commitment, err := ckzg4844.BlobToKZGCommitment((*ckzg4844.Blob)(blob))
6868
if err != nil {
6969
return Commitment{}, err
7070
}
@@ -73,10 +73,10 @@ func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
7373

7474
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
7575
// represented by the blob.
76-
func ckzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
76+
func ckzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
7777
ckzgIniter.Do(ckzgInit)
7878

79-
proof, claim, err := ckzg4844.ComputeKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes32)(point))
79+
proof, claim, err := ckzg4844.ComputeKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes32)(point))
8080
if err != nil {
8181
return Proof{}, Claim{}, err
8282
}
@@ -102,21 +102,21 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
102102
// the commitment.
103103
//
104104
// This method does not verify that the commitment is correct with respect to blob.
105-
func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
105+
func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
106106
ckzgIniter.Do(ckzgInit)
107107

108-
proof, err := ckzg4844.ComputeBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
108+
proof, err := ckzg4844.ComputeBlobKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
109109
if err != nil {
110110
return Proof{}, err
111111
}
112112
return (Proof)(proof), nil
113113
}
114114

115115
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
116-
func ckzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
116+
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
117117
ckzgIniter.Do(ckzgInit)
118118

119-
valid, err := ckzg4844.VerifyBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes48)(proof))
119+
valid, err := ckzg4844.VerifyBlobKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes48)(proof))
120120
if err != nil {
121121
return err
122122
}

crypto/kzg4844/kzg4844_ckzg_nocgo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func ckzgInit() {
3232
}
3333

3434
// ckzgBlobToCommitment creates a small commitment out of a data blob.
35-
func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
35+
func ckzgBlobToCommitment(blob *Blob) (Commitment, error) {
3636
panic("unsupported platform")
3737
}
3838

3939
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
4040
// represented by the blob.
41-
func ckzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
41+
func ckzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
4242
panic("unsupported platform")
4343
}
4444

@@ -52,11 +52,11 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
5252
// the commitment.
5353
//
5454
// This method does not verify that the commitment is correct with respect to blob.
55-
func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
55+
func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
5656
panic("unsupported platform")
5757
}
5858

5959
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
60-
func ckzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
60+
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
6161
panic("unsupported platform")
6262
}

crypto/kzg4844/kzg4844_gokzg.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func gokzgInit() {
4646
}
4747

4848
// gokzgBlobToCommitment creates a small commitment out of a data blob.
49-
func gokzgBlobToCommitment(blob Blob) (Commitment, error) {
49+
func gokzgBlobToCommitment(blob *Blob) (Commitment, error) {
5050
gokzgIniter.Do(gokzgInit)
5151

52-
commitment, err := context.BlobToKZGCommitment((gokzg4844.Blob)(blob), 0)
52+
commitment, err := context.BlobToKZGCommitment((*gokzg4844.Blob)(blob), 0)
5353
if err != nil {
5454
return Commitment{}, err
5555
}
@@ -58,10 +58,10 @@ func gokzgBlobToCommitment(blob Blob) (Commitment, error) {
5858

5959
// gokzgComputeProof computes the KZG proof at the given point for the polynomial
6060
// represented by the blob.
61-
func gokzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
61+
func gokzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
6262
gokzgIniter.Do(gokzgInit)
6363

64-
proof, claim, err := context.ComputeKZGProof((gokzg4844.Blob)(blob), (gokzg4844.Scalar)(point), 0)
64+
proof, claim, err := context.ComputeKZGProof((*gokzg4844.Blob)(blob), (gokzg4844.Scalar)(point), 0)
6565
if err != nil {
6666
return Proof{}, Claim{}, err
6767
}
@@ -80,19 +80,19 @@ func gokzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Pro
8080
// the commitment.
8181
//
8282
// This method does not verify that the commitment is correct with respect to blob.
83-
func gokzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
83+
func gokzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
8484
gokzgIniter.Do(gokzgInit)
8585

86-
proof, err := context.ComputeBlobKZGProof((gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), 0)
86+
proof, err := context.ComputeBlobKZGProof((*gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), 0)
8787
if err != nil {
8888
return Proof{}, err
8989
}
9090
return (Proof)(proof), nil
9191
}
9292

9393
// gokzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
94-
func gokzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
94+
func gokzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
9595
gokzgIniter.Do(gokzgInit)
9696

97-
return context.VerifyBlobKZGProof((gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
97+
return context.VerifyBlobKZGProof((*gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
9898
}

crypto/kzg4844/kzg4844_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func randFieldElement() [32]byte {
3636
return gokzg4844.SerializeScalar(r)
3737
}
3838

39-
func randBlob() Blob {
39+
func randBlob() *Blob {
4040
var blob Blob
4141
for i := 0; i < len(blob); i += gokzg4844.SerializedScalarSize {
4242
fieldElementBytes := randFieldElement()
4343
copy(blob[i:i+gokzg4844.SerializedScalarSize], fieldElementBytes[:])
4444
}
45-
return blob
45+
return &blob
4646
}
4747

4848
func TestCKZGWithPoint(t *testing.T) { testKZGWithPoint(t, true) }

internal/ethapi/api_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ func TestFillBlobTransaction(t *testing.T) {
10911091
Config: params.MergedTestChainConfig,
10921092
Alloc: types.GenesisAlloc{},
10931093
}
1094-
emptyBlob = kzg4844.Blob{}
1094+
emptyBlob = new(kzg4844.Blob)
10951095
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
10961096
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
10971097
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
@@ -1174,14 +1174,14 @@ func TestFillBlobTransaction(t *testing.T) {
11741174
From: &b.acc.Address,
11751175
To: &to,
11761176
Value: (*hexutil.Big)(big.NewInt(1)),
1177-
Blobs: []kzg4844.Blob{emptyBlob},
1177+
Blobs: []kzg4844.Blob{*emptyBlob},
11781178
Commitments: []kzg4844.Commitment{emptyBlobCommit},
11791179
Proofs: []kzg4844.Proof{emptyBlobProof},
11801180
},
11811181
want: &result{
11821182
Hashes: []common.Hash{emptyBlobHash},
11831183
Sidecar: &types.BlobTxSidecar{
1184-
Blobs: []kzg4844.Blob{emptyBlob},
1184+
Blobs: []kzg4844.Blob{*emptyBlob},
11851185
Commitments: []kzg4844.Commitment{emptyBlobCommit},
11861186
Proofs: []kzg4844.Proof{emptyBlobProof},
11871187
},
@@ -1194,14 +1194,14 @@ func TestFillBlobTransaction(t *testing.T) {
11941194
To: &to,
11951195
Value: (*hexutil.Big)(big.NewInt(1)),
11961196
BlobHashes: []common.Hash{emptyBlobHash},
1197-
Blobs: []kzg4844.Blob{emptyBlob},
1197+
Blobs: []kzg4844.Blob{*emptyBlob},
11981198
Commitments: []kzg4844.Commitment{emptyBlobCommit},
11991199
Proofs: []kzg4844.Proof{emptyBlobProof},
12001200
},
12011201
want: &result{
12021202
Hashes: []common.Hash{emptyBlobHash},
12031203
Sidecar: &types.BlobTxSidecar{
1204-
Blobs: []kzg4844.Blob{emptyBlob},
1204+
Blobs: []kzg4844.Blob{*emptyBlob},
12051205
Commitments: []kzg4844.Commitment{emptyBlobCommit},
12061206
Proofs: []kzg4844.Proof{emptyBlobProof},
12071207
},
@@ -1214,7 +1214,7 @@ func TestFillBlobTransaction(t *testing.T) {
12141214
To: &to,
12151215
Value: (*hexutil.Big)(big.NewInt(1)),
12161216
BlobHashes: []common.Hash{{0x01, 0x22}},
1217-
Blobs: []kzg4844.Blob{emptyBlob},
1217+
Blobs: []kzg4844.Blob{*emptyBlob},
12181218
Commitments: []kzg4844.Commitment{emptyBlobCommit},
12191219
Proofs: []kzg4844.Proof{emptyBlobProof},
12201220
},
@@ -1226,12 +1226,12 @@ func TestFillBlobTransaction(t *testing.T) {
12261226
From: &b.acc.Address,
12271227
To: &to,
12281228
Value: (*hexutil.Big)(big.NewInt(1)),
1229-
Blobs: []kzg4844.Blob{emptyBlob},
1229+
Blobs: []kzg4844.Blob{*emptyBlob},
12301230
},
12311231
want: &result{
12321232
Hashes: []common.Hash{emptyBlobHash},
12331233
Sidecar: &types.BlobTxSidecar{
1234-
Blobs: []kzg4844.Blob{emptyBlob},
1234+
Blobs: []kzg4844.Blob{*emptyBlob},
12351235
Commitments: []kzg4844.Commitment{emptyBlobCommit},
12361236
Proofs: []kzg4844.Proof{emptyBlobProof},
12371237
},

0 commit comments

Comments
 (0)