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: Add EcPairing precompile #383

Merged
merged 11 commits into from
Apr 23, 2024
Merged

Conversation

jrchatruc
Copy link
Contributor

@jrchatruc jrchatruc commented Apr 19, 2024

What ❔

This PR adds the EcPairing precompile from https://github.com/lambdaclass/zksync_era_precompiles/, commit 4bdfebf831e21d58c5ba6945d4524763f1ef64d4.

Part of EVM-572

Why ❔

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

@jrchatruc jrchatruc changed the title Add EcPairing precompile feat: Add EcPairing precompile Apr 19, 2024
@jrchatruc jrchatruc marked this pull request as ready for review April 20, 2024 19:11
/// @param x The x coordinate of the point in Montgomery form.
/// @param y The y coordinate of the point in Montgomery form.
/// @return ret True if the point is on the curve, false otherwise.
function g1AffinePointIsOnCurve(x, y) -> ret {
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably mix of tabs/spaces, it looks weird in the github PR diff
image

Copy link
Contributor Author

@jrchatruc jrchatruc Apr 22, 2024

Choose a reason for hiding this comment

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

Fixed on this commit 99af881

@@ -3,120 +3,127 @@
"contractName": "AccountCodeStorage",
"bytecodePath": "artifacts-zk/contracts-preprocessed/AccountCodeStorage.sol/AccountCodeStorage.json",
"sourceCodePath": "contracts-preprocessed/AccountCodeStorage.sol",
"bytecodeHash": "0x01000075e8397f3d02eddfe166a8324a2ac31a6da0db8eeebfa8739d3f31aad6",
"sourceCodeHash": "0xfbf66e830201c4b7fda14f0ddf28a53beb7fbb48a8406392bcfd0ef7ea9265c8"
"bytecodeHash": "0x01000081df25f20524a83dc78040b54bdd50e97de2381e220757f07a56a9dd8b",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are there all these changes? did you use a different compiler version?

Copy link
Contributor Author

@jrchatruc jrchatruc Apr 22, 2024

Choose a reason for hiding this comment

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

It seems there was an issue in my environment, although the local setup (yarn sc build) is not working for me on this branch (i.e. dev), so it was hard for me to fix; something seems to be broken on the repo setup. I had to hardcode the path to my solc version 0.8.20 on the typescript code to get it to work properly.

The file is now fixed on commit ccae737 and only the new pairing hashes are added

@IAvecilla
Copy link
Contributor

The table below presents the gas usage reports for the ecpairing precompile, comparing its performance before and after all the optimizations suggested after the audit.

Test case Gas used with optimizations Gas used without optimizations
ecpairing_empty_data_insufficient_gas 65473 92281
ecpairing_one_point_with_g1_zero 1631296 943352
ecpairing_one_point_with_g2_zero 1410436 93092
ecpairing_empty_data 65473 92281
ecpairing_one_point_fail 3144003 3923454
ecpairing_one_point_insufficient_gas 3144003 3923454
ecpairing_fuzz_negative_1 3364750 3922908
ecpairing_three_point_fail_1 6616353 11584084
ecpairing_three_point_match_1 4880704 7753722
ecpairing_two_points_with_one_g2_zero 3144592 3924055
ecpairing_two_point_fail_2 4879413 7753925
ecpairing_two_point_fail_1 4879539 7754507
ecpairing_two_point_match_1 4879611 7754597
ecpairing_two_point_match_2 4879611 7754597
ecpairing_two_point_match_5 1631885 943953
ecpairing_two_point_match_4 4880115 7753121
ecpairing_two_point_match_3 4879959 7753409
ecpairing_fuzz_negative_2 4879761 4773613
ecpairing_two_point_oog 4879611 7754597
ecpairing_fuzz_negative_3 3140000 3923000
ecpairing_fuzz_negative_4 11824649 23077095
ecpairing_fuzz_positive_1 4879000 7753900
ecpairing_fuzz_positive_2 1411000 94300
ecpairing_fuzz_positive_3 2074194 2645074
ecpairing_fuzz_positive_4 8351577 15414267
ecpairing_fuzz_positive_5 10087461 19244012

IAvecilla and others added 2 commits April 23, 2024 17:04
@StanislavBreadless StanislavBreadless merged commit 467565d into dev Apr 23, 2024
22 checks passed
@StanislavBreadless StanislavBreadless deleted the add-pairing-precompile branch April 23, 2024 15:30
github-merge-queue bot pushed a commit to matter-labs/zksync-era that referenced this pull request Apr 23, 2024
## What ❔

Add `EcPairing` precompile to the system contracts list. This is
expected to be merged after the
[PR](matter-labs/era-contracts#383) adding the
`EcPairing` precompile implementation gets merged into `era-contracts`.
The address of the precompile corresponds to the one used in Ethereum
(`0x08`).

Part of EVM-572

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: Javier Chatruc <[email protected]>
github-merge-queue bot pushed a commit to matter-labs/zksync-era that referenced this pull request Apr 24, 2024
## What ❔

Add `EcPairing` precompile to the system contracts list. This is
expected to be merged after the
[PR](matter-labs/era-contracts#383) adding the
`EcPairing` precompile implementation gets merged into `era-contracts`.
The address of the precompile corresponds to the one used in Ethereum
(`0x08`).

Part of EVM-572

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
github-merge-queue bot pushed a commit to matter-labs/zksync-era that referenced this pull request Apr 24, 2024
## What ❔

Add `EcPairing` precompile to the system contracts list. This is
expected to be merged after the
[PR](matter-labs/era-contracts#383) adding the
`EcPairing` precompile implementation gets merged into `era-contracts`.
The address of the precompile corresponds to the one used in Ethereum
(`0x08`).

Part of EVM-572

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
github-merge-queue bot pushed a commit to matter-labs/zksync-era that referenced this pull request Apr 24, 2024
## What ❔

Add `EcPairing` precompile to the system contracts list. This is
expected to be merged after the
[PR](matter-labs/era-contracts#383) adding the
`EcPairing` precompile implementation gets merged into `era-contracts`.
The address of the precompile corresponds to the one used in Ethereum
(`0x08`).

Part of EVM-572

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
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.

5 participants