Skip to content

Conversation

@nalepae
Copy link
Contributor

@nalepae nalepae commented Apr 17, 2025

Please read commit by commit.

This way, If we need to change the KZG backend, the only package to modify is the kzg package.

What type of PR is this?
Feature

What does this PR do? Why is it needed?
The whole picture is available here.

Other notes for review
Peerdas from scratch

Acknowledgements

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.
@nalepae nalepae mentioned this pull request Apr 17, 2025
3 tasks
@@ -1,4 +1,4102 @@
{
"g1_monomial": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reference to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here.

@@ -0,0 +1,138 @@
package kzg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this package located in blockchain instead of a place like consensus-types? Curious if there’s any rationale or tradeoff behind that decision

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new kzg.go file has been added here because the kzg package was located here.
Seems Potuz created this package here.

I'm not opposed to move it elsewhere. I don't have any strong opinion on that.

}

// BlobToKZGCommitment computes a KZG commitment from a given blob.
func BlobToKZGCommitment(blob *Blob) (Commitment, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we dont have unit tests for functions in this file, should we have them?

Copy link
Contributor Author

@nalepae nalepae Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked myself the same question.
It turns out all these functions are only wrappers around the KZG backend.

For example:

// ComputeBlobKZGProof computes the blob KZG proof from a given blob and its commitment.
func ComputeBlobKZGProof(blob *Blob, commitment Commitment) (Proof, error) {
	kzgBlob := kzg4844.Blob(*blob)

	proof, err := kzg4844.ComputeBlobProof(&kzgBlob, kzg4844.Commitment(commitment))
	if err != nil {
		return [48]byte{}, err
	}
	return Proof(proof), nil
}

does only:

  • Cast a *Blob into a kzg4844.Blob
  • Call kzg4844.ComputeBlobProof
  • Return the error if error
  • If no error, cast the result into Proof and return it

Testing the wrapper itself does not add a lot of safety.

However:

  • The KZG backend itself is very well tested (and will be externally audited in ~June)
  • All functions using these wrappers are very well tested as well (as in PeerDAS: Implement core. #15192)

@nalepae nalepae requested a review from terencechain April 17, 2025 18:41

// BlobToKZGCommitment computes a KZG commitment from a given blob.
func BlobToKZGCommitment(blob *Blob) (Commitment, error) {
kzgBlob := kzg4844.Blob(*blob)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cast directly from [BytesPerBlob]byte to the expected struct. If upstream changes the internal layout of ckzg4844.Blob, this could break. While currently safe (since it's just a byte array), a safer approach would be:

var kzgBlob kzg4844.Blob
copy(kzgBlob[:], blob[:])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with (*ckzg4844.Blob)(blob)

return makeCellsAndProofs(ckzgCells[:], ckzgProofs[:])
}

// VerifyBlobKZGProof verifies the KZG proofs for a given slice of commitments, cells indices, cells and proofs.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should start with VerifyCellKZGProofBatch

Comment on lines 127 to 128
var cells []Cell
var proofs []Proof
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can pre allocate these slices already

cells := make([]Cell, len(ckzgCells))
proofs := make([]Proof, len(ckzgProofs))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually because we use append we should pre allocate the capacity but not the size.

@nalepae nalepae enabled auto-merge April 17, 2025 21:59
@nalepae nalepae added this pull request to the merge queue Apr 17, 2025
Merged via the queue into develop with commit ab5505e Apr 17, 2025
15 checks passed
@nalepae nalepae deleted the peerdas-kzg branch April 17, 2025 23:11
nalepae added a commit that referenced this pull request Apr 27, 2025
…15186)

* Implement all needed KZG wrappers for peerDAS in the `kzg` package.

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.

* `.bazelrc`: Add `build --compilation_mode=opt`

* Remove --compilation_mode=opt, use supranational blst headers.

* Fix Terence's comment.

* Fix Terence`s comments.

---------

Co-authored-by: Preston Van Loon <[email protected]>
nalepae added a commit that referenced this pull request Apr 28, 2025
…15186)

* Implement all needed KZG wrappers for peerDAS in the `kzg` package.

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.

* `.bazelrc`: Add `build --compilation_mode=opt`

* Remove --compilation_mode=opt, use supranational blst headers.

* Fix Terence's comment.

* Fix Terence`s comments.

---------

Co-authored-by: Preston Van Loon <[email protected]>
nalepae added a commit that referenced this pull request Apr 28, 2025
…15186)

* Implement all needed KZG wrappers for peerDAS in the `kzg` package.

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.

* `.bazelrc`: Add `build --compilation_mode=opt`

* Remove --compilation_mode=opt, use supranational blst headers.

* Fix Terence's comment.

* Fix Terence`s comments.

---------

Co-authored-by: Preston Van Loon <[email protected]>
prestonvanloon added a commit that referenced this pull request May 2, 2025
…package. (#15186)"

This backs out commit ab5505e.

Fix conflicts in go.mod and go.sum
fernantho pushed a commit to fernantho/prysm that referenced this pull request Sep 26, 2025
…ffchainLabs#15186)

* Implement all needed KZG wrappers for peerDAS in the `kzg` package.

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.

* `.bazelrc`: Add `build --compilation_mode=opt`

* Remove --compilation_mode=opt, use supranational blst headers.

* Fix Terence's comment.

* Fix Terence`s comments.

---------

Co-authored-by: Preston Van Loon <[email protected]>
fernantho pushed a commit to fernantho/prysm that referenced this pull request Sep 26, 2025
…ffchainLabs#15186)

* Implement all needed KZG wrappers for peerDAS in the `kzg` package.

This way, If we need to change the KZG backend, the only package to
modify is the `kzg` package.

* `.bazelrc`: Add `build --compilation_mode=opt`

* Remove --compilation_mode=opt, use supranational blst headers.

* Fix Terence's comment.

* Fix Terence`s comments.

---------

Co-authored-by: Preston Van Loon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants