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

Bsgs optimization #360

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

marcus1979
Copy link

Improvements Applied in bsdsd.cpp

1) Precompute -intaux to avoid redundant computation.
2) Cache intermediate results in variables for reuse.
3)Use batch inversion for computing dx[i] values.
4) Reduce branching inside loops for better instruction pipelining.
5) Handle result checking separately to avoid polluting the computation logic.

@sssergy
Copy link

sssergy commented Dec 11, 2024

`bsgsd.cpp: In function ‘void* thread_process_bsgs(void*)’:
bsgsd.cpp:1653:3: error: ‘handle_key_found’ was not declared in this scope
1653 | handle_key_found(base_key, base_point);
| ^~~~~~~~~~~~~~~~
bsgsd.cpp:1654:15: error: expected ‘;’ before ‘printf’
1654 | bsgs_found=1
| ^
| ;
1655 |
1656 | printf("[+] Thread Key found privkey %s \n",hextemp);
| ~~~~~~
bsgsd.cpp:1683:7: error: ‘hLenght’ was not declared in this scope; did you mean ‘hLength’?
1683 | dx[hLenght].ModSub(&_2GSn.x, &startP.x); // Last point
| ^~~~~~~
| hLength
bsgsd.cpp:1691:5: error: ‘compute_points_batch’ was not declared in this scope
1691 | compute_points_batch(pts, dx, dy, dyn, _s, _p, GSn, startP);
| ^~~~~~~~~~~~~~~~~~~~
bsgsd.cpp:1695:11: error: ‘check_bloom_filter’ was not declared in this scope
1695 | if (check_bloom_filter(pts[i])) {
| ^~~~~~~~~~~~~~~~~~
bsgsd.cpp:1696:44: error: ‘j’ was not declared in this scope
1696 | if (bsgs_secondcheck(&base_key, (j * CPU_GRP_SIZE) + i, &keyfound)) {
| ^
bsgsd.cpp:1697:15: error: ‘handle_key_found’ was not declared in this scope
1697 | handle_key_found(keyfound, secp->ComputePublicKey(&keyfound));
| ^~~~~~~~~~~~~~~~
bsgsd.cpp:1705:38: error: ‘hLenght’ was not declared in this scope; did you mean ‘hLength’?
1705 | advance_start_point(startP, dx[hLenght + 1], dy, _s, _p, _2GSn);
| ^~~~~~~
| hLength
bsgsd.cpp:1705:7: error: ‘advance_start_point’ was not declared in this scope
1705 | advance_start_point(startP, dx[hLenght + 1], dy, _s, _p, _2GSn);
| ^~~~~~~~~~~~~~~~~~~
bsgsd.cpp:1711:6: error: expected ‘while’ before ‘compute_points_batch’
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~~~~~~~~~~~~~~~~~~~
bsgsd.cpp:1711:6: error: expected ‘(’ before ‘compute_points_batch’
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point GSn, const Point &startP) {
| ^~~~~~~~~~~~~~~~~~~~
| (
bsgsd.cpp:1711:33: error: expected primary-expression before ‘
’ token
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^
bsgsd.cpp:1711:39: error: expected primary-expression before ‘const’
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~~~~
bsgsd.cpp:1711:58: error: expected primary-expression before ‘&’ token
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^
bsgsd.cpp:1711:67: error: expected primary-expression before ‘&’ token
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^
bsgsd.cpp:1711:77: error: expected primary-expression before ‘&’ token
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^
bsgsd.cpp:1711:86: error: expected primary-expression before ‘&’ token
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^
bsgsd.cpp:1711:91: error: expected primary-expression before ‘const’
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~~~~
bsgsd.cpp:1711:109: error: expected primary-expression before ‘const’
1711 | nts_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~~~~

bsgsd.cpp:1711:6: error: ‘compute_points_batch’ was not declared in this scope
1711 | void compute_points_batch(Point *pts, const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~~~~~~~~~~~~~~~~~~~
bsgsd.cpp:1711:129: error: expected ‘)’ before ‘{’ token
1711 | , const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point *GSn, const Point &startP) {
| ^~
| )
bsgsd.cpp:1711:129: error: expected ‘;’ before ‘{’ token
1711 | , const Int *dx, Int &dy, Int &dyn, Int &_s, Int &_p, const Point GSn, const Point &startP) {
| ^~
| ;
bsgsd.cpp:1717:47: error: invalid use of ‘void’
1717 | pts[CPU_GRP_SIZE / 2 + i + 1].x.ModSub(&_p, &GSn[i].x).ModSub(&pts[CPU_GRP_SIZE / 2].x);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
bsgsd.cpp:1720:29: error: no matching function for call to ‘Int::ModNeg(Int
)’
1720 | dyn.ModNeg(&GSn[i].y);
| ^
In file included from secp256k1/Point.h:21,
from secp256k1/SECP256k1.h:21,
from bsgsd.cpp:21:
secp256k1/Int.h:123:8: note: candidate: ‘void Int::ModNeg()’
123 | void ModNeg(); // this <- -this (mod n)
| ^~~~~~
secp256k1/Int.h:123:8: note: candidate expects 0 arguments, 1 provided
bsgsd.cpp:1724:47: error: invalid use of ‘void’
1724 | pts[CPU_GRP_SIZE / 2 - i - 1].x.ModSub(&_p, &GSn[i].x).ModSub(&pts[CPU_GRP_SIZE / 2].x);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
bsgsd.cpp:1729:42: error: a function-definition is not allowed here before ‘{’ token
1729 | bool check_bloom_filter(const Point &pt) {
| ^
bsgsd.cpp:1736:42: error: a function-definition is not allowed here before ‘{’ token
1736 | bool check_bloom_filter(const Point &pt) {
| ^
bsgsd.cpp:1752:30: error: ‘i’ was not declared in this scope
1752 | pts[CPU_GRP_SIZE / 2 + (i + 1)] = pp;
| ^
bsgsd.cpp:1578:7: warning: unused variable ‘xpoint_raw’ [-Wunused-variable]
1578 | char xpoint_raw[32],*aux_c,*hextemp;
| ^~~~~~~~~~
bsgsd.cpp:1581:11: warning: unused variable ‘r’ [-Wunused-variable]
1581 | uint32_t r, cycles;
| ^
bsgsd.cpp:1755:5: warning: no return statement in function returning non-void [-Wreturn-type]
1755 | }
| ^
bsgsd.cpp:1575:33: warning: unused parameter ‘vargp’ [-Wunused-parameter]
1575 | void *thread_process_bsgs(void *vargp) {
| ~~~~~~^~~~~
bsgsd.cpp: At global scope:
bsgsd.cpp:1758:5: error: ‘pn’ does not name a type; did you mean ‘Gn’?
1758 | pn = startP;
| ^~
| Gn
bsgsd.cpp:1759:5: error: ‘dyn’ does not name a type; did you mean ‘yn’?
1759 | dyn.Set(&GSn[i].y);
| ^~~
| yn
bsgsd.cpp:1760:5: error: ‘dyn’ does not name a type; did you mean ‘yn’?
1760 | dyn.ModNeg();
| ^~~
| yn
bsgsd.cpp:1761:5: error: ‘dyn’ does not name a type; did you mean ‘yn’?
1761 | dyn.ModSub(&pn.y);
| ^~~
| yn
bsgsd.cpp:1763:5: error: ‘_s’ does not name a type
1763 | _s.ModMulK1(&dyn,&dx[i]);
| ^~
bsgsd.cpp:1764:5: error: ‘_p’ does not name a type
1764 | _p.ModSquareK1(&_s);
| ^~
bsgsd.cpp:1766:5: error: ‘pn’ does not name a type; did you mean ‘Gn’?
1766 | pn.x.ModNeg();
| ^~
| Gn
bsgsd.cpp:1767:5: error: ‘pn’ does not name a type; did you mean ‘Gn’?
1767 | pn.x.ModAdd(&_p);
| ^~
| Gn
bsgsd.cpp:1768:5: error: ‘pn’ does not name a type; did you mean ‘Gn’?
1768 | pn.x.ModSub(&GSn[i].x);
| ^~
| Gn
bsgsd.cpp:1777:5: error: ‘pts’ does not name a type; did you mean ‘puts’?
1777 | pts[0] = pn;
| ^~~
| puts
bsgsd.cpp:1779:5: error: expected unqualified-id before ‘for’
1779 | for(int i = 0; i<CPU_GRP_SIZE && bsgs_found == 0; i++) {
| ^~~
bsgsd.cpp:1779:20: error: ‘i’ does not name a type
1779 | for(int i = 0; i<CPU_GRP_SIZE && bsgs_found == 0; i++) {
| ^
bsgsd.cpp:1779:55: error: ‘i’ does not name a type
1779 | for(int i = 0; i<CPU_GRP_SIZE && bsgs_found == 0; i++) {
| ^
bsgsd.cpp:1814:5: error: ‘pp’ does not name a type
1814 | pp = startP;
| ^~
bsgsd.cpp:1815:5: error: ‘dy’ does not name a type
1815 | dy.ModSub(&_2GSn.y,&pp.y);
| ^~
bsgsd.cpp:1817:5: error: ‘_s’ does not name a type
1817 | _s.ModMulK1(&dy,&dx[i + 1]);
| ^~
bsgsd.cpp:1818:5: error: ‘_p’ does not name a type
1818 | _p.ModSquareK1(&_s);
| ^~
bsgsd.cpp:1820:5: error: ‘pp’ does not name a type
1820 | pp.x.ModNeg();
| ^~
bsgsd.cpp:1821:5: error: ‘pp’ does not name a type
1821 | pp.x.ModAdd(&_p);
| ^~
bsgsd.cpp:1822:5: error: ‘pp’ does not name a type
1822 | pp.x.ModSub(&_2GSn.x);
| ^~
bsgsd.cpp:1827:5: error: ‘pp’ does not name a type
1827 | pp.y.ModSub(&_2GSn.x,&pp.x);
| ^~
bsgsd.cpp:1828:5: error: ‘pp’ does not name a type
1828 | pp.y.ModMulK1(&_s);
| ^~
bsgsd.cpp:1829:5: error: ‘pp’ does not name a type
1829 | pp.y.ModSub(&_2GSn.y);
| ^~
bsgsd.cpp:1830:5: error: ‘startP’ does not name a type
1830 | startP = pp;
| ^~~~~~
bsgsd.cpp:1832:5: error: ‘j’ does not name a type
1832 | j++;
| ^
bsgsd.cpp:1833:4: error: expected declaration before ‘}’ token
1833 | } //while all the aMP points
| ^
bsgsd.cpp:1834:3: error: expected declaration before ‘}’ token
1834 | } // end else
| ^
bsgsd.cpp:1835:2: error: expected declaration before ‘}’ token
1835 | }while(base_key.IsLower(&n_range_end) && bsgs_found == 0);
| ^
bsgsd.cpp:1835:3: error: expected unqualified-id before ‘while’
1835 | }while(base_key.IsLower(&n_range_end) && bsgs_found == 0);
| ^~~~~
bsgsd.cpp:1836:2: error: expected unqualified-id before ‘delete’
1836 | delete grp;
| ^~~~~~
bsgsd.cpp:1837:14: error: expected constructor, destructor, or type conversion before ‘(’ token
1837 | pthread_exit(NULL);
| ^
bsgsd.cpp:1838:1: error: expected declaration before ‘}’ token
1838 | }
| ^
make: *** [Makefile:60: bsgsd] Error 1
`

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.

2 participants