Skip to content

crypto/bn256: default to gnark #32024

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

Merged
merged 1 commit into from
Jun 16, 2025
Merged

crypto/bn256: default to gnark #32024

merged 1 commit into from
Jun 16, 2025

Conversation

kevaundray
Copy link
Contributor

No description provided.

@jwasinger jwasinger changed the title chore!: Use gnark instead of cloudflare crypto/bn256: default to Gnark Jun 13, 2025
@jwasinger
Copy link
Contributor

jwasinger commented Jun 13, 2025

Benchmarks of this PR on M2 MBP (arm):

BenchmarkPrecompiledBn256Add/chfast1-Gas=150-12         	  792328	      1463 ns/op	       150.0 gas/op	       102.5 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/chfast2-Gas=150-12         	  795624	      1482 ns/op	       150.0 gas/op	       101.2 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio1-Gas=150-12        	 4020206	       302.4 ns/op	       150.0 gas/op	       496.1 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio2-Gas=150-12        	 3812008	       318.1 ns/op	       150.0 gas/op	       471.6 mgas/s	     128 B/op       2 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio3-Gas=150-12        	 3670334	       317.8 ns/op	       150.0 gas/op	       471.9 mgas/s	     128 B/op       2 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio4-Gas=150-12        	 3609680	       331.8 ns/op	       150.0 gas/op	       452.1 mgas/s	     192 B/op       3 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio5-Gas=150-12        	 3991012	       298.7 ns/op	       150.0 gas/op	       502.1 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio6-Gas=150-12        	 3630218	       330.9 ns/op	       150.0 gas/op	       453.3 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio7-Gas=150-12        	 3614862	       329.3 ns/op	       150.0 gas/op	       455.6 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio8-Gas=150-12        	 3489369	       343.6 ns/op	       150.0 gas/op	       436.5 mgas/s	     128 B/op       2 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio9-Gas=150-12        	 3554090	       331.8 ns/op	       150.0 gas/op	       452.1 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio10-Gas=150-12       	 3640299	       329.8 ns/op	       150.0 gas/op	       454.8 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio11-Gas=150-12       	  766395	      1515 ns/op	       150.0 gas/op	        99.00 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio12-Gas=150-12       	  779530	      1518 ns/op	       150.0 gas/op	        98.81 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio13-Gas=150-12       	  801121	      1504 ns/op	       150.0 gas/op	        99.75 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio14-Gas=150-12       	 3757437	       317.2 ns/op	       150.0 gas/op	       472.8 mgas/s	      64 B/op       1 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast1-Gas=6000-12  	   62271	     19149 ns/op	      6000 gas/op	       313.3 mgas/s	     328 B/op       5 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast2-Gas=6000-12  	   33004	     36028 ns/op	      6000 gas/op	       166.5 mgas/s	     544 B/op       7 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast3-Gas=6000-12  	   33939	     35323 ns/op	      6000 gas/op	       169.8 mgas/s	     544 B/op       7 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio1-Gas=6000-12 	   31046	     38428 ns/op	      6000 gas/op	       156.1 mgas/s	     576 B/op       7 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio6-Gas=6000-12 	   31027	     38713 ns/op	      6000 gas/op	       155.0 mgas/s	     576 B/op       7 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio11-Gas=6000-12         	   30328	     38724 ns/op	      6000 gas/op	       154.9 mgas/s	     576 B/op	       7 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff1-Gas=113000-12             	    1407	    845678 ns/op	    113000 gas/op	       133.6 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff2-Gas=113000-12             	    1400	    842764 ns/op	    113000 gas/op	       134.1 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff3-Gas=113000-12             	    1377	    847719 ns/op	    113000 gas/op	       133.3 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff4-Gas=147000-12             	    1050	   1089662 ns/op	    147000 gas/op	       134.9 mgas/s	    2824 B/op	      21 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff5-Gas=147000-12             	    1095	   1091265 ns/op	    147000 gas/op	       134.7 mgas/s	    2824 B/op	      21 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff6-Gas=113000-12             	    1413	    866943 ns/op	    113000 gas/op	       130.3 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/empty_data-Gas=45000-12         	100000000	        11.21 ns/op	     45000 gas/op	   4014901 mgas/s	       0 B/op	       0 allocs/op
BenchmarkPrecompiledBn256Pairing/one_point-Gas=79000-12          	    1923	    597025 ns/op	     79000 gas/op	       132.3 mgas/s	     920 B/op	      11 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_2-Gas=113000-12 	    2392	    498038 ns/op	    113000 gas/op	       226.9 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_3-Gas=113000-12 	    1418	   1052368 ns/op	    113000 gas/op	       107.4 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_4-Gas=113000-12 	    1381	    858369 ns/op	    113000 gas/op	       131.6 mgas/s	    1856 B/op	      16 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_1-Gas=385000-12 	     540	   2189400 ns/op	    385000 gas/op	       175.8 mgas/s	    9664 B/op	      46 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_2-Gas=385000-12 	     453	   2686634 ns/op	    385000 gas/op	       143.3 mgas/s	    9664 B/op	      46 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_3-Gas=113000-12 	    1416	    868058 ns/op	    113000 gas/op	       130.2 mgas/s	    1856 B/op	      16 allocs/op

Benchmarks on master:

BenchmarkPrecompiledBn256Add/chfast1-Gas=150-12         	  172806	      6888 ns/op	       150.0 gas/op	        21.77 mgas/s	     768 B/op      14 allocs/op
BenchmarkPrecompiledBn256Add/chfast2-Gas=150-12         	  172438	      6938 ns/op	       150.0 gas/op	        21.61 mgas/s	     768 B/op      14 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio1-Gas=150-12        	 3203986	       367.0 ns/op	       150.0 gas/op	       408.7 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio2-Gas=150-12        	 3123658	       384.0 ns/op	       150.0 gas/op	       390.6 mgas/s	     672 B/op      10 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio3-Gas=150-12        	 3121344	       386.7 ns/op	       150.0 gas/op	       387.9 mgas/s	     672 B/op      10 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio4-Gas=150-12        	 2984788	       399.6 ns/op	       150.0 gas/op	       375.4 mgas/s	     736 B/op      11 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio5-Gas=150-12        	 3275545	       367.8 ns/op	       150.0 gas/op	       407.9 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio6-Gas=150-12        	 2454954	       487.9 ns/op	       150.0 gas/op	       307.4 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio7-Gas=150-12        	 2454031	       488.8 ns/op	       150.0 gas/op	       306.9 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio8-Gas=150-12        	 2388044	       514.3 ns/op	       150.0 gas/op	       291.6 mgas/s	     672 B/op      10 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio9-Gas=150-12        	 2436228	       511.0 ns/op	       150.0 gas/op	       293.5 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio10-Gas=150-12       	 2403188	       490.6 ns/op	       150.0 gas/op	       305.8 mgas/s	     608 B/op       9 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio11-Gas=150-12       	  171998	      6964 ns/op	       150.0 gas/op	        21.53 mgas/s	     768 B/op      14 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio12-Gas=150-12       	  171207	      7010 ns/op	       150.0 gas/op	        21.39 mgas/s	     768 B/op      14 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio13-Gas=150-12       	  168226	      7251 ns/op	       150.0 gas/op	        20.68 mgas/s	     768 B/op      14 allocs/op
BenchmarkPrecompiledBn256Add/cdetrio14-Gas=150-12       	 1366881	       848.6 ns/op	       150.0 gas/op	       176.8 mgas/s	     736 B/op      13 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast1-Gas=6000-12  	   24404	     48673 ns/op	      6000 gas/op	       123.3 mgas/s	    1280 B/op      25 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast2-Gas=6000-12  	   22874	     52393 ns/op	      6000 gas/op	       114.5 mgas/s	    1472 B/op      26 allocs/op
BenchmarkPrecompiledBn256ScalarMul/chfast3-Gas=6000-12  	   23649	     50233 ns/op	      6000 gas/op	       119.4 mgas/s	    1472 B/op      26 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio1-Gas=6000-12 	   22485	     57409 ns/op	      6000 gas/op	       104.5 mgas/s	    1504 B/op      26 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio6-Gas=6000-12 	   21655	     53060 ns/op	      6000 gas/op	       113.1 mgas/s	    1504 B/op      26 allocs/op
BenchmarkPrecompiledBn256ScalarMul/cdetrio11-Gas=6000-12         	   22491	     53986 ns/op	      6000 gas/op	       111.1 mgas/s	    1504 B/op	      26 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff1-Gas=113000-12             	     840	   1428096 ns/op	    113000 gas/op	        79.12 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff2-Gas=113000-12             	     834	   1429250 ns/op	    113000 gas/op	        79.05 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff3-Gas=113000-12             	     850	   1413788 ns/op	    113000 gas/op	        79.92 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff4-Gas=147000-12             	     639	   1888542 ns/op	    147000 gas/op	        77.83 mgas/s	  126561 B/op	    1158 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff5-Gas=147000-12             	     639	   1861790 ns/op	    147000 gas/op	        78.95 mgas/s	  126561 B/op	    1158 allocs/op
BenchmarkPrecompiledBn256Pairing/jeff6-Gas=113000-12             	     853	   1392420 ns/op	    113000 gas/op	        81.14 mgas/s	   84497 B/op	     773 allocs/op
BenchmarkPrecompiledBn256Pairing/empty_data-Gas=45000-12         	    2448	    464451 ns/op	     45000 gas/op	        96.88 mgas/s	     544 B/op	       6 allocs/op
BenchmarkPrecompiledBn256Pairing/one_point-Gas=79000-12          	    1240	    953811 ns/op	     79000 gas/op	        82.82 mgas/s	   42496 B/op	     389 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_2-Gas=113000-12 	     836	   1410534 ns/op	    113000 gas/op	        80.10 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_3-Gas=113000-12 	     837	   1421547 ns/op	    113000 gas/op	        79.48 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/two_point_match_4-Gas=113000-12 	     837	   1417557 ns/op	    113000 gas/op	        79.71 mgas/s	   84529 B/op	     774 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_1-Gas=385000-12 	     231	   5143678 ns/op	    385000 gas/op	        74.84 mgas/s	  420726 B/op	    3836 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_2-Gas=385000-12 	     230	   5297139 ns/op	    385000 gas/op	        72.67 mgas/s	  420727 B/op	    3836 allocs/op
BenchmarkPrecompiledBn256Pairing/ten_point_match_3-Gas=113000-12 	     840	   1424706 ns/op	    113000 gas/op	        79.31 mgas/s	   84529 B/op	     774 allocs/op

@jwasinger
Copy link
Contributor

this was merged in #32026

@MariusVanDerWijden
Copy link
Member

@jwasinger I only merged it into the performance branch, we should keep this PR to merge it into master

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM

@fjl fjl changed the title crypto/bn256: default to Gnark crypto/bn256: default to gnark Jun 16, 2025
@fjl fjl merged commit e0cf89e into ethereum:master Jun 16, 2025
5 of 6 checks passed
fjl added a commit that referenced this pull request Jun 16, 2025
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