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

Precompiles for BLS12-381 curve operations #9317

Merged
merged 245 commits into from
Jul 4, 2024

Conversation

olga24912
Copy link
Contributor

@olga24912 olga24912 commented Jul 17, 2023

Implementation for NEP-488: near/NEPs#488

Gas Estimation

The test vectors for gas estimation were taken from EIP-2537 and adopted for our input format: https://eips.ethereum.org/assets/eip-2537/bench_vectors

Command for gas estimation (from runtime/runtime-params-estimator/emu-cost folder):

cargo run --release --package runtime-params-estimator --all-features --bin runtime-params-estimator -- --home "./tmp_home_dir" --accounts-num 20000 --additional-accounts-num 200000 --iters 1 --warmup-iters 1 --containerize --metric icount

Gas Estimation results:

Bls12381MapFpToG1Base                                  420_103_750 gas [     3360.83i 0.00r 0.00w] UNCERTAIN (computed in 71.36s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381MapFpToG1Element                            83_940_185_431 gas [   671521.48i 0.00r 0.00w] UNCERTAIN (computed in 398.97s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381MapFp2ToG2Base                                 425_460_312 gas [     3403.68i 0.00r 0.00w] UNCERTAIN (computed in 25.86s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381MapFp2ToG2Element                          296_382_845_775 gas [  2371062.77i 0.00r 0.00w] UNCERTAIN (computed in 306.68s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381PairingBase                                703_330_359_812 gas [  5626642.88i 0.00r 0.00w] UNCERTAIN (computed in 92.34s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381PairingElement                             850_444_740_812 gas [  6803557.93i 0.00r 0.00w] UNCERTAIN (computed in 478.76s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P1SumBase                                    5_329_433_250 gas [    42635.47i 0.00r 0.00w] UNCERTAIN (computed in 27.68s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P1SumElement                                 1_952_367_105 gas [    15618.94i 0.00r 0.00w] UNCERTAIN (computed in 37.53s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P2SumBase                                    6_136_626_312 gas [    49093.01i 0.00r 0.00w] UNCERTAIN (computed in 27.79s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P2SumElement                                 4_920_333_450 gas [    39362.67i 0.00r 0.00w] UNCERTAIN (computed in 54.97s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381G1MultiexpBase                               5_323_237_875 gas [    42585.90i 0.00r 0.00w] UNCERTAIN (computed in 27.53s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381G1MultiexpElement                          303_497_441_743 gas [  2427979.53i 0.00r 0.00w] UNCERTAIN (computed in 1730.00s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381G2MultiexpBase                               6_120_231_625 gas [    48961.85i 0.00r 0.00w] UNCERTAIN (computed in 31.46s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381G2MultiexpElement                          662_703_174_257 gas [  5301625.39i 0.00r 0.00w] UNCERTAIN (computed in 3852.99s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P1DecompressBase                               429_739_937 gas [     3437.92i 0.00r 0.00w] UNCERTAIN (computed in 27.09s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P1DecompressElement                         26_855_436_628 gas [   214843.49i 0.00r 0.00w] UNCERTAIN (computed in 151.64s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P2DecompressBase                               400_538_375 gas [     3204.31i 0.00r 0.00w] UNCERTAIN (computed in 26.52s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24
Bls12381P2DecompressElement                         54_577_904_272 gas [   436623.23i 0.00r 0.00w] UNCERTAIN (computed in 264.86s) HIGH-VARIANCE: runtime/runtime-params-estimator/src/utils.rs:354:24

Copy link
Collaborator

@akhi3030 akhi3030 left a comment

Choose a reason for hiding this comment

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

Approving to unblock merging.

@olga24912
Copy link
Contributor Author

Overall LGTM on the idea! I mostly reviewed for code quality, assuming that the audit had reviewed security and correctness already; though I did notice a one-character but significant typo around gas costs.

It looks like some tests are also failing, so it’ll be something else to have a look at, though it’ll hopefully not be much work :)

@Ekleog-NEAR Thank you for your review! I have resolved all the comments. Let me know if you have any further comments.

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 75.41371% with 104 lines in your changes missing coverage. Please review.

Project coverage is 71.76%. Comparing base (5dadd93) to head (0c50335).

Files Patch % Lines
runtime/runtime-params-estimator/src/lib.rs 0.00% 59 Missing ⚠️
core/parameters/src/view.rs 68.42% 18 Missing ⚠️
...me-params-estimator/src/costs_to_runtime_config.rs 0.00% 18 Missing ⚠️
runtime/near-vm-runner/src/logic/bls12381.rs 98.35% 0 Missing and 4 partials ⚠️
runtime/near-vm-runner/src/logic/logic.rs 62.50% 0 Missing and 3 partials ⚠️
core/primitives-core/src/version.rs 0.00% 1 Missing ⚠️
runtime/near-vm-runner/src/logic/errors.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #9317    +/-   ##
========================================
  Coverage   71.75%   71.76%            
========================================
  Files         791      792     +1     
  Lines      161943   162366   +423     
  Branches   161943   162366   +423     
========================================
+ Hits       116202   116517   +315     
- Misses      40703    40801    +98     
- Partials     5038     5048    +10     
Flag Coverage Δ
backward-compatibility 0.23% <0.00%> (-0.01%) ⬇️
db-migration 0.23% <0.00%> (-0.01%) ⬇️
genesis-check 1.35% <0.00%> (-0.01%) ⬇️
integration-tests 37.88% <8.51%> (-0.08%) ⬇️
linux 71.40% <11.27%> (-0.16%) ⬇️
linux-nightly 71.33% <75.41%> (+<0.01%) ⬆️
macos 54.58% <100.00%> (+0.03%) ⬆️
pytests 1.58% <0.00%> (-0.01%) ⬇️
sanity-checks 1.38% <0.00%> (-0.01%) ⬇️
unittests 66.18% <75.41%> (+<0.01%) ⬆️
upgradability 0.28% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akhi3030 akhi3030 added this pull request to the merge queue Jul 4, 2024
Merged via the queue into near:master with commit 4e9e742 Jul 4, 2024
29 of 30 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Jul 22, 2024
…1818)

Stabilize NEP-488: Host Functions for BLS12-381 Curve Operations

* NEP-488: near/NEPs#488
* Implementation: #9317
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.

4 participants