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

Support EIP-2539 and EIP-3026 #1049

Merged
merged 6 commits into from
May 8, 2023

Conversation

hujw77
Copy link
Contributor

@hujw77 hujw77 commented May 5, 2023

Description

This PR implements EIP-2039 which defines BLS12-377 elliptic curve operations, and EIP-3026 which defines BW6-761 elliptic curve operations as precompiles.

Background

The ALC (accountable light client) design is based on the paper published by the Web3 Foundation. It presents an efficient method for utilizing SNARK to verify the aggregated public key of signers, while still holding those signers accountable. This approach greatly improves the speed and cost-effectiveness of proof generation.
To facilitate ALC from PoC to production ready. We implement EIP-2539 and EIP-3026 for substrate chains to verify apk-proof which is necessary for ALC.

This PR is also the important part of this grant.

Other changes

  • Support precompile failure test vectors.
  • Update broken shell.nix.

Tests

Test vectors are generated with https://github.com/hujw77/eip-test-gen.

TODO in next PR

  • EIP-3026 gas table is not decided yet.
  • Use host function after the PR.

sorpaas and others added 4 commits March 7, 2023 15:35
* Update shell.nix

* Read point from input

* Finish `BLS12377G1Add`

* Fix `BLS12377G1Add` output encode

* Finish `BLS12377G1Mul`

* Finish `BLS12377G1MultiExp`

* Finish `BLS12377G2Add`

* Finish `BLS12377G2Mul`

* Draft `eip-2539` implement

* Finish `BLS12377Pairing`

* Draft `eip-2539`

* Multiplication by the unnormalized scalar

* Rename serialize to write

* Test Cases

* Test Cases

* Rewrite read_fq

* Rename

* Doc and cleanup

* Tidy

* Tidy

* Tidy

* Only check point in subgroup for pairing

* Fmt

* Tests

* Typo

* Typo

* Fix conv

* Change err info

* Fmt

* EIP-2539 tests

* EIP-2539 tests

* Lint and test
* Update shell.nix

* G1Add and G1Mul

* G1MultiExp

* G2Add

* G2Mul and G2MultiExp

* Bw6Pairing

* EIP-3026 tests

* EIP-3026 failure tests

* Fix lint

* Lint

* Lint and test

* Comment

* Deps order
@hujw77 hujw77 requested a review from sorpaas as a code owner May 5, 2023 07:00
@boundless-forest
Copy link
Collaborator

@sorpaas Please take a reivew. See the grant for more information.

@sorpaas sorpaas merged commit 6afd9a4 into polkadot-evm:master May 8, 2023
@burdges
Copy link

burdges commented May 16, 2023

At present this would run in wasm on polkadot, yes? It'd be good if someone here glanced at paritytech/substrate#13031 and https://github.com/paritytech/ark-substrate or even reviewed them to checked that they'd support this properly.

@sorpaas
Copy link
Member

sorpaas commented May 16, 2023

Yeah this currently runs in wasm at this moment.

ashutoshvarma pushed a commit to AstarNetwork/frontier that referenced this pull request May 29, 2023
* Release branch polkadot-v0.9.38 (polkadot-evm#1015)

* EIP-2539 (#15)

* Update shell.nix

* Read point from input

* Finish `BLS12377G1Add`

* Fix `BLS12377G1Add` output encode

* Finish `BLS12377G1Mul`

* Finish `BLS12377G1MultiExp`

* Finish `BLS12377G2Add`

* Finish `BLS12377G2Mul`

* Draft `eip-2539` implement

* Finish `BLS12377Pairing`

* Draft `eip-2539`

* Multiplication by the unnormalized scalar

* Rename serialize to write

* Test Cases

* Test Cases

* Rewrite read_fq

* Rename

* Doc and cleanup

* Tidy

* Tidy

* Tidy

* Only check point in subgroup for pairing

* Fmt

* Tests

* Typo

* Typo

* Fix conv

* Change err info

* Fmt

* EIP-2539 tests

* EIP-2539 tests

* Lint and test

* EIP-3026  (#16)

* Update shell.nix

* G1Add and G1Mul

* G1MultiExp

* G2Add

* G2Mul and G2MultiExp

* Bw6Pairing

* EIP-3026 tests

* EIP-3026 failure tests

* Fix lint

* Lint

* Lint and test

* Comment

* Deps order

* Fmt

* Lint

---------

Co-authored-by: Wei Tang <wei@pacna.org>
ashutoshvarma pushed a commit to AstarNetwork/frontier that referenced this pull request Jun 8, 2023
* Release branch polkadot-v0.9.38 (polkadot-evm#1015)

* EIP-2539 (#15)

* Update shell.nix

* Read point from input

* Finish `BLS12377G1Add`

* Fix `BLS12377G1Add` output encode

* Finish `BLS12377G1Mul`

* Finish `BLS12377G1MultiExp`

* Finish `BLS12377G2Add`

* Finish `BLS12377G2Mul`

* Draft `eip-2539` implement

* Finish `BLS12377Pairing`

* Draft `eip-2539`

* Multiplication by the unnormalized scalar

* Rename serialize to write

* Test Cases

* Test Cases

* Rewrite read_fq

* Rename

* Doc and cleanup

* Tidy

* Tidy

* Tidy

* Only check point in subgroup for pairing

* Fmt

* Tests

* Typo

* Typo

* Fix conv

* Change err info

* Fmt

* EIP-2539 tests

* EIP-2539 tests

* Lint and test

* EIP-3026  (#16)

* Update shell.nix

* G1Add and G1Mul

* G1MultiExp

* G2Add

* G2Mul and G2MultiExp

* Bw6Pairing

* EIP-3026 tests

* EIP-3026 failure tests

* Fix lint

* Lint

* Lint and test

* Comment

* Deps order

* Fmt

* Lint

---------

Co-authored-by: Wei Tang <wei@pacna.org>
@boundless-forest boundless-forest deleted the echo/eips branch August 24, 2023 03:11
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.

4 participants