2023-08-03 20:35:30 +00:00
|
|
|
package kzg
|
|
|
|
|
|
|
|
import (
|
|
|
|
GoKZG "github.com/crate-crypto/go-kzg-4844"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
2023-08-03 20:35:30 +00:00
|
|
|
)
|
|
|
|
|
2024-01-06 23:47:09 +00:00
|
|
|
// Verify performs single or batch verification of commitments depending on the number of given BlobSidecars.
|
|
|
|
func Verify(sidecars ...blocks.ROBlob) error {
|
|
|
|
if len(sidecars) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if len(sidecars) == 1 {
|
|
|
|
return kzgContext.VerifyBlobKZGProof(
|
|
|
|
bytesToBlob(sidecars[0].Blob),
|
|
|
|
bytesToCommitment(sidecars[0].KzgCommitment),
|
|
|
|
bytesToKZGProof(sidecars[0].KzgProof))
|
|
|
|
}
|
|
|
|
blobs := make([]GoKZG.Blob, len(sidecars))
|
|
|
|
cmts := make([]GoKZG.KZGCommitment, len(sidecars))
|
|
|
|
proofs := make([]GoKZG.KZGProof, len(sidecars))
|
|
|
|
for i, sidecar := range sidecars {
|
|
|
|
blobs[i] = bytesToBlob(sidecar.Blob)
|
|
|
|
cmts[i] = bytesToCommitment(sidecar.KzgCommitment)
|
|
|
|
proofs[i] = bytesToKZGProof(sidecar.KzgProof)
|
|
|
|
}
|
|
|
|
return kzgContext.VerifyBlobKZGProofBatch(blobs, cmts, proofs)
|
2023-12-07 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 20:35:30 +00:00
|
|
|
func bytesToBlob(blob []byte) (ret GoKZG.Blob) {
|
|
|
|
copy(ret[:], blob)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func bytesToCommitment(commitment []byte) (ret GoKZG.KZGCommitment) {
|
|
|
|
copy(ret[:], commitment)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func bytesToKZGProof(proof []byte) (ret GoKZG.KZGProof) {
|
|
|
|
copy(ret[:], proof)
|
|
|
|
return
|
|
|
|
}
|