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

KZG point eval precompile #4860

Merged
merged 29 commits into from
Jan 23, 2023
Merged

KZG point eval precompile #4860

merged 29 commits into from
Jan 23, 2023

Conversation

jflo
Copy link
Contributor

@jflo jflo commented Dec 22, 2022

PR description

Adds a new precompile as part of EIP-4844 which allows contracts to evaluate KZG commitments.

Fixed Issue(s)

fixes #4822

Documentation

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

Changelog

@jflo jflo added the doc-change-required Indicates an issue or PR that requires doc to be updated label Dec 22, 2022
@jflo jflo marked this pull request as ready for review January 3, 2023 14:15
.github/workflows/dco.yml Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@jflo jflo marked this pull request as draft January 4, 2023 02:18
@jflo jflo force-pushed the KZGpointEvalPrecompile branch 2 times, most recently from 524830b to 2e21716 Compare January 6, 2023 15:23
@jflo jflo requested a review from siladu January 6, 2023 15:34
@jflo jflo marked this pull request as ready for review January 6, 2023 15:34
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

Added some comments but still want to understand and play with the tests a bit more.

Regarding the task list on #4822...

  • package the mainnet kzg trusted setup file so it is delivered via distribution in such a way that it can be loaded by native lib from the filesystem; loading from classpath won't work.

What was the solution for this?

  • add support for reftests that cover it

Was this done in this PR?

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
@jflo
Copy link
Contributor Author

jflo commented Jan 15, 2023

Loading from classpath is fine, and user will be able to override that later. We are still waiting on retesteth updates to cover it.

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

looks good, please check the comments

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
@jflo jflo requested review from siladu and fab-10 January 19, 2023 19:41
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

Some old and new comments

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
KZGPointEvalPrecompiledContract.class.getResourceAsStream(
"mainnet_kzg_trusted_setup_4096.txt");
try {
File jniWillLoadFrom = File.createTempFile("kzgTrustedSetup", "txt");

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.
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

LGTM, just a nit

jumpDestCacheWeightKilobytes, Optional.ofNullable(kzgTrustedSetupFilePath));
jumpDestCacheWeightKilobytes,
kzgTrustedSetupFilePath != null
? Optional.ofNullable(Path.of(kzgTrustedSetupFilePath))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: result of Path::of is never null

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a base level configuration option. This is the wrong place in code to do it. It should be an argument in the MainnetEVMs methods for relevant versions.

Copy link
Contributor

@shemnon shemnon left a comment

Choose a reason for hiding this comment

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

I don't like how the KZG files are being brought in. Especially if we already have hard-coded a default as part of the library. It's a config for one precompile so it shouldn't impact the configuration of the base EVM.

Also, once it's up and running how often will alternate KZGs be brought in? Do we really need configurability?

@@ -29,6 +31,8 @@ public class EvmOptions implements CLIOptions<EvmConfiguration> {
/** The constant JUMPDEST_CACHE_WEIGHT. */
public static final String JUMPDEST_CACHE_WEIGHT = "--Xevm-jumpdest-cache-weight-kb";

public static final String KZG_TRUSTED_SETUP_FILE_PATH = "--evm-kzg-trusted-setup-path";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be an --X option. Once the ceremony is done we will have the kzg embedded in the distribution, correct? So this is just transitional for testing?

jumpDestCacheWeightKilobytes, Optional.ofNullable(kzgTrustedSetupFilePath));
jumpDestCacheWeightKilobytes,
kzgTrustedSetupFilePath != null
? Optional.ofNullable(Path.of(kzgTrustedSetupFilePath))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a base level configuration option. This is the wrong place in code to do it. It should be an argument in the MainnetEVMs methods for relevant versions.

build.gradle Outdated
@@ -109,7 +109,7 @@ allprojects {
}
maven {
url 'https://artifacts.consensys.net/public/maven/maven/'
content { includeGroupByRegex('tech\\.pegasys\\..*') }
content { includeGroupByRegex('tech\\.pegasys.*') }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
content { includeGroupByRegex('tech\\.pegasys.*') }
content { includeGroupByRegex('tech\\.pegasys(\\..*)?') }

Removing the dot opens the door wide to uncontrolled DNS names like tech.pegasys-but-not-really:comprimised-kzg. Instead it should be listed as an optional section.

@@ -71,7 +71,8 @@ public class Address extends DelegatingBytes implements org.hyperledger.besu.plu
/** The constant BLS12_MAP_FP2_TO_G2. */
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x12);

/** The constant ZERO. */
public static final Address KZG_POINT_EVAL = Address.precompiled(0x14);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this address fixed already? Has BLS been "locked in" to those addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as i know it is, the specs have been stable on it.

Comment on lines 18 to 21
repositories {
maven { url "https://artifacts.consensys.net/public/maven/maven/" }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be needed here and should be removed. The repository is already enumerated in the parent build file.

@@ -54,6 +58,7 @@ dependencies {
implementation 'org.apache.tuweni:tuweni-concurrent'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.apache.tuweni:tuweni-rlp'
implementation 'tech.pegasys:jc-kzg-4844:0.1.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

Versions should not be listed in child build files. Please add an entry to <root>/gradle/versions.gradle

evm/build.gradle Outdated
Comment on lines 33 to 35
repositories {
maven { url "https://artifacts.consensys.net/public/maven/maven/" }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be here, the root gradle should cover this. If it doesn't it should be fixed there.

evm/build.gradle Outdated Show resolved Hide resolved
@jflo
Copy link
Contributor Author

jflo commented Jan 21, 2023

I don't like how the KZG files are being brought in. Especially if we already have hard-coded a default as part of the library. It's a config for one precompile so it shouldn't impact the configuration of the base EVM.

Also, once it's up and running how often will alternate KZGs be brought in? Do we really need configurability?

Yeah, the cart may be before the horse. I'm gonna remove configurability for interop, and we can add it back in if we actually discover a use case for it.

Signed-off-by: Justin Florentine <justin+github@florentine.us>
…ry load time

Signed-off-by: Justin Florentine <justin+github@florentine.us>
@jflo jflo requested a review from shemnon January 23, 2023 10:16
Signed-off-by: Justin Florentine <justin+github@florentine.us>
@jflo jflo enabled auto-merge (squash) January 23, 2023 12:59
@jflo jflo merged commit f8a0f87 into hyperledger:main Jan 23, 2023
@macfarla macfarla mentioned this pull request Jan 24, 2023
2 tasks
garyschulte pushed a commit to garyschulte/besu that referenced this pull request Jan 24, 2023
* KZG implementation

Signed-off-by: Justin Florentine <justin+github@florentine.us>
@alexandratran alexandratran removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Feb 1, 2023
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
* KZG implementation

Signed-off-by: Justin Florentine <justin+github@florentine.us>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* KZG implementation

Signed-off-by: Justin Florentine <justin+github@florentine.us>
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.

KZG point evaluation precompile
5 participants