Skip to content

Conversation

asanso
Copy link
Contributor

@asanso asanso commented Mar 15, 2024

ATTENTION: ERC-RELATED PULL REQUESTS NOW OCCUR IN ETHEREUM/ERCS

--

When opening a pull request to submit a new EIP, please use the suggested template: https://github.com/ethereum/EIPs/blob/master/eip-template.md

We have a GitHub bot that automatically merges some PRs. It will merge yours immediately if certain criteria are met:

  • The PR edits only existing draft PRs.
  • The build passes.
  • Your GitHub username or email address is listed in the 'author' header of all affected PRs, inside .
  • If matching on email address, the email address is the one publicly listed on your GitHub profile.

@asanso asanso requested a review from eth-bot as a code owner March 15, 2024 10:43
@github-actions github-actions bot added c-update Modifies an existing proposal s-review This EIP is in Review t-core labels Mar 15, 2024
@eth-bot
Copy link
Collaborator

eth-bot commented Mar 15, 2024

File EIPS/eip-2537fast_subgroup_checks.md.md

Requires 1 more reviewers from @axic, @g11tech, @gcolvin, @lightclient, @SamWilsn, @xinbenlv

@eth-bot eth-bot changed the title Rephrased subgroup check part Update EIP-2537: Rephrased subgroup check part Mar 15, 2024
@eth-bot eth-bot enabled auto-merge (squash) March 15, 2024 10:44
Copy link
Collaborator

@eth-bot eth-bot left a comment

Choose a reason for hiding this comment

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

All Reviewers Have Approved; Performing Automatic Merge...

@asanso
Copy link
Contributor Author

asanso commented Mar 15, 2024

@shamatar, @ineffectualproperty, @ralexstokes I rephrased a bit the subgroup check section including the fast subgroup check.
Once we are on it, I would like to continue the discussion started in #8274 (comment).
Namery IMHO we need to decide if to employ subgroup checks only for pairing or for all operations.
Thoughts ?

@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 15, 2024
Copy link
Collaborator

@eth-bot eth-bot left a comment

Choose a reason for hiding this comment

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

All Reviewers Have Approved; Performing Automatic Merge...

@shamatar
Copy link
Contributor

The nature of suggestion is great, but now phrasing mentioning double and add and subgroup check is misleading. If you just say that

  • one must check
  • one should use fast subgroup checks
  • default gas pricing assumes naive double-and-add multiplication

it'll be clear enough

@shamatar
Copy link
Contributor

Separately on mandatory checks: if no one found any use case when out of group elements are interesting for multiplication/addition then we can make subgroup checks mandatory iff fast subgroup checks are also mandatory. Of course, gas schedule will change, but most likely change will only be substantial for G1 add

eth-bot
eth-bot previously approved these changes Mar 17, 2024
Copy link
Collaborator

@eth-bot eth-bot left a comment

Choose a reason for hiding this comment

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

All Reviewers Have Approved; Performing Automatic Merge...

@asanso
Copy link
Contributor Author

asanso commented Mar 18, 2024

@shamatar thanks for the comment.

The nature of suggestion is great, but now phrasing mentioning double and add and subgroup check is misleading.

any suggestion on the words to use ? the "double-and-add" part was already present in the original text

auto-merge was automatically disabled March 21, 2024 12:22

Head branch was pushed to by a user without write access

@eth-bot eth-bot added the e-consensus Waiting on editor consensus label Mar 21, 2024
@github-actions github-actions bot removed the w-ci Waiting on CI to pass label Mar 21, 2024
@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 21, 2024
@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 22, 2024
@github-actions github-actions bot removed the w-ci Waiting on CI to pass label Mar 22, 2024
@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 22, 2024
@github-actions github-actions bot removed the w-ci Waiting on CI to pass label Mar 22, 2024
@asanso
Copy link
Contributor Author

asanso commented Mar 22, 2024

@shamatar I adjusted the text to include ALL the calls and added a new separate document (similar to the existing one for hash to curve) in https://github.com/asanso/EIPs/blob/patch-9/assets/eip-2537/fast_subgroup_checks.md .

Thoughts ? cc @ineffectualproperty @ralexstokes

@github-actions github-actions bot added the w-ci Waiting on CI to pass label Mar 22, 2024
Copy link

The commit 1f129eb (as a parent of 9271b4d) contains errors.
Please inspect the Run Summary for details.

@shamatar
Copy link
Contributor

Actually I found an example where we may need to allow out-of-main-subgroup points https://github.com/ethyla/bls12-381-hash-to-curve/blob/main/src/readable_Hash_to_curve.sol

@asanso
Copy link
Contributor Author

asanso commented Mar 27, 2024

@shamatar what exactly in that file?

@shamatar
Copy link
Contributor

It's a full hash-to-curve implementation (starting from byte string and then using field element -> curve point precompile). I'm checking how is map-to-curve specified now. If it clears a cofactor internally then such case would not be applicable, but as far as I remember it's not.

Full author's comment https://ethereum-magicians.org/t/eip-2537-bls12-precompile-discussion-thread/4187/60

@shamatar
Copy link
Contributor

At least my implementation clears a cofactor for fp-to-g1. Now checking the spec

@shamatar
Copy link
Contributor

Spec is also defined to clear a cofactor

@asanso
Copy link
Contributor Author

asanso commented Mar 27, 2024

So one reason more to work in the subgroup for all the operations correct ?

@shamatar
Copy link
Contributor

Kind of. I think original IETF draft for mapping to curve suggests to get two points, add them and then clear cofactor, that makes sense because clearing cofactor is amortized this way. But if we want to keep a number of exposed precompile function manageable, we can build-in those cofactor cleanups.

My only concern is at some point we will see a use case where secondary subgroup point is needed. Yes, it's hard to produce it in EVM because precompiles will give only main subgroup, but I do not claim a knowledge of all possible cases

@mratsim
Copy link
Contributor

mratsim commented Apr 10, 2024

I've also mentioned concerned about subgroup checks here: https://ethereum-magicians.org/t/eip-2537-bls12-precompile-discussion-thread/4187/63

The issue is that without them, libraries cannot use endomorphism acceleration or the result will be wrong. They might also not be able to use projective coordinates with complete formula (from Renes 2015), though Jacobian coordinates would work OK.

As mentioned in https://ethereum-magicians.org/t/eip-2537-bls12-precompile-discussion-thread/4187/66, there are 3 paths ahead:

  1. No change approach. no subgroup check, price like double-and-add and Pippenger today and add test vectors. For MSMs, in both Gnark and Constantine, endomorphism acceleration was not a problem or was even slower due to probably decomposition overhead + memory bandwidth / hardware cache limitations (at least on x86, Apple memory likely behaves differently).
  2. Misuse resistance approach. See @asanso, enforce subgroup check except on addition.
  3. Modular approach or performance approach, provide subgroup_check and clear_cofactor as separate primitives. People can cache subgroup_checks and ensure their cost is only paid once. Issue: they need to learn what a subgroup and cofactor is.

Some important point is that for large MSMs, endomorphism acceleration doesn't help, hence subgroup check cost is paid in vain. For single scalar mul, it represents about 1/3 (G1) and 1/5 (G2) more operations. (benchmarks in the link)

I do agree with @asanso that having them on all operations is reasonable due to the risk of some crypto libraries defaulting to endomorphism acceleration and outputting wrong result.

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

@mratsim
Copy link
Contributor

mratsim commented Apr 10, 2024

mratsim/constantine#368 (comment)

For @asanso on gas pricing

gas costs in ratio of G1 scalarmul image

original: https://gist.github.com/mratsim/6785a29e72865cfa94e1174fae1e1168 image

Reproduction

git clone https://github.com/mratsim/constantine
cd constantine
git checkout eip2537
CC=clang nimble bench_eip2537_subgroup_checks_impact

@asanso asanso closed this by deleting the head repository Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-update Modifies an existing proposal e-consensus Waiting on editor consensus s-review This EIP is in Review t-core w-ci Waiting on CI to pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants