crypto/kzg4844: do lazy init in all ckzg funcs#27679
crypto/kzg4844: do lazy init in all ckzg funcs#27679karalabe merged 3 commits intoethereum:masterfrom jtraglia:kzg-nits
Conversation
Tests call it directly, without doing the proper loading, so this PR breaks that |
|
Ah sorry, I didn't notice that. I've made some changes to the test file that should fix this.
|
|
Also, from looking at the benchmarks I can tell that go-kzg is using concurrency. In Peter's comment about this a while back, it didn't seem like this was the desired behavior. Should I fix this in another PR? The last argument in go-kzg functions is |
|
We reviewed this in a team call, and it seems not great to call |
|
This seems a simpler fix that's also consistent with the go version diff --git a/crypto/kzg4844/kzg4844_ckzg_cgo.go b/crypto/kzg4844/kzg4844_ckzg_cgo.go
index d62ca3fad..540028569 100644
--- a/crypto/kzg4844/kzg4844_ckzg_cgo.go
+++ b/crypto/kzg4844/kzg4844_ckzg_cgo.go
@@ -74,6 +74,8 @@ 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
@@ -84,6 +86,8 @@ 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
@@ -99,6 +103,8 @@ 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
@@ -108,6 +114,8 @@ 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 |
|
@fjl Okay, no worries. I understand. I've made a new commit that should resolve this. |
* crypto/kzg4844: remove unnecessary init call & fix typo * Fix kzg4844 tests/benchmarks * Make init lazy & revert changes to tests
This reverts commit 618fcc6.
This reverts commit 618fcc6.
* crypto/kzg4844: remove unnecessary init call & fix typo * Fix kzg4844 tests/benchmarks * Make init lazy & revert changes to tests
ckzgIniter.Do(ckzgInit)call to all c-kzg functions.b.ResetTimer()in benchmarks for accuracy.