Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EIP-7594 #452

Merged
merged 246 commits into from
Jul 18, 2024
Merged

Add support for EIP-7594 #452

merged 246 commits into from
Jul 18, 2024

Conversation

jtraglia
Copy link
Member

@jtraglia jtraglia commented Jul 12, 2024

This is a big PR which merges the das branch into main.

Client teams: when you have time, please review the changes to the bindings you use.

When we merge this, please squash the commits.

Notable changes to the bindings

  • Add compute_cells_and_kzg_proofs, recover_cells_and_kzg_proofs, verify_cell_kzg_proof_batch bindings.
  • Extend the trusted setup with G1 points in monomial form; there are three groups of points now.
  • Change load_trusted_setup (bytes version) to take flat array of bytes rather than list of point bytes.
    • This means the size params represent number of total bytes, not the number of points.
  • Add precompute parameter to functions which load the trusted setup.
    • This is an integer between 0 and 15. It's used to speed up proof computations.
    • Refer to this HackMD document to compare tradeoffs.
  • Make some of the previously public constants private.

Notable changes to the core implementation

  • Replace big stack allocations with heap allocations in load_trusted_setup_file.
  • Modify g1_lincomb_fast to work with points at infinity.
    • Relatively simple change, but EIP-4844 functions use it.
  • Replace uses of CHECK macro with normal conditions.
    • There was a risk of misusing this and returning without freeing allocations.

Other notable changes

  • Replace old C LLVMFuzzer with new cargo-fuzz implementation in Rust.

jtraglia and others added 30 commits November 14, 2023 13:24
I have included Go bindings for this new method. I will add Rust bindings
later. This will break the Rust bindings build until then, sorry about that.
The sample structure now includes the data, proof, and indices. This should
make things easier to read and understand. Bindings will be broken for a little
while. Going to remove the 2d functions, as I don't think they are that useful
at the moment.
@jtraglia jtraglia requested a review from a team July 12, 2024 18:25

foreach (string testFile in testFiles)
{
string yaml = File.ReadAllText(testFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

In general cases could be separated to a source passed to TestCaseSource attribute

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I only did this for the new ones. Let's follow-up with a PR for the old tests later.

{
Ckzg.ComputeCellsAndKzgProofs(cells, proofs, blob, _ts);
Assert.That(test.Output, Is.Not.EqualTo(null));
byte[] expectedCells = GetFlatBytes(test.Output.ElementAt(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the type of it be an array of arrays instead? Could you access elements just by [index]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I'm not sure about this one. Let's look into this afterwards.

@@ -43,24 +43,36 @@ public static void loadNativeLibrary() {
}
}

/** Scalar field modulus of BLS12-381 */
public static final BigInteger BLS_MODULUS =
Copy link
Contributor

@StefanBratanov StefanBratanov Jul 15, 2024

Choose a reason for hiding this comment

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

Why did we decide to make the constants private. They could be useful to projects using the library. We use some of them in Teku.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, protecting those constants was a conscious decision. It was an attempt to remove cryptographic details from the clients. In some cases cryptography code can be easy to mess up, and client devs might not be aware of the various cryptographic intricacies, so this change was done so that cryptography logic gets concentrated in the libraries.

How do you use these constants in Teku?

Copy link
Contributor

@StefanBratanov StefanBratanov Jul 18, 2024

Choose a reason for hiding this comment

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

We have a utility class which flattens a list of commitments/proofs for example and we calculate the expected size based on these constants to initialize the array e.g. https://github.com/Consensys/teku/blob/master/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/CKZG4844Utils.java

We also use in tests https://github.com/Consensys/teku/blob/master/infrastructure/kzg/src/test/java/tech/pegasys/teku/kzg/CKZG4844Test.java

I suppose not an issue to replicate those in Teku internally in the module, but would lead to duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

Stefan, we've decided to revert this change. So these constants are public again for all bindings. With the exception of the BYTES_PER_G* constants because load_trusted_setup takes a flat array of bytes now.

jtraglia added 4 commits July 15, 2024 11:48
I believe this affects how clients see the return types. It appears as a slice
instead of an array of a known size. This isn't right.
bindings/nim/kzg.nim Outdated Show resolved Hide resolved
bindings/nim/kzg.nim Outdated Show resolved Hide resolved
bindings/nim/kzg.nim Outdated Show resolved Hide resolved
bindings/nim/kzg.nim Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.