Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f3348e3
Update eip-2537.md
asanso Mar 15, 2024
7ce436e
Update eip-2537.md
asanso Mar 15, 2024
af5f6e4
Update eip-2537.md
asanso Mar 15, 2024
537f0ef
Update eip-2537.md
asanso Mar 15, 2024
31454df
Create eip-2537fast_subgroup_checks.md
asanso Mar 21, 2024
7b704d0
Create fast_subgroup_checks.md
asanso Mar 21, 2024
c11b3b3
Update eip-2537.md
asanso Mar 21, 2024
dd5987d
Update fast_subgroup_checks.md
asanso Mar 21, 2024
81e93d8
Update fast_subgroup_checks.md
asanso Mar 21, 2024
b9c8588
Update eip-2537.md
asanso Mar 21, 2024
422f2d9
Update fast_subgroup_checks.md
asanso Mar 21, 2024
f18628d
Update fast_subgroup_checks.md
asanso Mar 21, 2024
0b7671a
Update fast_subgroup_checks.md
asanso Mar 21, 2024
4984aae
Update fast_subgroup_checks.md
asanso Mar 21, 2024
b0007e7
Update fast_subgroup_checks.md
asanso Mar 21, 2024
a4ee4db
Update fast_subgroup_checks.md
asanso Mar 21, 2024
53f91fe
Update fast_subgroup_checks.md
asanso Mar 21, 2024
a3d6148
Update fast_subgroup_checks.md
asanso Mar 21, 2024
b4ee65c
Update fast_subgroup_checks.md
asanso Mar 21, 2024
9957dd2
Update fast_subgroup_checks.md
asanso Mar 21, 2024
c4a20a2
Update fast_subgroup_checks.md
asanso Mar 21, 2024
2ce1afc
Update field_to_curve.md
asanso Mar 21, 2024
b4d9621
Update fast_subgroup_checks.md
asanso Mar 21, 2024
ce2d83c
Update fast_subgroup_checks.md
asanso Mar 21, 2024
0752dfe
Update fast_subgroup_checks.md
asanso Mar 21, 2024
e352ed0
Update fast_subgroup_checks.md
asanso Mar 21, 2024
8961bcd
Update fast_subgroup_checks.md
asanso Mar 21, 2024
6907436
Update fast_subgroup_checks.md
asanso Mar 22, 2024
5a32513
Update fast_subgroup_checks.md
asanso Mar 22, 2024
2d6f7ef
Update fast_subgroup_checks.md
asanso Mar 22, 2024
e6e3134
Update fast_subgroup_checks.md
asanso Mar 22, 2024
c872f8b
Update fast_subgroup_checks.md
asanso Mar 22, 2024
300ded6
Update fast_subgroup_checks.md
asanso Mar 22, 2024
197e88c
Update fast_subgroup_checks.md
asanso Mar 22, 2024
ebed2da
Update fast_subgroup_checks.md
asanso Mar 22, 2024
6d89b6c
Update fast_subgroup_checks.md
asanso Mar 22, 2024
82ff6a6
Update fast_subgroup_checks.md
asanso Mar 22, 2024
5ec74e9
Update fast_subgroup_checks.md
asanso Mar 22, 2024
104c2d4
Update fast_subgroup_checks.md
asanso Mar 22, 2024
453fe8c
Update fast_subgroup_checks.md
asanso Mar 22, 2024
2b0a144
Update fast_subgroup_checks.md
asanso Mar 22, 2024
fc09b50
Update fast_subgroup_checks.md
asanso Mar 22, 2024
229e523
Update eip-2537.md
asanso Mar 22, 2024
1f129eb
Update fast_subgroup_checks.md
asanso Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions EIPS/eip-2537.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,14 @@ There are no backward compatibility questions.

### Subgroup checks

A subgroup check **is mandatory** during the pairing call. Implementations *should* use fast subgroup checks: at the time of writing, multiplication gas cost is based on the `double-and-add` multiplication method that has a clear "worst case" (all bits are equal to one). For pairing operations, it is expected that implementations use faster subgroup checks, e.g. by using the wNAF multiplication method for elliptic curves that is ~ `40%` cheaper with windows size equal to 4. (Tested empirically. Savings are due to lower hamming weight of the group order and even lower hamming weight for wNAF. Concretely, subgroup check for both G1 and G2 points in a pair are around `35000` combined).

The check **is mandatory** during **ALL** the calls. Implementations *should* use fast subgroup checks. It can be stated that it **must** be performed by fast subgroup checks to achieve a speedup, resulting in a discount over naive implementations based on the `double-and-add` multiplication method, which has a clear "worst-case" scenario where all bits are equal to one.
Before accepting an input, it is recommended to subject the input to the appropriate endomorphism test as described in https://eprint.iacr.org/2021/1130.pdf.
Copy link
Contributor

Choose a reason for hiding this comment

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

MUST perform a subgroup check, and reject invalid point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mratsim what do you mean? is there anything wrong with this part of the text ?

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, in RFC MUST is the way to specify that something is mandatory, and the spec should explicitly mention that it returns as an error on failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mratsim Is the problem the capitalization of 'must' rather than using lowercase? Or am I missing something else? :)

Copy link
Contributor

@mratsim mratsim Apr 14, 2024

Choose a reason for hiding this comment

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

To be clear, I have 2 issues:

  1. Instead of is mandatory: "scalar multiplications, MSMs and pairings MUST perform a subgroup check. Implementations SHOULD use the fast subgroup check method from 2021/1130 detailed in <link to fast subgroupcheck markdown file>"
  2. "On inputs that fail the subgroup check the precompile MUST return an error."

Rationale:

  • MUST is how mandatory steps are usually specified. I added details since EC add and hashing-to-curve do not have subgroup checks. And now we have a dedicated document for fast subgroup-checks.
  • Similar to the paragraph on Field elements encoding with "On inputs that can not be a valid encodings of field elements the precompile must return an error.", it's important to spell what happens on failure or people have to look at the implementations to make sure. For example what if for MSM, the offending point and its corresponding coefficient were skipped?

I can make a PR to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make a PR to this PR.

@mratsim this would be great.
One you are on it I everyone agrees you can already to the PR to this PR with this strategy:

  1. Misuse resistance approach. See @asanso, enforce subgroup check except on addition.

assuming @shamatar @ralexstokes @ineffectualproperty agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shamatar @ralexstokes @ineffectualproperty #8456 got merged with :

Misuse resistance approach. See @asanso, enforce subgroup check except on addition.

Unless you want me to revert it , this is what the status quo is


The algorithms and set of parameters for fast subgroup checks are provided by a separate [document](../assets/eip-2537/fast_subgroup_checks.md)

### Field to curve mapping

Algorithms and set of parameters for SWU mapping method is provided by a separate [document](../assets/eip-2537/field_to_curve.md)
The algorithms and set of parameters for SWU mapping method are provided by a separate [document](../assets/eip-2537/field_to_curve.md)

## Test Cases

Expand Down
51 changes: 51 additions & 0 deletions assets/eip-2537/fast_subgroup_checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Fast subgroup checks used by EIP 2537

### Fields and Groups

Field Fp is defined as the finite field of size `p` with elements represented as integers between 0 and p-1 (both inclusive).

Field Fp2 is defined as `Fp[X]/(X^2-nr2)` with elements `el = c0 + c1 * v`, where `v` is the formal square root of `nr2` represented as integer pairs `(c0,c1)`.

Group G1 is defined as a set of Fp pairs (points) `(x,y)` such that either `(x,y)` is `(0,0)` or `x,y` satisfy the curve Fp equation.

Group G2 is defined as a set of Fp2 pairs (points) `(x',y')` such that either `(x,y)` is `(0,0)` or `(x',y')` satisfy the curve Fp2 equation.

## Curve parameters

The set of parameters used by fast subgroup checks:

```
|x| (seed) = 15132376222941642752
x is negative = true
Cube root of unity modulo p - Beta = 793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350
r = 4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437 * v
s = 2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530 + 1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257 * v
```

## Helper function to compute the conjugate over Fp2 - `conjugate`

`conjugate(c0 + c1 * v) := c0 - c1 * v`

## G1 endomorphism - `phi`

The endomorphism `phi` transform the point from `(x,y)` to `(Beta*x,y)` where `Beta` is a precomputed cube root of unity modulo `p` given above in parameters sections:

`phi((x,y)) := (Beta*x,y)`

## G2 endomorphism - `psi`

`psi((x,y)) := (conjugate(x)*r,conjugate(y)*s)`

# The G1 case

Before accepting a point `P` as input that purports to be a member of G1 subject the input to the following endomorphism test: `phi(P) + x^2*P = 0`


# The G2 case

Before accepting a point `P` as input that purports to be a member of G2 subject the input to the following endomorphism test: `psi(P) + x*P = 0`

# Resources

* https://eprint.iacr.org/2021/1130.pdf, sec.4
* https://eprint.iacr.org/2022/352.pdf, sec. 4.2
6 changes: 5 additions & 1 deletion assets/eip-2537/field_to_curve.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,8 @@ The constants used to compute y\_den are as follows:

- k\_(4,0) = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb + 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb * I
- k\_(4,1) = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3 * I
- k\_(4,2) = 0x12 + 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99 * I
- k\_(4,2) = 0x12 + 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99 * I

# Resources

* https://eprint.iacr.org/2019/403
1 change: 1 addition & 0 deletions assets/eip-2537fast_subgroup_checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@