Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: MixMAx123 on November 16, 2019, 07:52:32 PM



Title: Presentation of my ECC Calculator
Post by: MixMAx123 on November 16, 2019, 07:52:32 PM
Here I would like to introduce my little ECC calculator
https://github.com/MrMaxweII/Secp256k1-Calculator/blob/master/README.md

https://user-images.githubusercontent.com/34688939/68996640-257c1d00-089d-11ea-960b-4a55e3ef7781.png

Secp256k1-Calculator

A small calculator of operations calculated on the elliptic curve Secp256k1.
All entered in hexa decimal numbers.
All calculations are done mod (p).
Same numbers are marked in color.
following arithmetic operations are implemented:

   - mod(n) addition, subtraction, multiplication and division of 256bit hexadecimal numbers.
   - addition and subtraction of points on the curve.
   - Multiplication with a point on the curve
   - Divide a point on the curve with a number
   - ECDSA Signature
   - ECDSA verification




Title: Re: Presentation of my ECC Calculator
Post by: charlie137 on November 19, 2019, 04:28:07 PM
very smooth solution!! sry no merit https://www.blockchain.com/btc/tx/3eda977b908fcdd8962794be6b48f8f07fa988a56b275b39919d6efd6e3342c3


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on November 19, 2019, 06:10:19 PM
Thank you very much Charlie137  :-*

Have you (or anyone else) tested / compared everything?
In particular, the signature is difficult to compare with a reverence program, since always the "k" (random number) is different.


Title: Re: Presentation of my ECC Calculator
Post by: bytcoin on February 15, 2020, 10:37:12 PM
Here I would like to introduce my little ECC calculator
https://github.com/MrMaxweII/Secp256k1-Calculator/blob/master/README.md

https://user-images.githubusercontent.com/34688939/68996640-257c1d00-089d-11ea-960b-4a55e3ef7781.png

Secp256k1-Calculator

A small calculator of operations calculated on the elliptic curve Secp256k1.
All entered in hexa decimal numbers.
All calculations are done mod (p).
Same numbers are marked in color.
following arithmetic operations are implemented:

   - mod(n) addition, subtraction, multiplication and division of 256bit hexadecimal numbers.
   - addition and subtraction of points on the curve.
   - Multiplication with a point on the curve
   - Divide a point on the curve with a number
   - ECDSA Signature
   - ECDSA verification



I used and liked it ... very good tool


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on February 16, 2020, 09:32:57 AM
Thank you very much.
If you have any requests, improvements or comments. Just ask! I would be happy to extend it.


Title: Re: Presentation of my ECC Calculator
Post by: MrFreeDragon on April 11, 2020, 01:28:31 AM
Nice idea and realization!

What libriary do you use to perform scalar multiplication and division (multiplication by inverse scalar). The multiplication and division is calculated very slow.... like 10-20 seconds for one operation. However one operation should be performed immediately i beleive.
Points addition/division is also made no immediately but with some 1-2 seconds freeze.

My python code performs 120-140 scalar multiplications per second on the same machine (faster by 1.5k times). So, no need to calculate just one operation for 10-20 seconds. For python I use gmpy2 C based library. Not sure which one should you use for Java.

If you improve the productivity it would be great


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 12, 2020, 04:23:49 PM
My python code performs 120-140 scalar multiplications per second on the same machine (faster by 1.5k times). So, no need to calculate just one operation for 10-20 seconds. For python I use gmpy2 C based library. Not sure which one should you use for Java.

I have a python code that performs over 4300 scalar multiplications per second (about 2800 if I don't use the invert function from gmpy2).

this is a file "privatekeys.txt" with 10k private key randomly generated:

Code:
1AD2C071915A20CE95C8D837E46F40D2A9BB40E15211762CD870A9EC24FD5DCF
A50154B9DEFAC142389432B7B97E5E3205E5059F46F3A8E4A54AB4C4F37103D4
C2A3427EDEE65A6E55E5351569B73D6448E112A8E8FAE3A42361E6DB1F577301
1DE7392790C5991340A36C083F39F7790A3DAF7AD62ECF7E2562623FDA0EC02D
5A2AD7B410A5C36B92DD57EEEFEAACEFAF221799321CBFC0E3CDB540E68BB143
5394DEA7AFBC9D7ACC681E1CACEB910B80F4270640986FFEF45720FD77DDDA03
64516A0F85BB18E75EF5EFD7AEC5929036601571A8755B9A3CE73EA9442894D5
E79FBF28CE7C581765BCC547B438F4C125ABEB8D1695ECBEC943CB1EAED95E2A
66373691273764AF0ECA57B766B4944F026E9491F263A9B7F89A729BC3F9E267
99A0204812703736DBFF2DBC5588891DEADB990ABA50DD81A6FACFE852683FB2
886EB68EF4FC81176356046AABCFC2BEC693AF9DC2D3DFB41BF9A8958470F9B2
AD79EE6AA11BE610DFA83B359CCC331B296AF79F8DF1BF898E5606D9A0C5A352
24835D92C7AE06338E1A2967344E93C2E64BD94D04608BCEDA3BC58D2AE23128
79CFDFC3B8424A892501F3F2154B0B0BDFE0C072940C11A48E06D0610DCB410F
BB61CE1DEA8067405CC8BD1DAB85E121E65EE52122CAFEB36FD5C6771F6E4A01
B448D08CD188ABA800E4AD49CDDD2CD2A5526EABFA274A18E26B8CA985CB84FB
F1794E3C951AC53EE737E2E821AC661751C1A12446C9654CCA3155769D4DC93A
35391EF096CC397AFC14866F89A9D4D25B3FB7B26D52784F702FB92B26EA4340
D9015CBC66ED22CB7F922F0A9255B31A2ADCAF8C7D5404A50F7D99E883D6F468
D8458384595BFF6582F81AC1E0E201D41083954D1BDEC92E85D2AB05AE4EA560
003BEDA0948482FF179736214B1B1A53AF497C5FC898A49697067AD1C62B058B
7EF17EBE250E148D0E976206A92987B1DFC27CCF9E2D2A27699FA2F218032CE6
6EF9AD9C56C24CF1E9A4D1E86736C1D1CADA43F2BCCF61DCB3A96FF9577A17A0
4AC48D9A3D7608AFE55C649D2DBB4877A675B2FF882973D1E007DFC67EB72EF9
C62B6EAC78A0332FC608E5A175451310FA56E7C4C1E743ABBD868065F125DD4D
7E6541FDDC39B0731867444A06DF05B9FC469DD4FF8984B9FEB4EE36F4FAC157
F84B10C33CCA40CAC91FA6AFF46109B5802887B84995EF6E85A0BC64BDEF9223
052E1CF8F8847DFADA8211FD317326D6FAECBF70A63CF4CCE6C0891E02B6CFDC
8DB495FEF9382AA17CD5C8DAC0B541A78D34BA9CE01757340CBCCE3CBCECF986
476C4C338391F4774050AB190B97319FE76751F8BFE0ACD6CE316E12168EF166
F6CC9C7991F8C169CD048B92AD37BD54B0C88BEEDAF5418723E33EE13366912F
64D727900FDA42C31635FAD1614949220437E7A7A05981A55ABFE589C04C2F8C
9D60108B7F6D00AA44CE32A7A8030A85228DC43C3D2443DF6E1792E26C5CAAC4
4AF919E499348D445D8125257FFDE369D87C1A9C2C1F45AED5D7F4EB93401371
2D68E4F0F5ED706FC0B30FD593578B471C1ED555A4EA610052B0F804FF7A4782
3406379F4773FCEF0DF5A7CDD44B500F3AF0F444E39BE07E89A47DFC4A8C11B8
E0B82F93B829AC7ABB41F8D5671903946FDCE540F05575EAEC9483B5DFABCD2E
821F9AD9D8D93C594294EB282F3ABA27775E37D8D69A8DDF9E1AC738889E27DE
0DE807C445995319711721E107C06010ADC4B854706EDF3D017B4CB2D002020E
0AF4B0F89DDA027E5F30B1B18C1F19ACE234734DDFAD91CA6BAEE1DBECBFCED9
3E66FAB721CE35E63030F57266E0E075684CDCED1F87315ADEF9D308C3004B51
3DA4B269035A6796F6F2DC1A0CED3C6A53545B625A8586A30E39C7489BE18CC1
56EC6611EFD360E78AAF25BBD5DBA9C015EF2B707AAEAA0A7B689D2D1E874684
284394C49EA753C5FC9041D7B84533FF011209983EB5B1B0FC53C6643BE609D4
966CD577CCB6BFEA79DAF198F78DCC203F95D837CB47F04D5848E0D524250857
34D5E3E76CF980739B68A606C627E6A9EF1EDD0FBBC0C0E40B620C5C40E7B166
410C060332C41B46513A25A9993BC63F7CA839B07891FDFD846DCD228711D5D3
9C35A4392BB7C1A3ECB411A7C8E8E44FFF59084B5B76346F134F96D42A743B8A
3B9AEB8733677E8A376E6420F8234116676635FC49471FC9A476E1CF90D96D1C
B7CA915833FB4BCA8C7C27903ECCD82291D0A8FEC85A286AE849D73D1DDA2AC4
C1A3D503EB04F5F251213B4D672DF4009D2932C89922C3E46A21A431B7469197
249595B3730803216F1731B920663F8256747C78A374BA7A59BEFD3BEFAF4763
D360CAEC986DF1C6A383F979E389BDE63923ACA33C9DEB3AE9FE6B95DCD5B31F
67CF3E287447ACE96F40EE255E493E5369060D06F21DF6B8D24A47302161A27D
EC3F11E7DF34890DA6548C18731F1FA515FA7C9844C49C763C93BB4CC6616918
174DB4E368A2B9F3B3602AA644253E2B599E91BB160CE88F26A15DF996A77D2E
4A2C1F24263FF268B0AC058A11609292BB1DA48CF1F43B8CDB4F2FF298564D0B
B8F6B32179073E75A827CF30C9A0EF95EEECFB2F36136CB478420B3E484CAE52
19A040D5F524491902ED25609424A53BDF53B62959CAAA05471F009A9B0C6B02
179A0AD82E47B0A3C48DAD58A648726908937BD7962E305A60A272E330241DAF
7E981777557FB603666210A1B9693AE3571187DF7B1F770BC4C1E87C01ACFCAA
82C8718DE90205C944B6970ACBEB754EA65C7E6552616BB2E2D733A40647AFC9
63D79D058CAFECBEB956FAC2D1BF9A878C94E049D3A23111167FAA5BDDF965B6
3708F72A7B53E57E6C951AF217424FA063A420AB6F4C65B13AAD35B20F45D4AA
A30395D4093276476452ACB799C758B0615934DA94351278ED524664F6515112
AAD433AF01EB90C507B4F0797728AA3C8B3FFDC3B842148EE47483802824ED4C
4DB71304C304D01DD0E4C10953A4DC56A731A7D69809690F5D8D29897DF599E9
C35DE7EBB9755C13DE4D24D954F19E6A5056CE230281DBD18CBB3AFCFB2513D8
C9929CEB373CFD1DF4B976BD37C5C95DC17E8EFF809D4853E8433384CF72B7E1
3F5C93D9A423CA66A5112595AAA1641EB29990CC44C70582878BDBE7F9DD13EB
E73E58FBB6A258BDA0A3029C5BB525DF48783A1EB745A5D62E6E3B52ABEAFF28
05B1791C14EC00C48FF37C135D547B6C0A766148DDA304151F394EC8CACC9597
FFB898795DEBB1C529C09EF8CE752CD631FD9B8EB6748429AB36E5FEF2DEC57A
46FF2C3FD482B56215D5B083303404835A2870116251F790BF07F8EFF20E0438
8546FD16F1A6936891ACDBE707BD85540DED4152C981D7AF08B3A03F7F25EEF0
006DD4CC8B1D1B9A76A7E13B20C472C3AE54C6611ECB61BCC47C41A5A2F03919
FD30A34A000776017DB9A25747690C819C55EB1E45501255E7163169F27210B6
798923D42AE5C1F0694F054C176CED83C50AE7A7EA2BA215A963CEB4F46C37DA
000CE07A4654DE203D025AD61E773AE6B7BECB81826F04A51EDACE8E7EBED2DF
1D35302E72512228EDDAD6545ED606B0238C9E24488045EDE1F30131D8204A8F
30B18014A8968A54A0CD1CD6F6F60225D855320851D5DA719187DC779E0BE987
5D7D0DE407B3195CF5501B28EFBC2E05126AE4D0E7E2B53C001BB17386FD97A8
6C4A3F55FB2631C38FBAAB34D939811A51F5AB8F1405CDAB7F63395800809A59
D70737894CC290A18E1C392DEE0527CF86EAB8A0010605B48442C0ABB96D047E
1CEBF0333A270ED505C6973A9746D28F09F1F93921280F3BD98E544FA517C553
55CF106FA8654B2C91A07F64C14C6938A8A1E734940DB661E8C9A348BD4509D2
B2EBE6843A75AC5A06B7E2D3F11EA49AEF91860D33CEF127E347124773644A35
CFFC8E9996697B4FCFE3422281B239A13C5E29A4E3F19741D3F55949D0533E44
CF9C8792AFAD077E26294E4E14E4D1A1130AC2465F7E2C940291BF679773DC36
51DC778D8A05524E21C955BA2AE05BE56A0020908042C11C91485B1A7CECA541
A7F4A36C49CD728307DE7114A2EB620F8CE1B09E7753631A037A8E44466BC678
3A7FC3821624B3EDE54C5F7B87B15EBFDD9A34DB7EF7EF22A69E46F3AE9B7240
0DD3BD18CDFF53B214EBFCDC9F972744D357DAB7E154C5202870397007923440
6FCA181395F9E35FD9EDCC43FE10FF140FF690F33AAE417B4FD4C366B42ED65D
C49DAFBC61ED7FEE0F7D6B9648F622948725047E3E62EE2D7F73C65148898B2D
83B4341FD7A7B408C8B46ED3ED2A44B040B7DB06173AB54B32FA065D3A0B6344
6165584383E73BDF6FB55D18B4C3CE31F22DC6A4B78B2EBD2F773E3606D308AD
79ADCD836A229917B5F59B35BCEB7EA8BA39086409A10BB9FC7540315CD3D1BF
4374E571066619EA06C98F92C55A2D864A5104F53817C8A7C5F4B2993067D826
66835054F9194331EDDAB433B3390D8CB15CEA4D33923A69F747C4BF7E3EE82A
4AC399441D2779D855C2D32996FD455D0388BDF4E77C4BC55877FDC5D6731EBD
2BCA19265837C2FBB5C4C0CB698F30F98CB3A97CCE6206C844F43497908F9D0D
9C25488B4799BA50843B945DF234DE575F79A0A7ECDD91714F47E2F25C388F9A
101A04DD02389204C51EA7794DA9B025FBE05690906E1C2BDF665FF433EBFF17
7E868C3EEE061303727771167E0A67BD486ABDBDF5CD7736758A1F9F7022925F
B91D170BAC8CBAB1E59644CAB1F8D5724CF11C5DC0B8F36AEDCB8668FECBDC18
435BE1E7CEAD4B54B9944D96EC596D2CFC993EF31412664F057104DD359E740C
4C0DF007BB660C495EA0A05379B32C64B6DEF49D06F6B8574002E18E26C63D45
155D831875E283285F47AE1F50DB9FBD77D89C1EB8600A7BD5EA420E22C696A0
...

and with my script "private_to_publickeys.py " I get:

Code:
$ time python3 private_to_publickeys.py privatekeys.txt > publickeys.txt

real 0m2,292s
user 0m2,288s
sys 0m0,000s


$ less publickeys.txt

744375d976381191832c869d7ec34d838ed953cc87289cfa3299d2d7b4fcf2f5 072494d19739cd2b501e9266dbdfe2faf3964aca63995ae6859aed5e7c32b841
e7fdd9a3e62a29a146a52950f9d8cdea45d8d3d6cfea771578de5b3e6af88397 b62ec1da84db4f01a63efba89449863073f7811f6ab8ee02ea5345164be0aefd
956094120bc30cb30c3b0ba48b6d39e4a6da1b659284a85d9ca63ce39152b87e 09cfa90f960f8eeefa990900b25071c14477ff23faeea90e3ff4920993756a20
6300782460c79cf882ad80625541ad1b447c3949f4f2024135f12b66787222ec 99040131e14e1a203a3c196029e167560c4a4d7adf96bebe44704783eab8992b
498a062de88480b4c92c6428a40746bb255fb0effe1f7747b40677acd61046fd 965c8b9ea7e570b2493a17bb1b8257c1108b79343e93ea04292caacd0108f27c
6f645b62eaab5b4c7a802e4dea34a582becfea71c416b5295512be857ed59ac5 da9a2b2313f7cf0433220a6dac3cea8e2c845f6e2d2e6deed95cfda123fc6ead
42f06ce7db698ddc88f56a14b20a0b26aa5dd5c1e16e469bd785335c1e5e069e 227b99f66a90b71bc4c6fcc5b28ac59d23d6e3b0a16e49b72d508df21f4ed60d
079b04bdadc1051cfd50c8f67f0d18ccb9acf820dc1cd138e3edf50250a9c7fb 6298ac5a0e4d49fd21687f9b905cfc1cfae56176a9730343fe35f289d3f14159
29d280573eda1c5673b0cb62433882e709fed34db76c4f8bc044f5bbc8b51e8e 4e70acaab32c2f86b0c57f019be80f298030265ed826912f4ef01b361af15243
d67effa474d640a84e6f21b8cf1b7c458a04b6236f4d5948930a613872f769e8 8087e7bc2cbcc955b0116589eec6716966fbf09e2321540c05223521bdcc4a17
9185115c0010a2a471710db2f269ceb071ddb712e6da9eccc38e1a408dd763d5 b8e6b276e6d92c7e7a7df3c36210a90ac0cec473f628697f5e7237ccdf475e45
958278eb1fd4b0a7764fa6fb70d0aba2a317ff5d4d19078d16556a135602d583 37a993fec4353fbd5dd40dabe21e3a3e8784d16f61e007cdc9070385f575a07c
c48fc46f1415b54e49545c886ac7bd8450c371311288609d020f2635bced79e7 36f96a7c124c6928e94872718b2fb1c9960c50e16c77faf9354e5ac0358c6dcb
3cc195dec1fcd55f2fcb7fe62810af3abd9411233068f86d689977808f0af021 266ad1e6d806950cebbd1dd8647ed2d9476152a9531fc52e7c0af0fe02afb1cc
0243e768b972040da69dc157ca78419cf474d2735db405e8113ddf197b827cfe e5fb095769d653521fe909502d8f1872d1246dd335c706e1ee877710605e18ee
17c1724ac9365013c9a815c394e82f5e769db685da1957540606532c229c249b 55d0163a2f263dee7a5d51d71847dde5889e6c41fa663b46210dc62b09e7d193
...

if I don't use gmpy2 at all I get instead:

Code:
$ time python3 private_to_publickeys.py privatekeys.txt > publickeys.txt

real 0m3,499s
user 0m3,488s
sys 0m0,008s


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 12, 2020, 05:19:27 PM
Nice idea and realization!

What libriary do you use to perform scalar multiplication and division (multiplication by inverse scalar). The multiplication and division is calculated very slow.... like 10-20 seconds for one operation. However one operation should be performed immediately i beleive.
Points addition/division is also made no immediately but with some 1-2 seconds freeze.

My python code performs 120-140 scalar multiplications per second on the same machine (faster by 1.5k times). So, no need to calculate just one operation for 10-20 seconds. For python I use gmpy2 C based library. Not sure which one should you use for Java.

If you improve the productivity it would be great

Thank you for the information and the feedback.
I think that's very good!

I use my self-written library Secp256k1: https://github.com/MrMaxweII/Secp256k1 (https://github.com/MrMaxweII/Secp256k1)
When it comes to calculating time, it makes a big difference whether you multiply by a known generator point or an unknown point on the curve.
If there is an unknown point on the elliptic curve, the algorithm is different and much slower.
I don't know anything about other python codes because I only program in Java. Surely there will be algorithms that are better or faster than mine. My code is not particularly performance, but the result is correct in the end. On a powerful PC, the calculation takes an average of 2 seconds.
This is not particularly fast, but I find it sufficient for this purpose in this calculator.
It is not the case that they use this calculator to carry out mass calculations one after the other. It is not made for such purposes. When it comes to speed, you shouldn't use my library.

I am sorry, for this reason, I do not think that I will invest a lot of time here to make the calculation faster.
If there was a great demand and no alternatives, it would be different.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 12, 2020, 05:29:26 PM
1) on my pc (Ubuntu 17.04) I get a windows too small; how to resize it?

2)
Scalar
653646536547337543

Vector
x
65366546543536537574373456456

If I click on the first 'y' I get '0', If I click on the second one I get 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', it is a bug?


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 12, 2020, 05:44:17 PM
An X coordinate "65366546543536537574373456456" is not on the SECP256k1 curve. So this is an input error.
If you enter coordinates explicitly, the points must lie on the curve.

I'm just starting my Ubuntu to test it there ...

So under Linux (Ubuntu) the font size is a bit larger, so that the input fields are a bit too short to display the whole number.
But the cursor can be moved in the input field with the arrow keys and the numbers then scroll to the right or left.
This at least enables input and output. Even if it's not nice, admittedly.
The GUI was created under Windows. There all fields are the right size. I'm sorry if it is different on Linux.
With my next update, I will improve that.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 12, 2020, 05:51:03 PM
I'm just starting my Ubuntu to test it there ...

My PC Lenovo has a very high resolution:

Code:
xdpyinfo | grep dimensions
  dimensions:    3840x2160 pixels (1016x571 millimeters)


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 12, 2020, 06:05:11 PM
I'm just starting my Ubuntu to test it there ...

My PC Lenovo has a very high resolution:

Code:
xdpyinfo | grep dimensions
  dimensions:    3840x2160 pixels (1016x571 millimeters)

Could you print out a screen?


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 12, 2020, 06:28:13 PM
I'm just starting my Ubuntu to test it there ...

My PC Lenovo has a very high resolution:

Code:
xdpyinfo | grep dimensions
  dimensions:    3840x2160 pixels (1016x571 millimeters)

Could you print out a screen?

https://i.imgur.com/A9frh8p.png


Title: Re: Presentation of my ECC Calculator
Post by: MrFreeDragon on April 13, 2020, 01:02:03 AM
-snip-
I have a python code that performs over 4300 scalar multiplications per second (about 2800 if I don't use the invert function from gmpy2).
-snip-

What kind of CPU do you use?
I tested the code under Ubuntu, and it needs 16 seconds to perform 10k scalar multiplications for 10k random private keys, so it is 620-630 per second. However for the subsequent multiplications for numbers from 1 up to 10,000 (not random) it needed 0.6 seconds for all 10k multiplications.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 13, 2020, 06:17:43 AM
What kind of CPU do you use?
Intel Xeon CPU E3-1505M v6 3.00 GHz, a mobile cpu and my laptop is 3 years old.


I tested the code under Ubuntu, and it needs 16 seconds to perform 10k scalar multiplications for 10k random private keys, so it is 620-630 per second. However for the subsequent multiplications for numbers from 1 up to 10,000 (not random) it needed 0.6 seconds for all 10k multiplications.

I use a precomputed table of multiples of G.


Title: Re: Presentation of my ECC Calculator
Post by: Coding Enthusiast on April 13, 2020, 06:59:22 AM
I use my self-written library Secp256k1: https://github.com/MrMaxweII/Secp256k1 (https://github.com/MrMaxweII/Secp256k1)

One of the main reasons for your code being slow is that you are using BigInteger, or more precisely an arbitrary length integer. The implementation of BigInteger is also known to be not-optimized which contributed to it being slow.
Optimization of BigInteger itself could help increase speed by a factor of 5 to 10.
Replacing it with a fixed length integer increases the speed by a factor of 20.
Replacing methods such as Add, Subtract, Multiply,... with their modular alternatives (AddMod, MultMod,...) increases the speed by a factor of 10.

There are some more ideas I'm currently exploring that would optimize ECC further. I've actually started a topic about optimization here 4 month ago but didn't receive any reply so the ideas are kinda on pause right now.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 13, 2020, 07:18:43 AM
There are some more ideas I'm currently exploring that would optimize ECC further. I've actually started a topic about optimization here 4 month ago but didn't receive any reply so the ideas are kinda on pause right now.

If you want to share your ideas …

Optimizing field operations is the first thing, in particular way
a) "mod p" after multiplication
b) inversion operation

Optimizing scalar multiplication (group operation) is another step.


Title: Re: Presentation of my ECC Calculator
Post by: Coding Enthusiast on April 13, 2020, 07:40:54 AM
If you want to share your ideas …

The other ideas were mostly language related (C#) which is why I didn't mention them. For instance I've been experimenting with the new feature added in recent C# versions called ref structs. A ref readonly struct has been a successful optimization too.
Another idea was playing around with underlying integer type (UInt32 versus UInt64) and to use 32-bit or half of a UInt64 which later I found an article explaining an optimization for Curve25519 which uses radix 251 representation instead.

Basically I've started the optimization from the lowest part which is the integer type and all the basic arithmetic.
If there is interest, I could start a topic and share my findings when I'm done optimizing ECC in near future.


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 13, 2020, 09:35:39 AM
Quote
https://i.imgur.com/A9frh8p.png

It looks exactly like me in Ubuntu.
The input fields are then a little too short for the length of the number.
But it can be scrolled.

I use my self-written library Secp256k1: https://github.com/MrMaxweII/Secp256k1 (https://github.com/MrMaxweII/Secp256k1)

One of the main reasons for your code being slow is that you are using BigInteger, or more precisely an arbitrary length integer. The implementation of BigInteger is also known to be not-optimized which contributed to it being slow.
Optimization of BigInteger itself could help increase speed by a factor of 5 to 10.
Replacing it with a fixed length integer increases the speed by a factor of 20.
Replacing methods such as Add, Subtract, Multiply,... with their modular alternatives (AddMod, MultMod,...) increases the speed by a factor of 10.

There are some more ideas I'm currently exploring that would optimize ECC further. I've actually started a topic about optimization here 4 month ago but didn't receive any reply so the ideas are kinda on pause right now.

That's exactly the case! Thanks for the feedback.
I know that too, but I didn't mean to change that.
Programming my own data type is a lot of work for me and I have other projects I'm working on. I am currently programming a block explorer that uses the LevelDB database from the Bitcoin Core.
Using BigInteger is the easiest way to start.
If someone knows, provides or programs a suitable data type in Java for this 32 byte data, it would be great and I would then incorporate this into my libraries and into this program.
Of course, the required modular operations for this data type must then be provided. I still can't assess how difficult that would be.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 13, 2020, 12:49:30 PM
However for the subsequent multiplications for numbers from 1 up to 10,000 (not random) it needed 0.6 seconds for all 10k multiplications.

Consecutive keys:

210k keys per sec; with some optimizations: 800k per sec.


Title: Re: Presentation of my ECC Calculator
Post by: MrFreeDragon on April 13, 2020, 02:32:28 PM
-snip-
I use a precomputed table of multiples of G.

I did not use any precomputed multiples of G.
Do you use just 256 precomupted points for powers of two (2^0, 2^1, 2^2, 2^3, 2^4, ... 2^255) and later represent every private key number in binary and make scalar additions of precomputed points? If no, how much is your precomupted table and what kind of points include?


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 13, 2020, 02:41:45 PM
-snip-
I use a precomputed table of multiples of G.

I did not use any precomputed multiples of G.
Do you use just 256 precomupted points for powers of two (2^0, 2^1, 2^2, 2^3, 2^4, ... 2^255) and later represent every private key number in binary and make scalar additions of precomputed points? If no, how much is your precomupted table and what kind of points include?


https://github.com/MrMaxweII/Secp256k1-Calculator/blob/master/EXPList.java


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 13, 2020, 03:07:54 PM
https://github.com/MrMaxweII/Secp256k1-Calculator/blob/master/EXPList.java

-snip-
I use a precomputed table of multiples of G.

I did not use any precomputed multiples of G.
Do you use just 256 precomupted points for powers of two (2^0, 2^1, 2^2, 2^3, 2^4, ... 2^255) and later represent every private key number in binary and make scalar additions of precomputed points? If no, how much is your precomupted table and what kind of points include?


If you precompute only the powers of two, you avoid only the doublings. It is like you split your binary key in 256 pieces, each piece in this case is a particular point and then you perform 255 additions between these points.
But if you split 256 in 128/64/32/16/8 parts and you precompute every key in these "parts" (in these cases each part has more than 1 point) you can lower the number of additions.

I use 32 groups of 255 points = 8160 precomputed points.

I represent every private key in binary, I split that number in 32 pieces (each piece has 256/32=8 bit -> 255 elements) and I compute only 32-1 = 31 group additions (instead of 256) for each key. No doubling.

Just for example, if you have a 32 bit key:

key = 10101010101000001111111101000010

split in 4 pieces of 32/4=8 bits:

(10101010)*2^24 + (10100000)*2^16 + (11111111)*2^8 + (01000010)

Then I need to do only 3 additions, if I have precomputed this table (a line for each piece):

Code:
00000001  00000010 00000011  …   11111111

  2^0       2*2^0    3*2^0   …    255*2^0       --> one of these is (01000010)

  2^8       2*2^8    3*2^8   …    255*2^8       --> one of these is (11111111)*2^8

2^(2*8)  2*2^(2*8)  3*2^(2*8) . 255*2^(2*8)    --> one of these is (10100000)*2^16

2^(3*8)  2*2^(3*8)  3*2^(3*8) . 255*2^(3*8)    -->  one of these is (10101010)*2^24

Each line has 255 elements because you don't need the (00000000) element.


For a 256 bit key, this is the precomputed table (32 lines * 255 elements = 8160):
Code:
2^0 , 2*2^0,  3*2^0, … , 255*2^0

2^8,  2*2^8,  3*2^8, …,  255*2^8    

2^(2*8),  2*2^(2*8), 3*2^(2*8) , .., 255*2^(2*8)

2^(3*8),  2*2^(3*8), 3*2^(3*8) , .., 255*2^(3*8)

2^(4*8),  2*2^(4*8), 3*2^(4*8) , .., 255*2^(4*8)

2^(5*8),  2*2^(5*8), 3*2^(5*8) , .., 255*2^(5*8)



2^(31*8),  2*2^(31*8), 3*2^(31*8) , .., 255*2^(31*8)


I split a 256 bit key in 32 pieces of 8 bit and I compute 31 additions.


Title: Re: Presentation of my ECC Calculator
Post by: MrFreeDragon on April 13, 2020, 04:06:59 PM
-snip-
I represent every private key in binary, I split that number in 32 pieces (each piece has 256/32=8 bit -> 255 elements) and I compute only 32-1 = 31 group additions (instead of 256) for each key. No doubling.
-snip-
I split a 256 bit key in 32 pieces of 8 bit and I compute 31 additions.

Thank you very much! Very good approach!

I have tested already with 256 precomputed powers of two (so performed 255 additions) - for 10k random private keys I need 7.13 seconds (1400 per second) compared to 16 seconds (625 per second) without precomputed table. More than 2 times improvement.

I beleive that with your approach the speed will be faster. Not sure but seems that if I need only 31 additions instead of 255, the speed should be faster by 255/31 = 8 times, so for 10k I will need less than 1 second (11k per second).

I use 32 groups of 255 points = 8160 precomputed points.
How do you think, if use 16 groups 65,535 points (1 048 576 points) will it be faster? Only 15 additions will be required.


Title: Re: Presentation of my ECC Calculator
Post by: arulbero on April 13, 2020, 04:15:15 PM

I use 32 groups of 255 points = 8160 precomputed points.
How do you think, if use 16 groups 65,535 points (1 048 576 points) will it be faster? Only 15 additions will be required.

I think it would be slower, the table would be in RAM and not in some faster cpu's cache.


Title: Re: Presentation of my ECC Calculator
Post by: brainless on April 22, 2021, 09:15:15 PM
can some ecc expert write about Point addition / Point concatenate

https://bitcointalk.org/index.php?topic=5332526.new#new

waiting your expert views


Title: Re: Presentation of my ECC Calculator
Post by: fxsniper on April 23, 2021, 02:26:47 AM
How to use this program?
Did developer have video show hot to use?


Title: Re: Presentation of my ECC Calculator
Post by: MixMAx123 on April 23, 2021, 07:23:18 AM
How to use this program?
Did developer have video show hot to use?


If I find the time, I'll make a video. Unfortunately, my English is very poor and I am not a video professional. I would be very happy from someone else who would like to make a video of the program :-)