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: implement g1_mul #19

Merged
merged 10 commits into from
Mar 26, 2024
Merged

feat: implement g1_mul #19

merged 10 commits into from
Mar 26, 2024

Conversation

fgimenez
Copy link
Member

@fgimenez fgimenez commented Mar 21, 2024

Towards #11

Implements the BLS12_G1MUL precompile following the geth reference implementation. Includes tests based on test vectors from https://github.com/ethereum/go-ethereum/tree/ab49f228ad6f37ba78be66b34aa5fee740245f57/core/vm/testdata/precompiles

@fgimenez fgimenez force-pushed the fgimenez/eip2537-precompiles-g1-mul branch from df01c1b to 5b889a5 Compare March 22, 2024 17:06
@fgimenez fgimenez changed the base branch from fgimenez/eip2537-precompiles to main March 22, 2024 17:12
@fgimenez fgimenez added C-enhancement New feature or request A-precompile Related to an alphanet precompile labels Mar 22, 2024
@fgimenez fgimenez marked this pull request as ready for review March 22, 2024 17:30
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,

pending @Rjected, not too familiar with the point math -.-

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.

I have one small nit about using the builtin multiplication methods, although the current impl looks fine, especially since tests pass. The move to blst will also change all the API usage

Comment on lines +89 to +98
for byte in scalar0.into_iter().rev() {
for bit_index in 0..8 {
let bit = (byte >> bit_index) & 1;
if bit == 0x01 {
q = q.add(n);
}
n = n.double();
}
}
q
Copy link
Member

Choose a reason for hiding this comment

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

It looks like G1Projective implements multiply (and Mul<Scalar>), so we probably don't need to reimplement double-and-add

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, I started using the methods you mentioned but the results didn't match the test vectors. Finally ended up writing a direct translation of the method used in geth https://github.com/ethereum/go-ethereum/blob/master/crypto/bls12381/g1.go#L345-L356, with this everything is ok.

As you said, with the move to blst everything will change

Copy link
Member

Choose a reason for hiding this comment

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

indeed, I started using the methods you mentioned but the results didn't match the test vectors. Finally ended up writing a direct translation of the method used in geth https://github.com/ethereum/go-ethereum/blob/master/crypto/bls12381/g1.go#L345-L356, with this everything is ok.

As you said, with the move to blst everything will change

hmm, interesting, let's keep this as-is then, and see what happens after blst

@fgimenez fgimenez merged commit 2fa48b8 into main Mar 26, 2024
12 checks passed
@fgimenez fgimenez deleted the fgimenez/eip2537-precompiles-g1-mul branch April 6, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-precompile Related to an alphanet precompile C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants