This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
feat/#325 precomiple ecPairing #504
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b945f58
feat: ecc_circuit supports pairing
KimiWu123 bda702b
feat: add rlc copy constraint
KimiWu123 e5cc965
test: complete pairing testing
KimiWu123 f2f5d43
feat: add infinity check
KimiWu123 0edc604
feat: impl. precompile ecPairing
KimiWu123 0846653
test: complete ecPairing testing
KimiWu123 4a0c56a
doc: refinement
KimiWu123 b562ef5
doc: apply reviewer's feedback
KimiWu123 a22645c
Merge branch 'master' into feat/#325-ecPairing
KimiWu123 50a8a56
fix: reviewer's feedback
KimiWu123 043549e
test: fix return data len when invalid inputs
KimiWu123 5978ddc
fix: output of pairing result is not eq a successful call
KimiWu123 4bef7cf
test: fix output and success value
KimiWu123 547979c
test: fix testing data
KimiWu123 ded9863
test: remove is_succeess flag since it eq is_valid_data
KimiWu123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# ecPairing precompile | ||
|
||
## Procedure | ||
|
||
The `ecPairing` precompile computes the bilinear map between two given points in the groups G1 and G2, respectively, over the alt_bn128 curve. | ||
|
||
### Circuit behavior | ||
|
||
The input is arbitrarily many pairs of elliptic curve points. Each pair is given as a six 32-bytes values and is constructed as follows | ||
|
||
``` | ||
input[0; 31] (32 bytes): x1 | ||
input[32; 63] (32 bytes): y1 | ||
input[64; 95] (32 bytes): x2 | ||
input[96; 127] (32 bytes): y2 | ||
input[128; 159] (32 bytes): x3 (result) | ||
input[160; 191] (32 bytes): y3 (result) | ||
``` | ||
|
||
The first two 32-bytes values represent the first point (px, py) from group G1, the next four 32-bytes values represent the other point (qx, qy) from group G2. | ||
|
||
The bn254Pairing code first checks that a multiple of 6 elements have been sent, and then performs the pairings check(s). The check that is performed for two pairs is e(p1, q1) = e(-p2, q2) which is equivalent to the check e(p1, q1) * e(p2, q2) = 1. | ||
|
||
The output is 1 if all pairing checks were successful, otherwise it returns 0. | ||
|
||
``` | ||
input[0; 31] (32 bytes): success | ||
``` | ||
|
||
The pairing checks fail if not having a multiple of 6 32-bytes values or in the case of the points not being on the curve. In these cases all the provided gas is consumed. For these cases, the variable is_valid is set to 0. The variable output denotes whether the pairing checks were successful (in the case of is_valid = 1) | ||
### Gas cost | ||
|
||
1. A constant gas cost: 45,000 | ||
2. A dynamic gas cost: 34,000 * (len(data) / 192) | ||
|
||
If the input is not valid, all gas provided is consumed. | ||
|
||
## Constraints | ||
|
||
1. If the length of the input is not a multiple of 192 bytes | ||
- output is 0 | ||
2. If the input is empty which means it's a successful call, | ||
- `input_rlc` is zero | ||
- output is 1 | ||
3. `ecc_table` lookup | ||
4. If `is_valid` is false, | ||
- output is 0 | ||
- consume all the remaining gas | ||
|
||
## Code | ||
|
||
Please refer to `src/zkevm_specs/evm_circuit/execution/precompiles/ec_pairing.py`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[96: 128] is a wrong range which is 33 bytes. 😄