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

Precompiled optimizations and ecrecover refactor #323

Closed
wants to merge 39 commits into from

Conversation

hecmas
Copy link
Contributor

@hecmas hecmas commented Jan 31, 2024

Contents

This PR contains the following significative optimizations:

Commit 718b4f5e5947:

  • ecMul.zkasm calls to ecAdd.zkasm now avoid unnecessary checks.
  • Added a new file doublePointBN254.zkasm to perform doublings.

Commit 586ca2067565:

  • ecMul.zkasm now does not use any binary to perform the scalar k reconstruction.
  • A new file bitwiseReconstruction.zkasm has been added to allow "fill in" the missing bits of a particular $256$-bit number.

Counters:

  • Added counters explicitly for ecAdd, ecMul and ecPairing.
  • Some files renaming, to be more consistent with the theory; e.g., instead of scalarMulBN254, we now use scalarMulFP2BN254 to put emphasy on the underlying finite field.
  • All scalar reconstructions have been optimized with the slogan: "focus on verifying, not computing".
  • Minor optimizations and reorganizations of the code.
  • A new function has been added to perform point scalar multiplication by $6 x^2$ directly, where $x$ is the BN254 generator parameter.

EcRecover Refactor: A complete refactor of the ecrecover folder has been done, along with some major optimizations to the double scalar multiplication needed for the public key recovery. See the PR for more details.

Commit 96c24911d introduces a significant improvement (in the sense of number of steps) of the dblScalarMulSecp256k1 function. In particular, in order to avoid using memory variables that are used to reconstruct the scalars, we use small registers RCX and HASHPOS for this end, which are reset every 32-bit cycle.

  • Importantly, the file sm_main_exec.js of the proverjs needs to be corrected, since the fe2n() function is incorrectly throwing an error when the small registers are larger than 31 bits.

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@hecmas hecmas marked this pull request as draft February 5, 2024 17:01
@hecmas hecmas removed the zkevm-pil2 label Feb 5, 2024
@hecmas
Copy link
Contributor Author

hecmas commented Feb 5, 2024

Splited between #327 and #328

@hecmas hecmas closed this Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant