Skip to content

Commit 2b6fc33

Browse files
author
jagdeep sidhu
committed
Update data_blob.go
1 parent a09bf1d commit 2b6fc33

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

core/types/data_blob.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
package types
22

33
import (
4-
"bytes"
54
"encoding/hex"
65
"errors"
76
"fmt"
7+
"bytes"
88

99
"github.com/ethereum/go-ethereum/common"
1010
"github.com/ethereum/go-ethereum/common/hexutil"
1111
"github.com/ethereum/go-ethereum/crypto"
1212
"github.com/ethereum/go-ethereum/crypto/kzg"
13-
"github.com/ethereum/go-ethereum/log"
1413
"github.com/ethereum/go-ethereum/params"
1514
"github.com/protolambda/go-kzg/bls"
1615
"github.com/syscoin/btcd/wire"
16+
"github.com/ethereum/go-ethereum/log"
1717
)
1818

19+
1920
// Compressed BLS12-381 G1 element
2021
type KZGCommitment [48]byte
2122

2223
type NEVMBlob struct {
2324
VersionHash common.Hash
24-
Commitment *bls.G1Point
25-
Blob []bls.Fr
25+
Commitment *bls.G1Point
26+
Blob []bls.Fr
2627
}
2728
type NEVMBlobs struct {
2829
Blobs []*NEVMBlob
2930
}
30-
3131
// Verify that the list of `commitments` maps to the list of `blobs`
3232
//
3333
// This is an optimization over the naive approach (found in the EIP) of iteratively checking each blob against each
@@ -123,13 +123,13 @@ func (n *NEVMBlob) FromWire(NEVMBlobWire *wire.NEVMBlob) error {
123123
return errors.New("Blob should be a factor of 32")
124124
}
125125
n.Blob = make([]bls.Fr, params.FieldElementsPerBlob)
126-
numElements := lenBlob / 32
126+
numElements := lenBlob/32
127127
var inputPoint [32]byte
128128
for i := 0; i < numElements; i++ {
129129
copy(inputPoint[:32], NEVMBlobWire.Blob[i*32:(i+1)*32])
130130
ok := bls.FrFrom32(&n.Blob[i], inputPoint)
131131
if !ok {
132-
return errors.New("invalid chunk")
132+
return fmt.Errorf("FromWire: invalid chunk (element %d inputPoint %v)", i, inputPoint)
133133
}
134134
}
135135
return nil
@@ -149,19 +149,19 @@ func (n *NEVMBlob) FromBytes(blob []byte) error {
149149
return errors.New("Blob should be a factor of 32")
150150
}
151151
n.Blob = make([]bls.Fr, params.FieldElementsPerBlob)
152-
numElements := lenBlob / 32
152+
numElements := lenBlob/32
153153
var inputPoint [32]byte
154154
for i := 0; i < numElements; i++ {
155155
copy(inputPoint[:32], blob[i*32:(i+1)*32])
156156
ok := bls.FrFrom32(&n.Blob[i], inputPoint)
157-
if !ok {
158-
return errors.New("invalid chunk")
157+
if ok != true {
158+
return fmt.Errorf("FromBytes: invalid chunk (element %d inputPoint %v)", i, inputPoint)
159159
}
160160
}
161161

162162
// Get versioned hash out of input points
163163
n.Commitment = kzg.BlobToKzg(n.Blob)
164-
// need the full field elements array above to properly calculate and validate blob to kzg,
164+
// need the full field elements array above to properly calculate and validate blob to kzg,
165165
// can splice it after for network purposes and later when deserializing will again create full elements array to input spliced data from network
166166
n.Blob = n.Blob[0:numElements]
167167
var compressedCommitment KZGCommitment
@@ -188,8 +188,8 @@ func (n *NEVMBlob) Serialize() ([]byte, error) {
188188
var err error
189189
NEVMBlobWire.VersionHash = n.VersionHash.Bytes()
190190
var tmpCommit KZGCommitment
191-
lenBlobData := len(n.Blob) * 32
192-
NEVMBlobWire.Blob = make([]byte, 0, lenBlobData+int(tmpCommit.FixedLength()))
191+
lenBlobData := len(n.Blob)*32
192+
NEVMBlobWire.Blob = make([]byte, 0, lenBlobData + int(tmpCommit.FixedLength()) )
193193
NEVMBlobWire.Blob = append(NEVMBlobWire.Blob, bls.ToCompressedG1(n.Commitment)...)
194194
for _, fr := range n.Blob {
195195
bBytes := bls.FrTo32(&fr)
@@ -231,6 +231,7 @@ func (KZGCommitment) FixedLength() uint64 {
231231
return 48
232232
}
233233

234+
234235
func (p KZGCommitment) MarshalText() ([]byte, error) {
235236
return []byte("0x" + hex.EncodeToString(p[:])), nil
236237
}
@@ -270,6 +271,7 @@ func (p *BLSFieldElement) UnmarshalText(text []byte) error {
270271
// Blob data
271272
type Blob [params.FieldElementsPerBlob]BLSFieldElement
272273

274+
273275
func (blob *Blob) ByteLength() (out uint64) {
274276
return params.FieldElementsPerBlob * 32
275277
}
@@ -359,6 +361,7 @@ func (li BlobKzgs) Parse() ([]*bls.G1Point, error) {
359361
return out, nil
360362
}
361363

364+
362365
func (li BlobKzgs) ByteLength() uint64 {
363366
return uint64(len(li)) * 48
364367
}
@@ -414,4 +417,4 @@ func (blobs Blobs) ComputeCommitments() (commitments []KZGCommitment, versionedH
414417
versionedHashes[i] = commitments[i].ComputeVersionedHash()
415418
}
416419
return commitments, versionedHashes, true
417-
}
420+
}

0 commit comments

Comments
 (0)