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

evmmax: Implement ate pairing for bn254 curve #852

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

rodiazet
Copy link
Collaborator

@rodiazet rodiazet commented Mar 29, 2024

Implement optimized version of ecparing precompile in evmone according to EIP197 and based on High-Speed Software Implementation of the Optimal Ate Pairing over Barreto–Naehrig Curves

  • Adjust evmmax header to make possible use it's functions in constexpr initializers.`
  • Extend the interface with Jacobian caordinates point
  • Add template struct which implements basic logic for base and extension fields.
  • Add helper functions needed by the ate pairing.
  • Implement miller loop and final exponentiation.
  • Add unit tests and benchmark.
  • Enable the implementation to be used by state and blockchain tests

@rodiazet rodiazet force-pushed the ecpairing branch 4 times, most recently from 6cff817 to 82971ae Compare March 29, 2024 09:44
Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 99.82788% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.00%. Comparing base (d37b501) to head (ca5d8f3).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
test/precompiles_bench/precompiles_bench.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #852      +/-   ##
==========================================
- Coverage   94.21%   94.00%   -0.21%     
==========================================
  Files         149      154       +5     
  Lines       15927    16507     +580     
==========================================
+ Hits        15005    15517     +512     
- Misses        922      990      +68     
Flag Coverage Δ
eof_execution_spec_tests 16.90% <0.00%> (-0.62%) ⬇️
ethereum_tests 29.26% <93.28%> (+1.93%) ⬆️
ethereum_tests_silkpre 21.37% <91.40%> (+2.23%) ⬆️
execution_spec_tests 19.39% <1.72%> (-1.06%) ⬇️
unittests 89.22% <95.00%> (+0.21%) ⬆️

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

Files with missing lines Coverage Δ
lib/evmone_precompiles/ecc.hpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/bn254/fields.hpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/bn254/pairing.cpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/bn254/utils.hpp 100.00% <100.00%> (ø)
lib/evmone_precompiles/pairing/field_template.hpp 100.00% <100.00%> (ø)
test/state/precompiles.cpp 99.02% <100.00%> (+0.09%) ⬆️
test/unittests/evmmax_bn254_pairing_test.cpp 100.00% <100.00%> (ø)
test/precompiles_bench/precompiles_bench.cpp 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

@rodiazet rodiazet force-pushed the ecpairing branch 4 times, most recently from c339934 to 862c493 Compare April 2, 2024 11:17
@rodiazet rodiazet changed the title ate paring implementation for bn254 curve. implement ate pairing for bn254 curve. Apr 2, 2024
@rodiazet rodiazet requested a review from chfast April 2, 2024 11:31
@rodiazet rodiazet force-pushed the ecpairing branch 3 times, most recently from 5fc59bc to f734866 Compare April 2, 2024 13:15
@rodiazet rodiazet changed the title implement ate pairing for bn254 curve. EVMMAX: Implement ate pairing for bn254 curve. Apr 2, 2024
@rodiazet rodiazet changed the title EVMMAX: Implement ate pairing for bn254 curve. evmmax: Implement ate pairing for bn254 curve. Apr 2, 2024
@chfast chfast changed the title evmmax: Implement ate pairing for bn254 curve. evmmax: Implement ate pairing for bn254 curve Apr 3, 2024
@chfast
Copy link
Member

chfast commented Apr 3, 2024

Benchmarks

Laptop, Skylake CPU, clang-18

-----------------------------------------------------------------------------------------------------------------
Benchmark                                                       Time             CPU   Iterations UserCounters...
-----------------------------------------------------------------------------------------------------------------
precompile<PrecompileId::ecpairing, evmmax_cpp>_mean      3062286 ns      3062130 ns           10 gas_rate=50.2268M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, evmmax_cpp>_median    3060822 ns      3060713 ns           10 gas_rate=50.2497M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, evmmax_cpp>_stddev       8425 ns         8342 ns           10 gas_rate=136.436k/s gas_used=0
precompile<PrecompileId::ecpairing, evmmax_cpp>_cv           0.28 %          0.27 %            10 gas_rate=0.27% gas_used=0.00%
precompile<PrecompileId::ecpairing, libff>_mean           7954828 ns      7954583 ns           10 gas_rate=19.3348M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_median         7951823 ns      7951512 ns           10 gas_rate=19.3422M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_stddev           12605 ns        12610 ns           10 gas_rate=30.5417k/s gas_used=0
precompile<PrecompileId::ecpairing, libff>_cv                0.16 %          0.16 %            10 gas_rate=0.16% gas_used=0.00%

Server, AMD Zen2, clang-17

-----------------------------------------------------------------------------------------------------------------                                 
Benchmark                                                       Time             CPU   Iterations UserCounters...                                 
-----------------------------------------------------------------------------------------------------------------                                 
precompile<PrecompileId::ecpairing, evmmax_cpp>_mean      2712678 ns      2712707 ns           10 gas_rate=56.6963M/s gas_used=1.538M             
precompile<PrecompileId::ecpairing, evmmax_cpp>_median    2711113 ns      2711130 ns           10 gas_rate=56.7291M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, evmmax_cpp>_stddev       4666 ns         4658 ns           10 gas_rate=97.1147k/s gas_used=0
precompile<PrecompileId::ecpairing, evmmax_cpp>_cv           0.17 %          0.17 %            10 gas_rate=0.17% gas_used=0.00%
precompile<PrecompileId::ecpairing, libff>_mean           6819915 ns      6820019 ns           10 gas_rate=22.5513M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_median         6818710 ns      6818875 ns           10 gas_rate=22.555M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_stddev            6235 ns         6216 ns           10 gas_rate=20.5344k/s gas_used=0
precompile<PrecompileId::ecpairing, libff>_cv                0.09 %          0.09 %            10 gas_rate=0.09% gas_used=0.00%

Laptop, MacBook Air (M1, 2020), Apple M1

-----------------------------------------------------------------------------------------------------------------
Benchmark                                                       Time             CPU   Iterations UserCounters...
-----------------------------------------------------------------------------------------------------------------
precompile<PrecompileId::ecpairing, evmmax_cpp>_mean      1823636 ns      1823622 ns           10 gas_rate=84.3376M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, evmmax_cpp>_median    1823583 ns      1823581 ns           10 gas_rate=84.3396M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, evmmax_cpp>_stddev        545 ns          535 ns           10 gas_rate=24.7387k/s gas_used=0
precompile<PrecompileId::ecpairing, evmmax_cpp>_cv           0.03 %          0.03 %            10 gas_rate=0.03% gas_used=0.00%
precompile<PrecompileId::ecpairing, libff>_mean           7068315 ns      7068244 ns           10 gas_rate=21.7593M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_median         7066558 ns      7066560 ns           10 gas_rate=21.7645M/s gas_used=1.538M
precompile<PrecompileId::ecpairing, libff>_stddev            6901 ns         6802 ns           10 gas_rate=20.9269k/s gas_used=0
precompile<PrecompileId::ecpairing, libff>_cv                0.10 %          0.10 %            10 gas_rate=0.10% gas_used=0.00%

include/evmmax/evmmax.hpp Outdated Show resolved Hide resolved
include/evmmax/evmmax.hpp Outdated Show resolved Hide resolved
include/evmmax/evmmax.hpp Outdated Show resolved Hide resolved
@chfast chfast added the precompiles Related to EVM precompiles label Jul 22, 2024
@rodiazet rodiazet force-pushed the ecpairing branch 3 times, most recently from b0ee25b to f24df4c Compare August 8, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
precompiles Related to EVM precompiles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants