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

Implement a wrapper around c-kzg jni bindings #6520

Merged
merged 7 commits into from
Nov 30, 2022

Conversation

zilm13
Copy link
Contributor

@zilm13 zilm13 commented Nov 29, 2022

PR Description

I'm pretty unsure on everything here, but need to start from something
Some notes:

  • I was looking at bls module while making this
  • I'm not sure that we need KZGLoader here
  • No optimizations were taken into consideration at that stage
  • Test is pretty slow, but I've not found minimal setup anywhere
  • I've isolated reset exception if nothing is loaded, I'm not sure it's useful, looks more like a bug you could get into from my side

Fixed Issue(s)

Fixes #6470

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

.loadBytes(path)
.orElseThrow(() -> new FileNotFoundException("Not found"));

File temp = File.createTempFile("resource", ".tmp");

Check warning

Code scanning / CodeQL

Local information disclosure in a temporary directory

Local information disclosure vulnerability due to use of file readable by other local users.
Copy link
Contributor

@tbenr tbenr left a comment

Choose a reason for hiding this comment

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

Makes sense to me to leave CkzgLoader as a decoupling layer in case we'll different libraries in the future to choose from.

I provided some initial comments

* @param path a path to a trusted setup file in filesystem
* @throws KzgException if file not found or arguments from file are incorrect
*/
void loadTrustedSetup(final String path) throws KzgException;
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't use final in interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, fixed

* @param blobs Blobs
* @return the aggregated proof
*/
KZGProof computeAggregateKzgProof(List<Bytes> blobs);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we have throws KzgException; on all methods here?

return kzgImpl.verifyKzgProof(kzgCommitment, z, y, kzgProof);
}

private static String copyResourceToTempFile(final String path) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we pass-through the file if it is a local path?

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, but I guess we will need absolute path
also how could I recognize it?

Copy link
Contributor

Choose a reason for hiding this comment

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

is you switch path from String to URI and then getScheme().equalsIgnoreCase("file") ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you
also I decided to pass URL there instead of String, so it's clear that it comes with scheme and not just path

KZG.loadTrustedSetup(resourcePath);
KZG.resetTrustedSetup();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add another test named like testKzgLoadTrustedSetupTwice to verify that we cannot load a setup without resetting the previous one

@tbenr
Copy link
Contributor

tbenr commented Nov 30, 2022

Worth also checking what happens if we call the kzg functions without having previously loaded any setup

throws KzgException {
try {
return CKzg4844JNI.verifyAggregateKzgProof(
blobs.stream().reduce(Bytes::wrap).orElseThrow().toArray(),
Copy link
Contributor

Choose a reason for hiding this comment

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

empty blobs and commitments are actually a thing: ethereum/consensus-specs#3093
I think we should cover the case here and in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, doing it already, nice catch!

@zilm13 zilm13 marked this pull request as ready for review November 30, 2022 13:43
Copy link
Contributor

@tbenr tbenr left a comment

Choose a reason for hiding this comment

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

LGTM.
we should do an optimization round. I'll track it in the epic backlog

@zilm13 zilm13 merged commit bd55040 into Consensys:master Nov 30, 2022
@zilm13 zilm13 deleted the feature/eip4844-kzg-bindings branch November 30, 2022 14:31
@tbenr tbenr mentioned this pull request Nov 30, 2022
58 tasks
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.

Add c-kzg java binding dependency in infrastructure crypto module
2 participants