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

feat: bls12-381 g1_add precompile #17

Merged
merged 18 commits into from
Mar 22, 2024
Merged

Conversation

fgimenez
Copy link
Member

@fgimenez fgimenez commented Mar 15, 2024

Towards #11

Implements the BLS12_G1ADD precompile using the bls12_381 crate. This crate has been selected over blst because it exposes a much more ergonomic interface to be used from Rust code.

This implementation follows the spec at https://eips.ethereum.org/EIPS/eip-2537. Specifically, the logic takes into account the padding to specific lengths and the special encoding for the point of infinity as described here https://eips.ethereum.org/EIPS/eip-2537#point-of-infinity-encoding

It includes tests based on the test vectors defined for geth here https://github.com/ethereum/go-ethereum/blob/ab49f228ad6f37ba78be66b34aa5fee740245f57/core/vm/testdata/precompiles/blsG1Add.json for the happy path and here for the unhappy https://github.com/ethereum/go-ethereum/blob/ab49f228ad6f37ba78be66b34aa5fee740245f57/core/vm/testdata/precompiles/fail-blsG1Add.json (geth is one of the reference implementations cited in the spec https://eips.ethereum.org/EIPS/eip-2537#reference-implementation)

The PR also adds precompile functions for the rest of BLS12-381 precompiles still unimplemented, and includes all of them in the node.

@fgimenez fgimenez force-pushed the fgimenez/eip2537-precompiles branch 2 times, most recently from f9369a8 to 34d1b60 Compare March 15, 2024 16:13
@fgimenez fgimenez marked this pull request as ready for review March 19, 2024 12:03
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

mostly have nitpicks, this is a great start! some of the logic that uses subtle types was initially confusing but it makes sense given the bls library. The tests are great

crates/precompile/src/addresses.rs Show resolved Hide resolved
crates/precompile/src/bls12_381.rs Outdated Show resolved Hide resolved
crates/precompile/src/bls12_381.rs Outdated Show resolved Hide resolved
@fgimenez
Copy link
Member Author

mostly have nitpicks, this is a great start! some of the logic that uses subtle types was initially confusing but it makes sense given the bls library. The tests are great

cool thanks! ok, all the comments are addressed PTAL.

wrt to the submodule doc, do you think we could include #[deny(missing_docs)]?

@fgimenez fgimenez force-pushed the fgimenez/eip2537-precompiles branch from ab53503 to 21e3d06 Compare March 20, 2024 11:58
Copy link
Contributor

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

smol suggestion re blst precompile setup as a a function

Comment on lines 47 to 55
precompiles.inner.insert(BLS12_G1ADD.0, BLS12_G1ADD.1);
precompiles.inner.insert(BLS12_G1MUL.0, BLS12_G1MUL.1);
precompiles.inner.insert(BLS12_G1MULTIEXP.0, BLS12_G1MULTIEXP.1);
precompiles.inner.insert(BLS12_G2ADD.0, BLS12_G2ADD.1);
precompiles.inner.insert(BLS12_G2MUL.0, BLS12_G2MUL.1);
precompiles.inner.insert(BLS12_G2MULTIEXP.0, BLS12_G2MULTIEXP.1);
precompiles.inner.insert(BLS12_PAIRING.0, BLS12_PAIRING.1);
precompiles.inner.insert(BLS12_MAP_FP_TO_G1.0, BLS12_MAP_FP_TO_G1.1);
precompiles.inner.insert(BLS12_MAP_FP2_TO_G2.0, BLS12_MAP_FP2_TO_G2.1);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we extract this to a helper function, so this setup can be reused?

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 point, done here e008ab3 PTAL

Copy link
Member Author

Choose a reason for hiding this comment

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

@mattsse mattsse requested a review from Rjected March 20, 2024 18:07
@fgimenez fgimenez requested a review from mattsse March 20, 2024 21:14
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

Just one typo comment but this looks good to me now!

crates/precompile/src/bls12_381.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

@fgimenez fgimenez merged commit 2da4349 into main Mar 22, 2024
12 checks passed
@fgimenez fgimenez deleted the fgimenez/eip2537-precompiles branch March 22, 2024 17:13
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.

None yet

3 participants