77 "io"
88
99 "github.com/crate-crypto/go-proto-danksharding-crypto/eth"
10- api "github.com/crate-crypto/go-proto-danksharding-crypto/serialisation "
10+ api "github.com/crate-crypto/go-proto-danksharding-crypto/serialization "
1111 "github.com/ethereum/go-ethereum/common"
1212 "github.com/ethereum/go-ethereum/common/hexutil"
1313 "github.com/ethereum/go-ethereum/params"
@@ -199,6 +199,36 @@ func (li BlobKzgs) copy() BlobKzgs {
199199 return cpy
200200}
201201
202+ type KZGProofs []KZGProof
203+
204+ func (li * KZGProofs ) Deserialize (dr * codec.DecodingReader ) error {
205+ return dr .List (func () codec.Deserializable {
206+ i := len (* li )
207+ * li = append (* li , KZGProof {})
208+ return & (* li )[i ]
209+ }, 48 , params .MaxBlobsPerBlock )
210+ }
211+
212+ func (li KZGProofs ) Serialize (w * codec.EncodingWriter ) error {
213+ return w .List (func (i uint64 ) codec.Serializable {
214+ return & li [i ]
215+ }, 48 , uint64 (len (li )))
216+ }
217+
218+ func (li KZGProofs ) ByteLength () uint64 {
219+ return uint64 (len (li )) * 48
220+ }
221+
222+ func (li KZGProofs ) FixedLength () uint64 {
223+ return 0
224+ }
225+
226+ func (li KZGProofs ) copy () KZGProofs {
227+ cpy := make (KZGProofs , len (li ))
228+ copy (cpy , li )
229+ return cpy
230+ }
231+
202232type Blobs []Blob
203233
204234func (a * Blobs ) Deserialize (dr * codec.DecodingReader ) error {
@@ -229,28 +259,28 @@ func (blobs Blobs) copy() Blobs {
229259 return cpy
230260}
231261
232- // Return KZG commitments, versioned hashes and the aggregated KZG proof that correspond to these blobs
233- func (blobs Blobs ) ComputeCommitmentsAndAggregatedProof () (commitments []KZGCommitment , versionedHashes []common.Hash , aggregatedProof KZGProof , err error ) {
262+ // Return KZG commitments, versioned hashes and the proofs that correspond to these blobs
263+ func (blobs Blobs ) ComputeCommitmentsAndProofs () (commitments []KZGCommitment , versionedHashes []common.Hash , proofs [] KZGProof , err error ) {
234264 commitments = make ([]KZGCommitment , len (blobs ))
265+ proofs = make ([]KZGProof , len (blobs ))
235266 versionedHashes = make ([]common.Hash , len (blobs ))
236267
237268 for i , blob := range blobs {
238- commitment , err := eth .CryptoCtx .BlobToCommitment (blob )
269+ commitment , err := eth .CryptoCtx .BlobToKZGCommitment (blob )
239270 if err != nil {
271+ return nil , nil , nil , fmt .Errorf ("could not convert blob to commitment: %v" , err )
272+ }
240273
241- return nil , nil , KZGProof {}, fmt .Errorf ("could not convert blob to commitment: %v" , err )
274+ proof , err := eth .CryptoCtx .ComputeBlobKZGProof (blob , commitment )
275+ if err != nil {
276+ return nil , nil , nil , fmt .Errorf ("could not compute proof for blob: %v" , err )
242277 }
243278 commitments [i ] = KZGCommitment (commitment )
279+ proofs [i ] = KZGProof (proof )
244280 versionedHashes [i ] = common .Hash (eth .KZGToVersionedHash (commitment ))
245281 }
246282
247- proof , _ , err := eth .CryptoCtx .ComputeAggregateKZGProof (toBlobs (blobs ))
248- if err != nil {
249- return nil , nil , KZGProof {}, err
250- }
251- var kzgProof = KZGProof (proof )
252-
253- return commitments , versionedHashes , kzgProof , nil
283+ return commitments , versionedHashes , proofs , nil
254284}
255285
256286func toBlobs (_blobs Blobs ) []api.Blob {
@@ -267,39 +297,46 @@ func toComms(_comms BlobKzgs) []api.KZGCommitment {
267297 }
268298 return comms
269299}
300+ func toProofs (_proofs KZGProofs ) []api.KZGProof {
301+ proofs := make ([]api.KZGProof , len (_proofs ))
302+ for i , _proof := range _proofs {
303+ proofs [i ] = api .KZGProof (_proof )
304+ }
305+ return proofs
306+ }
270307
271308type BlobTxWrapper struct {
272- Tx SignedBlobTx
273- BlobKzgs BlobKzgs
274- Blobs Blobs
275- KzgAggregatedProof KZGProof
309+ Tx SignedBlobTx
310+ BlobKzgs BlobKzgs
311+ Blobs Blobs
312+ Proofs KZGProofs
276313}
277314
278315func (txw * BlobTxWrapper ) Deserialize (dr * codec.DecodingReader ) error {
279- return dr .Container (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .KzgAggregatedProof )
316+ return dr .Container (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .Proofs )
280317}
281318
282319func (txw * BlobTxWrapper ) Serialize (w * codec.EncodingWriter ) error {
283- return w .Container (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .KzgAggregatedProof )
320+ return w .Container (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .Proofs )
284321}
285322
286323func (txw * BlobTxWrapper ) ByteLength () uint64 {
287- return codec .ContainerLength (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .KzgAggregatedProof )
324+ return codec .ContainerLength (& txw .Tx , & txw .BlobKzgs , & txw .Blobs , & txw .Proofs )
288325}
289326
290327func (txw * BlobTxWrapper ) FixedLength () uint64 {
291328 return 0
292329}
293330
294331type BlobTxWrapData struct {
295- BlobKzgs BlobKzgs
296- Blobs Blobs
297- KzgAggregatedProof KZGProof
332+ BlobKzgs BlobKzgs
333+ Blobs Blobs
334+ Proofs KZGProofs
298335}
299336
300337// sizeWrapData returns the size in bytes of the ssz-encoded BlobTxWrapData
301338func (b * BlobTxWrapData ) sizeWrapData () common.StorageSize {
302- return common .StorageSize (codec .ContainerLength (& b .BlobKzgs , & b .Blobs , & b .KzgAggregatedProof ))
339+ return common .StorageSize (codec .ContainerLength (& b .BlobKzgs , & b .Blobs , & b .Proofs ))
303340}
304341
305342// validateBlobTransactionWrapper implements validate_blob_transaction_wrapper from EIP-4844
@@ -320,7 +357,7 @@ func (b *BlobTxWrapData) validateBlobTransactionWrapper(inner TxData) error {
320357 if l1 > params .MaxBlobsPerBlock {
321358 return fmt .Errorf ("number of blobs exceeds max: %v" , l1 )
322359 }
323- err := eth .CryptoCtx .VerifyAggregateKZGProof (toBlobs (b .Blobs ), api . KZGProof (b .KzgAggregatedProof ), toComms (b .BlobKzgs ))
360+ err := eth .CryptoCtx .VerifyBlobKZGProofBatch (toBlobs (b .Blobs ), toProofs (b .Proofs ), toComms (b .BlobKzgs ))
324361 if err != nil {
325362 return fmt .Errorf ("error during proof verification: %v" , err )
326363 }
@@ -337,9 +374,9 @@ func (b *BlobTxWrapData) validateBlobTransactionWrapper(inner TxData) error {
337374
338375func (b * BlobTxWrapData ) copy () TxWrapData {
339376 return & BlobTxWrapData {
340- BlobKzgs : b .BlobKzgs .copy (),
341- Blobs : b .Blobs .copy (),
342- KzgAggregatedProof : b . KzgAggregatedProof ,
377+ BlobKzgs : b .BlobKzgs .copy (),
378+ Blobs : b .Blobs .copy (),
379+ Proofs : b . Proofs . copy () ,
343380 }
344381}
345382
@@ -351,8 +388,8 @@ func (b *BlobTxWrapData) blobs() Blobs {
351388 return b .Blobs
352389}
353390
354- func (b * BlobTxWrapData ) aggregatedProof () KZGProof {
355- return b .KzgAggregatedProof
391+ func (b * BlobTxWrapData ) proofs () KZGProofs {
392+ return b .Proofs
356393}
357394
358395func (b * BlobTxWrapData ) encodeTyped (w io.Writer , txdata TxData ) error {
@@ -364,10 +401,10 @@ func (b *BlobTxWrapData) encodeTyped(w io.Writer, txdata TxData) error {
364401 return fmt .Errorf ("expected signed blob tx, got %T" , txdata )
365402 }
366403 wrapped := BlobTxWrapper {
367- Tx : * blobTx ,
368- BlobKzgs : b .BlobKzgs ,
369- Blobs : b .Blobs ,
370- KzgAggregatedProof : b . KzgAggregatedProof ,
404+ Tx : * blobTx ,
405+ BlobKzgs : b .BlobKzgs ,
406+ Blobs : b .Blobs ,
407+ Proofs : b . Proofs ,
371408 }
372409 return EncodeSSZ (w , & wrapped )
373410}
0 commit comments