Skip to content

Commit

Permalink
Revert "crypto/kzg4844: do lazy init in all ckzg funcs (ethereum#27679)"
Browse files Browse the repository at this point in the history
This reverts commit 618fcc6.
  • Loading branch information
devopsbo3 authored Nov 10, 2023
1 parent 4401477 commit 37f1731
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crypto/kzg4844/kzg4844.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func UseCKZG(use bool) error {
useCKZG.Store(use)

// Initializing the library can take 2-4 seconds - and can potentially crash
// on CKZG and non-ADX CPUs - so might as well do it now and don't wait until
// on CKZG and non-ADX CPUs - so might as well so it now and don't wait until
// a crypto operation is actually needed live.
if use {
ckzgIniter.Do(ckzgInit)
Expand Down
8 changes: 0 additions & 8 deletions crypto/kzg4844/kzg4844_ckzg_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ 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) {
ckzgIniter.Do(ckzgInit)

proof, claim, err := ckzg4844.ComputeKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes32)(point))
if err != nil {
return Proof{}, Claim{}, err
Expand All @@ -86,8 +84,6 @@ func ckzgComputeProof(blob Blob, point Point) (Proof, Claim, error) {
// ckzgVerifyProof verifies the KZG proof that the polynomial represented by the blob
// evaluated at the given point is the claimed value.
func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proof) error {
ckzgIniter.Do(ckzgInit)

valid, err := ckzg4844.VerifyKZGProof((ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes32)(point), (ckzg4844.Bytes32)(claim), (ckzg4844.Bytes48)(proof))
if err != nil {
return err
Expand All @@ -103,8 +99,6 @@ func ckzgVerifyProof(commitment Commitment, point Point, claim Claim, proof Proo
//
// This method does not verify that the commitment is correct with respect to blob.
func ckzgComputeBlobProof(blob Blob, commitment Commitment) (Proof, error) {
ckzgIniter.Do(ckzgInit)

proof, err := ckzg4844.ComputeBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment))
if err != nil {
return Proof{}, err
Expand All @@ -114,8 +108,6 @@ 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 {
ckzgIniter.Do(ckzgInit)

valid, err := ckzg4844.VerifyBlobKZGProof((ckzg4844.Blob)(blob), (ckzg4844.Bytes48)(commitment), (ckzg4844.Bytes48)(proof))
if err != nil {
return err
Expand Down
12 changes: 2 additions & 10 deletions crypto/kzg4844/kzg4844_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func randBlob() Blob {

func TestCKZGWithPoint(t *testing.T) { testKZGWithPoint(t, true) }
func TestGoKZGWithPoint(t *testing.T) { testKZGWithPoint(t, false) }

func testKZGWithPoint(t *testing.T, ckzg bool) {
if ckzg && !ckzgAvailable {
t.Skip("CKZG unavailable in this test build")
Expand All @@ -72,6 +73,7 @@ func testKZGWithPoint(t *testing.T, ckzg bool) {

func TestCKZGWithBlob(t *testing.T) { testKZGWithBlob(t, true) }
func TestGoKZGWithBlob(t *testing.T) { testKZGWithBlob(t, false) }

func testKZGWithBlob(t *testing.T, ckzg bool) {
if ckzg && !ckzgAvailable {
t.Skip("CKZG unavailable in this test build")
Expand Down Expand Up @@ -104,8 +106,6 @@ func benchmarkBlobToCommitment(b *testing.B, ckzg bool) {
useCKZG.Store(ckzg)

blob := randBlob()

b.ResetTimer()
for i := 0; i < b.N; i++ {
BlobToCommitment(blob)
}
Expand All @@ -124,8 +124,6 @@ func benchmarkComputeProof(b *testing.B, ckzg bool) {
blob = randBlob()
point = randFieldElement()
)

b.ResetTimer()
for i := 0; i < b.N; i++ {
ComputeProof(blob, point)
}
Expand All @@ -146,8 +144,6 @@ func benchmarkVerifyProof(b *testing.B, ckzg bool) {
commitment, _ = BlobToCommitment(blob)
proof, claim, _ = ComputeProof(blob, point)
)

b.ResetTimer()
for i := 0; i < b.N; i++ {
VerifyProof(commitment, point, claim, proof)
}
Expand All @@ -166,8 +162,6 @@ func benchmarkComputeBlobProof(b *testing.B, ckzg bool) {
blob = randBlob()
commitment, _ = BlobToCommitment(blob)
)

b.ResetTimer()
for i := 0; i < b.N; i++ {
ComputeBlobProof(blob, commitment)
}
Expand All @@ -187,8 +181,6 @@ func benchmarkVerifyBlobProof(b *testing.B, ckzg bool) {
commitment, _ = BlobToCommitment(blob)
proof, _ = ComputeBlobProof(blob, commitment)
)

b.ResetTimer()
for i := 0; i < b.N; i++ {
VerifyBlobProof(blob, commitment, proof)
}
Expand Down

0 comments on commit 37f1731

Please sign in to comment.