mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
chore(dep): upgrade go kzg 4844 (#718)
* crypto/kz4844: pass blobs by ref (#29050) This change makes use of the following underlying changes to the kzg-libraries in order to avoid passing large things on the stack: - c-kzg: https://github.com/ethereum/c-kzg-4844/pull/393 and - go-kzg: https://github.com/crate-crypto/go-kzg-4844/pull/63 * update version patch * run go mod tidy * use blob reference --------- Co-authored-by: Martin HS <martin@swende.se> Co-authored-by: Mason Liang <mason@scroll.io>
This commit is contained in:
parent
246955a4df
commit
90221d6fc7
9 changed files with 33 additions and 33 deletions
|
|
@ -66,7 +66,7 @@ func UseCKZG(use bool) error {
|
|||
}
|
||||
|
||||
// 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() {
|
||||
return ckzgBlobToCommitment(blob)
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ func BlobToCommitment(blob Blob) (Commitment, error) {
|
|||
|
||||
// ComputeProof computes the KZG proof at the given point for the polynomial
|
||||
// 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() {
|
||||
return ckzgComputeProof(blob, point)
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ func VerifyProof(commitment Commitment, point Point, claim Claim, proof Proof) e
|
|||
// the commitment.
|
||||
//
|
||||
// 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() {
|
||||
return ckzgComputeBlobProof(blob, commitment)
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ func ComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
|||
}
|
||||
|
||||
// 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() {
|
||||
return ckzgVerifyBlobProof(blob, commitment, proof)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ func ckzgInit() {
|
|||
}
|
||||
|
||||
// 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)
|
||||
|
||||
commitment, err := ckzg4844.BlobToKZGCommitment((ckzg4844.Blob)(blob))
|
||||
commitment, err := ckzg4844.BlobToKZGCommitment((*ckzg4844.Blob)(blob))
|
||||
if err != nil {
|
||||
return Commitment{}, err
|
||||
}
|
||||
|
|
@ -74,10 +74,10 @@ func ckzgBlobToCommitment(blob Blob) (Commitment, error) {
|
|||
|
||||
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
||||
// 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)
|
||||
|
||||
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 {
|
||||
return Proof{}, Claim{}, err
|
||||
}
|
||||
|
|
@ -103,10 +103,10 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
|
|||
// the commitment.
|
||||
//
|
||||
// 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)
|
||||
|
||||
proof, err := ckzg4844.ComputeBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
|
||||
proof, err := ckzg4844.ComputeBlobKZGProof((*ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
|
||||
if err != nil {
|
||||
return Proof{}, err
|
||||
}
|
||||
|
|
@ -114,10 +114,10 @@ func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ func ckzgInit() {
|
|||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
// ckzgComputeProof computes the KZG proof at the given point for the polynomial
|
||||
// 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")
|
||||
}
|
||||
|
||||
|
|
@ -52,11 +52,11 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
|
|||
// the commitment.
|
||||
//
|
||||
// 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")
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ func gokzgInit() {
|
|||
}
|
||||
|
||||
// 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)
|
||||
|
||||
commitment, err := context.BlobToKZGCommitment((gokzg4844.Blob)(blob), 0)
|
||||
commitment, err := context.BlobToKZGCommitment((*gokzg4844.Blob)(blob), 0)
|
||||
if err != nil {
|
||||
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
|
||||
// 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)
|
||||
|
||||
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 {
|
||||
return Proof{}, Claim{}, err
|
||||
}
|
||||
|
|
@ -80,10 +80,10 @@ func gokzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Pro
|
|||
// the commitment.
|
||||
//
|
||||
// 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)
|
||||
|
||||
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 {
|
||||
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.
|
||||
func gokzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error {
|
||||
func gokzgVerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error {
|
||||
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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ func randFieldElement() [32]byte {
|
|||
return gokzg4844.SerializeScalar(r)
|
||||
}
|
||||
|
||||
func randBlob() Blob {
|
||||
func randBlob() *Blob {
|
||||
var blob Blob
|
||||
for i := 0; i < len(blob); i += gokzg4844.SerializedScalarSize {
|
||||
fieldElementBytes := randFieldElement()
|
||||
copy(blob[i:i+gokzg4844.SerializedScalarSize], fieldElementBytes[:])
|
||||
}
|
||||
return blob
|
||||
return &blob
|
||||
}
|
||||
|
||||
func TestCKZGWithPoint(t *testing.T) { testKZGWithPoint(t, true) }
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -13,7 +13,7 @@ require (
|
|||
github.com/cespare/cp v0.1.0
|
||||
github.com/cloudflare/cloudflare-go v0.14.0
|
||||
github.com/consensys/gnark-crypto v0.10.0
|
||||
github.com/crate-crypto/go-kzg-4844 v0.7.0
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea
|
||||
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -101,8 +101,8 @@ github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH
|
|||
github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA=
|
||||
github.com/consensys/gnark-crypto v0.10.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA=
|
||||
github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI=
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
const (
|
||||
VersionMajor = 5 // Major version component of the current release
|
||||
VersionMinor = 3 // Minor version component of the current release
|
||||
VersionPatch = 0 // Patch version component of the current release
|
||||
VersionPatch = 1 // Patch version component of the current release
|
||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ func constructBlobPayload(chunks []*encoding.Chunk) (*kzg4844.Blob, common.Hash,
|
|||
}
|
||||
|
||||
// compute blob versioned hash
|
||||
c, err := kzg4844.BlobToCommitment(*blob)
|
||||
c, err := kzg4844.BlobToCommitment(blob)
|
||||
if err != nil {
|
||||
return nil, common.Hash{}, nil, fmt.Errorf("failed to create blob commitment")
|
||||
}
|
||||
|
|
@ -452,12 +452,12 @@ func (b *DABatch) BlobDataProof() ([]byte, error) {
|
|||
return nil, errors.New("called BlobDataProof with empty z")
|
||||
}
|
||||
|
||||
commitment, err := kzg4844.BlobToCommitment(*b.blob)
|
||||
commitment, err := kzg4844.BlobToCommitment(b.blob)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create blob commitment")
|
||||
}
|
||||
|
||||
proof, y, err := kzg4844.ComputeProof(*b.blob, *b.z)
|
||||
proof, y, err := kzg4844.ComputeProof(b.blob, *b.z)
|
||||
if err != nil {
|
||||
log.Crit("failed to create KZG proof at point", "err", err, "z", hex.EncodeToString(b.z[:]))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue