mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
wip pass blobs by reference
This commit is contained in:
parent
ebf9e11af2
commit
779c8b628c
9 changed files with 33 additions and 33 deletions
|
|
@ -49,8 +49,8 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyBlob = kzg4844.Blob{}
|
emptyBlob = kzg4844.Blob{}
|
||||||
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
|
emptyBlobCommit, _ = kzg4844.BlobToCommitment(&emptyBlob)
|
||||||
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
|
emptyBlobProof, _ = kzg4844.ComputeBlobProof(&emptyBlob, emptyBlobCommit)
|
||||||
emptyBlobVHash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
|
emptyBlobVHash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) err
|
||||||
// Blob commitments match with the hashes in the transaction, verify the
|
// Blob commitments match with the hashes in the transaction, verify the
|
||||||
// blobs themselves via KZG
|
// blobs themselves via KZG
|
||||||
for i := range sidecar.Blobs {
|
for i := range sidecar.Blobs {
|
||||||
if err := kzg4844.VerifyBlobProof(sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
|
if err := kzg4844.VerifyBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
|
||||||
return fmt.Errorf("invalid blob %d: %v", i, err)
|
return fmt.Errorf("invalid blob %d: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ func UseCKZG(use bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlobToCommitment creates a small commitment out of a data blob.
|
// BlobToCommitment creates a small commitment out of a data blob.
|
||||||
func BlobToCommitment(blob Blob) (Commitment, error) {
|
func BlobToCommitment(blob *Blob) (Commitment, error) {
|
||||||
if useCKZG.Load() {
|
if useCKZG.Load() {
|
||||||
return ckzgBlobToCommitment(blob)
|
return ckzgBlobToCommitment(blob)
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ func BlobToCommitment(blob Blob) (Commitment, error) {
|
||||||
|
|
||||||
// ComputeProof computes the KZG proof at the given point for the polynomial
|
// ComputeProof computes the KZG proof at the given point for the polynomial
|
||||||
// represented by the blob.
|
// represented by the blob.
|
||||||
func ComputeProof(blob Blob, point Point) (Proof, Claim, error) {
|
func ComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
|
||||||
if useCKZG.Load() {
|
if useCKZG.Load() {
|
||||||
return ckzgComputeProof(blob, point)
|
return ckzgComputeProof(blob, point)
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +134,7 @@ func VerifyProof(commitment Commitment, point Point, claim Claim, proof Proof) e
|
||||||
// the commitment.
|
// the commitment.
|
||||||
//
|
//
|
||||||
// This method does not verify that the commitment is correct with respect to blob.
|
// This method does not verify that the commitment is correct with respect to blob.
|
||||||
func ComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
func ComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
|
||||||
if useCKZG.Load() {
|
if useCKZG.Load() {
|
||||||
return ckzgComputeBlobProof(blob, commitment)
|
return ckzgComputeBlobProof(blob, commitment)
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,7 @@ func ComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
// VerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
||||||
func VerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
func VerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
|
||||||
if useCKZG.Load() {
|
if useCKZG.Load() {
|
||||||
return ckzgVerifyBlobProof(blob, commitment, proof)
|
return ckzgVerifyBlobProof(blob, commitment, proof)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@ func ckzgInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ckzgBlobToCommitment creates a small commitment out of a data blob.
|
// ckzgBlobToCommitment creates a small commitment out of a data blob.
|
||||||
func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
|
func ckzgBlobToCommitment(blob *Blob) (Commitment, error) {
|
||||||
ckzgIniter.Do(ckzgInit)
|
ckzgIniter.Do(ckzgInit)
|
||||||
|
|
||||||
commitment, err := ckzg4844.BlobToKZGCommitment((ckzg4844.Blob)(blob))
|
commitment, err := ckzg4844.BlobToKZGCommitment((*ckzg4844.Blob)(blob))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Commitment{}, err
|
return Commitment{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -73,10 +73,10 @@ func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
|
||||||
|
|
||||||
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
||||||
// represented by the blob.
|
// represented by the blob.
|
||||||
func ckzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
|
func ckzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
|
||||||
ckzgIniter.Do(ckzgInit)
|
ckzgIniter.Do(ckzgInit)
|
||||||
|
|
||||||
proof, claim, err := ckzg4844.ComputeKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes32)(point))
|
proof, claim, err := ckzg4844.ComputeKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes32)(point))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proof{}, Claim{}, err
|
return Proof{}, Claim{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -102,10 +102,10 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
|
||||||
// the commitment.
|
// the commitment.
|
||||||
//
|
//
|
||||||
// This method does not verify that the commitment is correct with respect to blob.
|
// This method does not verify that the commitment is correct with respect to blob.
|
||||||
func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
|
||||||
ckzgIniter.Do(ckzgInit)
|
ckzgIniter.Do(ckzgInit)
|
||||||
|
|
||||||
proof, err := ckzg4844.ComputeBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
|
proof, err := ckzg4844.ComputeBlobKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proof{}, err
|
return Proof{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -113,10 +113,10 @@ func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
||||||
func ckzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
|
||||||
ckzgIniter.Do(ckzgInit)
|
ckzgIniter.Do(ckzgInit)
|
||||||
|
|
||||||
valid, err := ckzg4844.VerifyBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes48)(proof))
|
valid, err := ckzg4844.VerifyBlobKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes48)(proof))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ func ckzgInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ckzgBlobToCommitment creates a small commitment out of a data blob.
|
// ckzgBlobToCommitment creates a small commitment out of a data blob.
|
||||||
func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
|
func ckzgBlobToCommitment(blob *Blob) (Commitment, error) {
|
||||||
panic("unsupported platform")
|
panic("unsupported platform")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
||||||
// represented by the blob.
|
// represented by the blob.
|
||||||
func ckzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
|
func ckzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
|
||||||
panic("unsupported platform")
|
panic("unsupported platform")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,11 +52,11 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
|
||||||
// the commitment.
|
// the commitment.
|
||||||
//
|
//
|
||||||
// This method does not verify that the commitment is correct with respect to blob.
|
// This method does not verify that the commitment is correct with respect to blob.
|
||||||
func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
func ckzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
|
||||||
panic("unsupported platform")
|
panic("unsupported platform")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
// ckzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
||||||
func ckzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
func ckzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
|
||||||
panic("unsupported platform")
|
panic("unsupported platform")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ func gokzgInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// gokzgBlobToCommitment creates a small commitment out of a data blob.
|
// gokzgBlobToCommitment creates a small commitment out of a data blob.
|
||||||
func gokzgBlobToCommitment(blob Blob) (Commitment, error) {
|
func gokzgBlobToCommitment(blob *Blob) (Commitment, error) {
|
||||||
gokzgIniter.Do(gokzgInit)
|
gokzgIniter.Do(gokzgInit)
|
||||||
|
|
||||||
commitment, err := context.BlobToKZGCommitment((gokzg4844.Blob)(blob), 0)
|
commitment, err := context.BlobToKZGCommitment((gokzg4844.Blob)(*blob), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Commitment{}, err
|
return Commitment{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -58,10 +58,10 @@ func gokzgBlobToCommitment(blob Blob) (Commitment, error) {
|
||||||
|
|
||||||
// gokzgComputeProof computes the KZG proof at the given point for the polynomial
|
// gokzgComputeProof computes the KZG proof at the given point for the polynomial
|
||||||
// represented by the blob.
|
// represented by the blob.
|
||||||
func gokzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
|
func gokzgComputeProof(blob *Blob, point Point) (Proof, Claim, error) {
|
||||||
gokzgIniter.Do(gokzgInit)
|
gokzgIniter.Do(gokzgInit)
|
||||||
|
|
||||||
proof, claim, err := context.ComputeKZGProof((gokzg4844.Blob)(blob), (gokzg4844.Scalar)(point), 0)
|
proof, claim, err := context.ComputeKZGProof((gokzg4844.Blob)(*blob), (gokzg4844.Scalar)(point), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proof{}, Claim{}, err
|
return Proof{}, Claim{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -80,10 +80,10 @@ func gokzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Pro
|
||||||
// the commitment.
|
// the commitment.
|
||||||
//
|
//
|
||||||
// This method does not verify that the commitment is correct with respect to blob.
|
// This method does not verify that the commitment is correct with respect to blob.
|
||||||
func gokzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
func gokzgComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error) {
|
||||||
gokzgIniter.Do(gokzgInit)
|
gokzgIniter.Do(gokzgInit)
|
||||||
|
|
||||||
proof, err := context.ComputeBlobKZGProof((gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), 0)
|
proof, err := context.ComputeBlobKZGProof((gokzg4844.Blob)(*blob), (gokzg4844.KZGCommitment)(commitment), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Proof{}, err
|
return Proof{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -91,8 +91,8 @@ func gokzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// gokzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
// gokzgVerifyBlobProof verifies that the blob data corresponds to the provided commitment.
|
||||||
func gokzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
func gokzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
|
||||||
gokzgIniter.Do(gokzgInit)
|
gokzgIniter.Do(gokzgInit)
|
||||||
|
|
||||||
return context.VerifyBlobKZGProof((gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
|
return context.VerifyBlobKZGProof((gokzg4844.Blob)(*blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -21,7 +21,7 @@ require (
|
||||||
github.com/deckarep/golang-set/v2 v2.1.0
|
github.com/deckarep/golang-set/v2 v2.1.0
|
||||||
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0
|
github.com/donovanhide/eventsource v0.0.0-20210830082556-c59027999da0
|
||||||
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3
|
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3
|
||||||
github.com/ethereum/c-kzg-4844 v0.4.0
|
github.com/ethereum/c-kzg-4844 v0.4.4-0.20240306214053-34858f7ec6f1
|
||||||
github.com/fatih/color v1.13.0
|
github.com/fatih/color v1.13.0
|
||||||
github.com/ferranbt/fastssz v0.1.2
|
github.com/ferranbt/fastssz v0.1.2
|
||||||
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e
|
github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -160,8 +160,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
|
github.com/ethereum/c-kzg-4844 v0.4.4-0.20240306214053-34858f7ec6f1 h1:dppiiKelBwtXKr36xtOs7yWEZhxEH7mrcAo0qbHcg7E=
|
||||||
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
|
github.com/ethereum/c-kzg-4844 v0.4.4-0.20240306214053-34858f7ec6f1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
|
||||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||||
github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk=
|
github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk=
|
||||||
|
|
|
||||||
|
|
@ -326,12 +326,12 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, b Backend) er
|
||||||
commitments := make([]kzg4844.Commitment, n)
|
commitments := make([]kzg4844.Commitment, n)
|
||||||
proofs := make([]kzg4844.Proof, n)
|
proofs := make([]kzg4844.Proof, n)
|
||||||
for i, b := range args.Blobs {
|
for i, b := range args.Blobs {
|
||||||
c, err := kzg4844.BlobToCommitment(b)
|
c, err := kzg4844.BlobToCommitment(&b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
|
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
|
||||||
}
|
}
|
||||||
commitments[i] = c
|
commitments[i] = c
|
||||||
p, err := kzg4844.ComputeBlobProof(b, c)
|
p, err := kzg4844.ComputeBlobProof(&b, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
|
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
@ -341,7 +341,7 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, b Backend) er
|
||||||
args.Proofs = proofs
|
args.Proofs = proofs
|
||||||
} else {
|
} else {
|
||||||
for i, b := range args.Blobs {
|
for i, b := range args.Blobs {
|
||||||
if err := kzg4844.VerifyBlobProof(b, args.Commitments[i], args.Proofs[i]); err != nil {
|
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
|
||||||
return fmt.Errorf("failed to verify blob proof: %v", err)
|
return fmt.Errorf("failed to verify blob proof: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue