-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyhunt.cpp
More file actions
13472 lines (12241 loc) · 430 KB
/
Copy pathkeyhunt.cpp
File metadata and controls
13472 lines (12241 loc) · 430 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Developed & Modified by TrueScent
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#if defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
#include <io.h>
#else
#include <unistd.h>
#endif
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <vector>
#include <map>
#include <inttypes.h>
#include "base58/libbase58.h"
#include "rmd160/rmd160.h"
#include "oldbloom/oldbloom.h"
#include "bloom/bloom.h"
#include "binaryfuse/binaryfuse_wrapper.h"
#include "sha3/sha3.h"
#include "util.h"
#include "secp256k1/SECP256k1.h"
#include "secp256k1/Point.h"
#include "secp256k1/Int.h"
#include "secp256k1/IntGroup.h"
#include "secp256k1/Random.h"
#include "hash/sha256.h"
#include "hash/sha512.h"
#include "hash/ripemd160.h"
#include "ed25519/ed25519.h"
#include "backend_config.h"
#include "research_engine.h"
#if defined(_MSC_VER) && !defined(strtok_r)
#define strtok_r strtok_s
#endif
#include "cpu_features.h"
#include "gpu/gpu_dispatcher.h"
#include "hash/hash160_avx512.h"
#include "hash/hash160_avx2.h"
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(_MSC_VER)
static int rand_r(unsigned int *seed) {
*seed = *seed * 1103515245u + 12345u;
return (int)((*seed >> 16) & 0x7FFF);
}
#if defined(_MSC_VER)
#ifndef strtok_r
#define strtok_r(str, delim, save) strtok_s((str), (delim), (save))
#endif
#ifndef popen
#define popen _popen
#endif
#ifndef pclose
#define pclose _pclose
#endif
#endif
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#include <windows.h>
#endif
#if defined(_MSC_VER)
#include "compat/getopt.h"
#include <windows.h>
#ifndef strdup
#define strdup _strdup
#endif
#else
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#endif
#if defined(__linux__) && !defined(__ANDROID__) && !defined(TERMUX)
#include <sys/random.h>
#endif
#ifdef __unix__
#ifndef __CYGWIN__
#if defined(__linux__) && !defined(__ANDROID__) && !defined(TERMUX)
#include <linux/random.h>
#endif
#endif
#endif
#define CRYPTO_NONE 0
#define CRYPTO_BTC 1
#define CRYPTO_ETH 2
#define CRYPTO_ALL 3
#define CRYPTO_TROOT 4
#define CRYPTO_BCH 5
#define CRYPTO_BTG 6
#define CRYPTO_ETC 7
#define CRYPTO_LTC 8
#define CRYPTO_DOGE 9
#define CRYPTO_XRP 10
#define CRYPTO_SOL 11
#define CRYPTO_AUTO 12
#define MODE_XPOINT 0
#define MODE_ADDRESS 1
#define MODE_BSGS 2
#define MODE_RMD160 3
#define MODE_PUB2RMD 4
#define MODE_MINIKEYS 5
#define MODE_VANITY 6
#define MODE_MNEMONIC 7
#define MODE_POETRY 8
#define MODE_BRAINWALLET 9
#define MODE_PUB2ADDR 10
#define MODE_KANGAROO 11
#define SEARCH_UNCOMPRESS 0
#define SEARCH_COMPRESS 1
#define SEARCH_BOTH 2
#define SEARCHMODE_SEQUENTIAL 0
#define SEARCHMODE_RANDOM 1
#define SEARCHMODE_CHAOS 2
#define SEARCHMODE_GRAVITY 3
#define SEARCHMODE_SPIRAL 4
#define SEARCHMODE_REVERSE 5
#define SEARCHMODE_AUTO 6
#define SEARCHMODE_RSEQ 7
#define SEARCHMODE_HILBERT 8
#define SEARCHMODE_SOBOL 9
#define SEARCHMODE_HALTON 10
#define SEARCHMODE_DENSITY 11
/* Mivvvy-style default chunk: random start, then walk this many keys before reseed */
#define RANDOM_SEQUENTIAL_DEFAULT_N 0x100000ULL
static uint64_t g_lds_step = 0;
static uint64_t g_milksad_cursor = 0;
uint32_t THREADBPWORKLOAD = 1048576;
struct checksumsha256 {
char data[32];
char backup[32];
};
struct bsgs_xvalue {
uint8_t value[6];
uint64_t index;
};
struct address_value {
uint8_t value[20];
};
struct troot_value {
uint8_t value[32];
};
struct sol_value {
uint8_t value[32];
};
struct tothread {
int nt; //Number thread
char *rs; //range start
char *rpt; //rng per thread
};
struct bPload {
uint32_t threadid;
uint64_t from;
uint64_t to;
uint64_t counter;
uint64_t workload;
uint32_t aux;
uint32_t finished;
};
#if defined(_MSC_VER) && !defined(__MINGW64__)
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
PACK(struct publickey
{
uint8_t parity;
union {
uint8_t data8[32];
uint32_t data32[8];
uint64_t data64[4];
} X;
});
#else
struct __attribute__((__packed__)) publickey {
uint8_t parity;
union {
uint8_t data8[32];
uint32_t data32[8];
uint64_t data64[4];
} X;
};
#endif
const char *Ccoinbuffer_default = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
char *Ccoinbuffer = (char*) Ccoinbuffer_default;
char *str_baseminikey = NULL;
char *raw_baseminikey = NULL;
char *minikeyN = NULL;
const char *version = "TrueCollider Search Modes + Binary Fuse Filters";
#ifndef CPU_GRP_SIZE
#define CPU_GRP_SIZE 1024
#endif
std::vector<Point> Gn;
Point _2Gn;
std::vector<Point> GSn;
Point _2GSn;
void menu();
void init_generator();
int searchbinary(struct address_value *buffer,char *data,int64_t array_length);
void sleep_ms(int milliseconds);
void _sort(struct address_value *arr,int64_t N);
void _insertionsort(struct address_value *arr, int64_t n);
void _introsort(struct address_value *arr,uint32_t depthLimit, int64_t n);
void _swap(struct address_value *a,struct address_value *b);
int64_t _partition(struct address_value *arr, int64_t n);
void _myheapsort(struct address_value *arr, int64_t n);
void _heapify(struct address_value *arr, int64_t n, int64_t i);
void bsgs_sort(struct bsgs_xvalue *arr,int64_t n);
void bsgs_myheapsort(struct bsgs_xvalue *arr, int64_t n);
void bsgs_insertionsort(struct bsgs_xvalue *arr, int64_t n);
void bsgs_introsort(struct bsgs_xvalue *arr,uint32_t depthLimit, int64_t n);
void bsgs_swap(struct bsgs_xvalue *a,struct bsgs_xvalue *b);
void bsgs_heapify(struct bsgs_xvalue *arr, int64_t n, int64_t i);
int64_t bsgs_partition(struct bsgs_xvalue *arr, int64_t n);
int bsgs_searchbinary(struct bsgs_xvalue *arr,char *data,int64_t array_length,uint64_t *r_value);
int bsgs_secondcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey);
int bsgs_thirdcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey);
#if !defined(NO_SSE) && (defined(__x86_64__) || defined(_M_X64)) && !defined(TERMUX)
void sha256sse_22(uint8_t *src0, uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *dst0, uint8_t *dst1, uint8_t *dst2, uint8_t *dst3);
void sha256sse_23(uint8_t *src0, uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *dst0, uint8_t *dst1, uint8_t *dst2, uint8_t *dst3);
#endif
bool vanityrmdmatch(unsigned char *rmdhash);
void writevanitykey(bool compress,Int *key);
int addvanity(char *target);
int minimum_same_bytes(unsigned char* A,unsigned char* B, int length);
void writekey(bool compressed,Int *key);
void writekeyeth(Int *key);
void writekeysol(Int *key);
static void append_found_file(const char *tag, const char *body);
static void report_hit_balance(const char *address, int crypto_type, const char *found_tag);
int node_check_balance(const char *address, int crypto_type);
int run_kangaroo_search(const char *pubkey_file);
static void append_found_file(const char *tag, const char *body);
static int gpu_check_privkey_list(const uint8_t *privs, int count, int compressed, int is_eth);
static int process_secp_gpu_privkey_batch(Int *key_mpz, Int *stride, Int *keyfound,
char *publickeyhashrmd160, uint64_t *count_out);
static uint64_t host_total_ram_bytes(void);
static void bsgs_recommend_from_ram(uint64_t ram_bytes, int *out_k, const char **out_n_hex);
void checkpointer(void *ptr,const char *file,const char *function,const char *name,int line);
bool isBase58(char c);
bool isValidBase58String(char *str);
bool readFileAddress(char *fileName);
bool readFileVanity(char *fileName);
bool forceReadFileAddress(char *fileName);
bool forceReadFileAddressEth(char *fileName);
bool forceReadFileAddressSol(char *fileName);
bool forceReadFileXPoint(char *fileName);
bool processOneVanity();
int autodetect_crypto_from_file(const char *fileName);
bool initBloomFilter(struct bloom *bloom_arg,uint64_t items_bloom);
int address_check(const void *buffer, int len);
void writeFileIfNeeded(const char *fileName);
void calcualteindex(int i,Int *key);
#if defined(_MSC_VER)
DWORD WINAPI thread_process_vanity(LPVOID vargp);
DWORD WINAPI thread_process_minikeys(LPVOID vargp);
DWORD WINAPI thread_process(LPVOID vargp);
DWORD WINAPI thread_process_mnemonic(LPVOID vargp);
DWORD WINAPI thread_process_derived(LPVOID vargp);
DWORD WINAPI thread_process_troot(LPVOID vargp);
DWORD WINAPI thread_process_sol(LPVOID vargp);
DWORD WINAPI thread_process_poetry(LPVOID vargp);
DWORD WINAPI thread_process_brainwallet(LPVOID vargp);
DWORD WINAPI thread_process_pub2addr(LPVOID vargp);
DWORD WINAPI thread_process_bsgs(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_backward(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_both(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_random(LPVOID vargp);
DWORD WINAPI thread_process_bsgs_dance(LPVOID vargp);
DWORD WINAPI thread_bPload(LPVOID vargp);
DWORD WINAPI thread_bPload_2blooms(LPVOID vargp);
#else
void *thread_process_vanity(void *vargp);
void *thread_process_minikeys(void *vargp);
void *thread_process(void *vargp);
void *thread_process_mnemonic(void *vargp);
void *thread_process_derived(void *vargp);
void *thread_process_troot(void *vargp);
void *thread_process_sol(void *vargp);
void *thread_process_poetry(void *vargp);
void *thread_process_brainwallet(void *vargp);
void *thread_process_pub2addr(void *vargp);
void *thread_process_bsgs(void *vargp);
void *thread_process_bsgs_backward(void *vargp);
void *thread_process_bsgs_both(void *vargp);
void *thread_process_bsgs_random(void *vargp);
void *thread_process_bsgs_dance(void *vargp);
void *thread_bPload(void *vargp);
void *thread_bPload_2blooms(void *vargp);
#endif
char *pubkeytopubaddress(char *pkey,int length);
void pubkeytopubaddress_dst(char *pkey,int length,char *dst);
void rmd160toaddress_dst(char *rmd,char *dst);
void set_minikey(char *buffer,char *rawbuffer,int length);
bool increment_minikey_index(char *buffer,char *rawbuffer,int index);
void increment_minikey_N(char *rawbuffer);
void KECCAK_256(uint8_t *source, size_t size,uint8_t *dst);
void generate_binaddress_eth(Point &publickey,unsigned char *dst_address);
void compute_taproot_output(Point &pubkey, uint8_t *x_only_out);
int troot_searchbinary(struct troot_value *arr, uint8_t *data, int64_t array_length);
int THREADOUTPUT = 0;
char *bit_range_str_min;
char *bit_range_str_max;
const char *bsgs_modes[22] = {"sequential","backward","both","random","dance","grumpy","interleave","orbit","residue","dual-range","nested","fractal","async-resolve","multi-target","negmap","handoff","gravity-giant","chaos-giant","sobol-giant","freeze-table","compact-dp","rseq"};
const char *modes[20] = {"xpoint","address","bsgs","rmd160","pub2rmd","minikeys","vanity","mnemonic","poetry","brainwallet","pubkey2addr","kangaroo","shadow160","weakrng","hybrid-dl","gaudry","CreateAccountWithSeed","wif-mask","hex-mask","kangaroo-mod"};
const char *cryptos[13] = {"btc","eth","all","troot","bch","btg","etc","ltc","doge","xrp","sol","auto"};
const char *publicsearch[3] = {"uncompress","compress","both"};
const char *searchmodes[12] = {"sequential","random","chaos","gravity","spiral","reverse","auto","rseq","hilbert","sobol","halton","density-map"};
const char *default_fileName = "addresses.txt";
int FLAGSEARCHMODE = SEARCHMODE_RANDOM;
int FLAGRS = 0; /* -rs / -x rseq: random-sequential (random base + sequential N walk) */
double chaos_x = 0.1;
const double chaos_r = 3.99999;
Int gravity_center;
int gravity_found_count = 0;
Int spiral_center;
double spiral_angle = 0.0;
const double spiral_step = 0.1;
int auto_phase = 0;
int auto_cycles = 0;
const int AUTO_PHASE_CYCLES[4] = {200, 300, 200, 300};
int FLAGMNEMONIC_WORDS = 0;
int FLAGMNEMONIC_LANG = 0;
int FLAGMNEMONIC_ALL_LANGS = 0;
int FLAGMNEMONIC_ETH = 0;
int FLAGDP = 1;
char mnemonic_lang_name[64] = "english";
int FLAGPOETRY_WORDS = 0;
int FLAGBRAINWALLET_WORDS = 0;
int FLAGPATH = 0;
char *path_string = NULL;
uint32_t parsed_path[16];
int parsed_path_len = 0;
int FLAGVERBOSE = 0;
const int NUM_BIP39_LANGUAGES = 10;
const char *bip39_language_names[] = {
"english", "spanish", "french", "italian", "czech",
"portuguese", "japanese", "korean", "chinese_simplified", "chinese_traditional"
};
char *bip39_wordlist_storage[2048];
char **bip39_wordlist = bip39_wordlist_storage;
int bip39_wordlist_size = 0;
char **bip39_all_wordlists[10];
int bip39_all_sizes[10];
bool load_bip39_wordlist(const char *lang) {
char path[512];
snprintf(path, sizeof(path), "tests/bip39/%s.txt", lang);
FILE *f = fopen(path, "r");
if(!f) {
snprintf(path, sizeof(path), "%s.txt", lang);
f = fopen(path, "r");
}
if(!f) {
fprintf(stderr, "[E] Cannot open BIP39 wordlist: %s\n", lang);
return false;
}
for(int i = 0; i < bip39_wordlist_size; i++) {
free(bip39_wordlist[i]);
bip39_wordlist[i] = NULL;
}
bip39_wordlist_size = 0;
char line[512];
while(fgets(line, sizeof(line), f) && bip39_wordlist_size < 2048) {
int len = strlen(line);
while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
line[--len] = '\0';
}
if(len > 0) {
bip39_wordlist[bip39_wordlist_size] = strdup(line);
bip39_wordlist_size++;
}
}
fclose(f);
if(bip39_wordlist_size != 2048) {
fprintf(stderr, "[E] BIP39 wordlist '%s' has %d words (expected 2048)\n", lang, bip39_wordlist_size);
return false;
}
return true;
}
void preload_all_wordlists() {
for(int i = 0; i < NUM_BIP39_LANGUAGES; i++) {
bip39_all_wordlists[i] = NULL;
bip39_all_sizes[i] = 0;
char path[512];
snprintf(path, sizeof(path), "tests/bip39/%s.txt", bip39_language_names[i]);
FILE *f = fopen(path, "r");
if(!f) {
fprintf(stderr, "[E] Cannot open BIP39 wordlist: %s (%s)\n", bip39_language_names[i], path);
continue;
}
bip39_all_wordlists[i] = (char**)calloc(2048, sizeof(char*));
if(!bip39_all_wordlists[i]) {
fprintf(stderr, "[E] Cannot allocate memory for %s\n", bip39_language_names[i]);
fclose(f);
continue;
}
int count = 0;
char line[512];
while(fgets(line, sizeof(line), f) && count < 2048) {
int len = strlen(line);
while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
line[--len] = '\0';
}
if(len > 0) {
bip39_all_wordlists[i][count] = strdup(line);
count++;
}
}
fclose(f);
bip39_all_sizes[i] = count;
if(count != 2048) {
fprintf(stderr, "[PRELOAD] Wordlist '%s' has %d/2048 words - skipping\n", bip39_language_names[i], count);
for(int j = 0; j < count; j++) free(bip39_all_wordlists[i][j]);
free(bip39_all_wordlists[i]);
bip39_all_wordlists[i] = NULL;
bip39_all_sizes[i] = 0;
}
}
}
// Poetry word list (words for hex encoding)
char *poetry_words[2048];
int poetry_words_size = 0;
bool load_poetry_words(const char *path) {
FILE *f = fopen(path, "r");
if(!f) {
fprintf(stderr, "[E] Cannot open poetry wordlist: %s\n", path);
return false;
}
poetry_words_size = 0;
char line[256];
while(fgets(line, sizeof(line), f) && poetry_words_size < 2048) {
int len = strlen(line);
while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
line[--len] = '\0';
}
if(len > 0) {
poetry_words[poetry_words_size] = strdup(line);
poetry_words_size++;
}
}
fclose(f);
printf("[+] Loaded poetry wordlist: %d words\n", poetry_words_size);
return true;
}
// Brainwallet word list
char *brainwallet_words[65536];
int brainwallet_words_size = 0;
bool load_brainwallet_words(const char *path) {
FILE *f = fopen(path, "r");
if(!f) {
fprintf(stderr, "[E] Cannot open brainwallet wordlist: %s\n", path);
return false;
}
brainwallet_words_size = 0;
char line[256];
while(fgets(line, sizeof(line), f) && brainwallet_words_size < 65536) {
int len = strlen(line);
while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) {
line[--len] = '\0';
}
if(len > 0) {
brainwallet_words[brainwallet_words_size] = strdup(line);
brainwallet_words_size++;
}
}
fclose(f);
printf("[+] Loaded brainwallet wordlist: %d words\n", brainwallet_words_size);
return true;
}
bool parse_derivation_path(const char *path) {
if(!path || path[0] != 'm') return false;
parsed_path_len = 0;
const char *p = path + 1;
while(*p && parsed_path_len < 16) {
if(*p == '/') { p++; continue; }
uint32_t index = 0;
bool hardened = false;
if(*p == '\0' || *p == '/') return false;
while(*p >= '0' && *p <= '9') {
index = index * 10 + (*p - '0');
p++;
}
if(*p == '\'' || *p == 'H' || *p == 'h') {
hardened = true;
index += 0x80000000;
p++;
}
parsed_path[parsed_path_len++] = index;
}
return parsed_path_len > 0;
}
#if defined(_MSC_VER)
HANDLE* tid = NULL;
HANDLE write_keys;
HANDLE write_random;
HANDLE bsgs_thread;
HANDLE *bPload_mutex = NULL;
#else
pthread_t *tid = NULL;
pthread_mutex_t write_keys;
pthread_mutex_t write_random;
pthread_mutex_t bsgs_thread;
pthread_mutex_t *bPload_mutex = NULL;
#endif
uint64_t FINISHED_THREADS_COUNTER = 0;
uint64_t FINISHED_THREADS_BP = 0;
uint64_t THREADCYCLES = 0;
uint64_t THREADCOUNTER = 0;
uint64_t FINISHED_ITEMS = 0;
uint64_t OLDFINISHED_ITEMS = -1;
uint8_t byte_encode_crypto = 0x00; /* Bitcoin */
int vanity_rmd_targets = 0;
int vanity_rmd_total = 0;
int *vanity_rmd_limits = NULL;
uint8_t ***vanity_rmd_limit_values_A = NULL,***vanity_rmd_limit_values_B = NULL;
int vanity_rmd_minimun_bytes_check_length = 999999;
char **vanity_address_targets = NULL;
struct bloom *vanity_bloom = NULL;
struct bloom bloom;
struct binaryfuse_wrapper bf_filter;
struct binaryfuse_wrapper bf_filter_coarse;
struct binaryfuse_wrapper bf_filter_mid;
int FLAG_FUSE_CASCADE = 0;
struct bloom troot_bloom;
struct binaryfuse_wrapper troot_bf_filter;
struct troot_value *trootTable = NULL;
uint64_t N_TROOT = 0;
struct bloom sol_bloom;
struct binaryfuse_wrapper sol_bf_filter;
struct sol_value *solTable = NULL;
uint64_t N_SOL = 0;
uint64_t *steps = NULL;
unsigned int *ends = NULL;
uint64_t N = 0;
uint64_t N_SEQUENTIAL_MAX = 0x100000000;
uint64_t DEBUGCOUNT = 0x400;
uint64_t u64range;
Int OUTPUTSECONDS;
int FLAGSKIPCHECKSUM = 0;
int FLAGENDOMORPHISM = 0;
int FLAGBLOOMMULTIPLIER = 1;
int FLAGVANITY = 0;
int FLAGBASEMINIKEY = 0;
int FLAGBSGSMODE = 0;
static char g_handoff_pubkey_file[1024] = "addresses.txt";
static int g_handoff_armed = 0;
int FLAGDEBUG = 0;
int FLAGDRYRUN = 0;
int FLAGQUIET = 0;
int FLAGMATRIX = 0;
int KFACTOR = 1;
int FLAG_K_AUTO = 0;
int FLAGNODECHECK = 0;
int MAXLENGTHADDRESS = -1;
int NTHREADS = 1;
int FLAGSAVEREADFILE = 0;
int FLAGREADEDFILE1 = 0;
char *NODE_RPC_URL = NULL;
int FLAGREADEDFILE2 = 0;
int FLAGREADEDFILE3 = 0;
int FLAGREADEDFILE4 = 0;
int FLAGUPDATEFILE1 = 0;
int FLAGSTRIDE = 0;
int FLAGSEARCH = 2;
int FLAGBITRANGE = 0;
int FLAGRANGE = 0;
int FLAGFILE = 0;
int FLAGMODE = MODE_ADDRESS;
int FLAGCRYPTO = 0;
int FLAGHAS_P2SH_TARGETS = 0;
int FLAGRAWDATA = 0;
int FLAGRANDOM = 0;
int FLAG_N = 0;
int FLAGPRECALCUTED_P_FILE = 0;
int bitrange;
/* Backend configuration (CPU vectorization, GPU). Defined in backend_config.cpp. */
extern struct BackendConfig g_backend_config;
struct GpuDispatcher *g_gpu_dispatcher = NULL;
char *str_N;
char *range_start;
char *range_end;
char *str_stride;
Int stride;
uint64_t BSGS_XVALUE_RAM = 6;
uint64_t BSGS_BUFFERXPOINTLENGTH = 32;
uint64_t BSGS_BUFFERREGISTERLENGTH = 36;
/*
BSGS Variables
*/
int *bsgs_found;
std::vector<Point> OriginalPointsBSGS;
bool *OriginalPointsBSGScompressed;
uint64_t bytes;
char checksum[32],checksum_backup[32];
char buffer_bloom_file[1024];
struct bsgs_xvalue *bPtable;
struct address_value *addressTable;
struct oldbloom oldbloom_bP;
struct bloom *bloom_bP;
struct bloom *bloom_bPx2nd; //2nd Bloom filter check
struct bloom *bloom_bPx3rd; //3rd Bloom filter check
struct checksumsha256 *bloom_bP_checksums;
struct checksumsha256 *bloom_bPx2nd_checksums;
struct checksumsha256 *bloom_bPx3rd_checksums;
#if defined(_MSC_VER)
HANDLE *bloom_bP_mutex;
HANDLE *bloom_bPx2nd_mutex;
HANDLE *bloom_bPx3rd_mutex;
#else
pthread_mutex_t *bloom_bP_mutex;
pthread_mutex_t *bloom_bPx2nd_mutex;
pthread_mutex_t *bloom_bPx3rd_mutex;
#endif
uint64_t bloom_bP_totalbytes = 0;
uint64_t bloom_bP2_totalbytes = 0;
uint64_t bloom_bP3_totalbytes = 0;
uint64_t bsgs_m = 4194304;
uint64_t bsgs_m2;
uint64_t bsgs_m3;
uint64_t bsgs_aux;
uint32_t bsgs_point_number;
const char *str_limits_prefixs[7] = {"Mkeys/s","Gkeys/s","Tkeys/s","Pkeys/s","Ekeys/s","Zkeys/s","Ykeys/s"};
const char *str_limits[7] = {"1000000","1000000000","1000000000000","1000000000000000","1000000000000000000","1000000000000000000000","1000000000000000000000000"};
Int int_limits[7];
Int BSGS_GROUP_SIZE;
Int BSGS_CURRENT;
Int BSGS_R;
Int BSGS_AUX;
Int BSGS_N;
Int BSGS_N_double;
Int BSGS_M; //M is squareroot(N)
Int BSGS_M_double;
Int BSGS_M2; //M2 is M/32
Int BSGS_M2_double; //M2_double is M2 * 2
Int BSGS_M3; //M3 is M2/32
Int BSGS_M3_double; //M3_double is M3 * 2
Int ONE;
Int ZERO;
Int MPZAUX;
Point BSGS_P; //Original P is actually G, but this P value change over time for calculations
Point BSGS_MP; //MP values this is m * P
Point BSGS_MP2; //MP2 values this is m2 * P
Point BSGS_MP3; //MP3 values this is m3 * P
Point BSGS_MP_double; //MP2 values this is m2 * P * 2
Point BSGS_MP2_double; //MP2 values this is m2 * P * 2
Point BSGS_MP3_double; //MP3 values this is m3 * P * 2
std::vector<Point> BSGS_AMP2;
std::vector<Point> BSGS_AMP3;
Point point_temp,point_temp2; //Temp value for some process
Int n_range_start;
Int n_range_end;
Int n_range_diff;
Int n_range_aux;
Int lambda,lambda2,beta,beta2;
Secp256K1 *secp;
// ============================================================
// Collider Search Modes - CPU Implementation
// ============================================================
void init_search_mode(Int *range_start, Int *range_end) {
Int range_mid;
switch(FLAGSEARCHMODE) {
case SEARCHMODE_CHAOS:
chaos_x = 0.1;
printf("[+] Chaos mode: logistic map r=%.5f\n", chaos_r);
break;
case SEARCHMODE_GRAVITY:
gravity_center.Set(range_start);
gravity_found_count = 0;
printf("[+] Gravity mode: adaptive search around found keys\n");
break;
case SEARCHMODE_SPIRAL:
range_mid.Set(range_end);
range_mid.Sub(range_start);
range_mid.ShiftR(1);
spiral_center.Set(range_start);
spiral_center.Add(&range_mid);
spiral_angle = 0.0;
printf("[+] Spiral mode: Archimedean spiral from midpoint\n");
break;
case SEARCHMODE_REVERSE:
printf("[+] Reverse mode: inverted BSGS baby/giant step roles\n");
break;
case SEARCHMODE_AUTO:
auto_phase = 0;
auto_cycles = 0;
printf("[+] Auto mode: cycling through spiral->chaos->gravity->reverse\n");
break;
case SEARCHMODE_HILBERT:
printf("[+] HilbertStride quasirandom coverage\n"); g_lds_step = 0; break;
case SEARCHMODE_SOBOL:
printf("[+] SobolWalk LDS coverage\n"); g_lds_step = 0; break;
case SEARCHMODE_HALTON:
printf("[+] Halton LDS coverage\n"); g_lds_step = 0; break;
case SEARCHMODE_DENSITY:
printf("[+] Density-map mode\n"); g_lds_step = 0; break;
default:
break;
}
}
void get_next_key_chaos(Int *result, Int *range_start, Int *range_end) {
Int range_size, temp;
uint64_t chaos_val;
range_size.Set(range_end);
range_size.Sub(range_start);
chaos_x = chaos_r * chaos_x * (1.0 - chaos_x);
chaos_val = (uint64_t)(chaos_x * 1e16) % 10000000000000000ULL;
temp.SetInt64(chaos_val);
temp.Mult(&range_size);
temp.ShiftR(53);
result->Set(range_start);
result->Add(&temp);
}
void get_next_key_gravity(Int *result, Int *range_start, Int *range_end) {
Int range_size, offset, temp;
double pull_strength;
int rand_val;
range_size.Set(range_end);
range_size.Sub(range_start);
if(gravity_found_count > 0) {
pull_strength = 0.7;
rand_val = rand() % 100;
if(rand_val < 70) {
offset.SetInt32(rand() % 1024);
if(rand() % 2 == 0) {
result->Set(&gravity_center);
result->Add(&offset);
} else {
result->Set(&gravity_center);
result->Sub(&offset);
}
} else {
result->Rand(range_start, range_end);
}
} else {
result->Rand(range_start, range_end);
}
}
void get_next_key_spiral(Int *result, Int *range_start, Int *range_end) {
Int range_size, offset_x, offset_y, temp;
double x, y, r;
int64_t ix, iy;
range_size.Set(range_end);
range_size.Sub(range_start);
r = spiral_step * spiral_angle;
x = r * cos(spiral_angle);
y = r * sin(spiral_angle);
ix = (int64_t)(x * 1e12) % 1000000;
iy = (int64_t)(y * 1e12) % 1000000;
offset_x.SetInt64(abs(ix));
offset_y.SetInt64(abs(iy));
result->Set(&spiral_center);
result->Add(&offset_x);
result->Sub(&offset_y);
spiral_angle += 0.1;
if(spiral_angle > 1000.0) {
spiral_angle = 0.0;
}
}
void get_next_key_auto(Int *result, Int *range_start, Int *range_end) {
auto_cycles++;
if(auto_cycles >= AUTO_PHASE_CYCLES[auto_phase]) {
auto_cycles = 0;
auto_phase = (auto_phase + 1) % 4;
if(FLAGQUIET == 0) {
const char *phase_names[] = {"SPIRAL", "CHAOS", "GRAVITY", "REVERSE"};
printf("\r[+] Auto: switching to %s phase \r", phase_names[auto_phase]);
fflush(stdout);
}
}
switch(auto_phase) {
case 0: get_next_key_spiral(result, range_start, range_end); break;
case 1: get_next_key_chaos(result, range_start, range_end); break;
case 2: get_next_key_gravity(result, range_start, range_end); break;
case 3: result->Rand(range_start, range_end); break;
}
}
void get_next_search_key(Int *result, Int *range_start, Int *range_end) {
if(g_research.submode == RSUB_WIF_MASK) {
uint8_t raw[32];
if(!research_wif_mask_next(&g_milksad_cursor, raw)) {
result->Set(range_end);
return;
}
result->Set32Bytes(raw);
return;
}
if(g_research.submode == RSUB_HEX_MASK ||
(g_research.key_mask[0] && g_research.submode != RSUB_MILKSAD &&
g_research.submode != RSUB_WIF_MASK)) {
uint8_t raw[32];
if(!research_hex_mask_next(&g_milksad_cursor, raw)) {
result->Set(range_end);
return;
}
result->Set32Bytes(raw);
return;
}
if(g_research.submode == RSUB_PROFANITY || g_research.submode == RSUB_ANDROID_SR ||
g_research.submode == RSUB_RANDSTORM || g_research.submode == RSUB_TIMESTAMP_KEY) {
uint8_t raw[32];
research_weakrng_key(g_research.submode, g_milksad_cursor++, raw);
result->Set32Bytes(raw);
return;
}
if(g_research.submode == RSUB_MILKSAD && (g_research.milksad_t0 || g_research.milksad_t1)) {
uint64_t t0 = g_research.milksad_t0 ? g_research.milksad_t0 : 1;
uint64_t t1 = g_research.milksad_t1 ? g_research.milksad_t1 : (t0 + 0x100000000ULL);
if(t1 < t0) { uint64_t tmp = t0; t0 = t1; t1 = tmp; }
uint64_t cur = t0 + g_milksad_cursor;
if(cur > t1) { result->Set(range_end); return; }
uint8_t raw[32];
research_weakrng_key(RSUB_MILKSAD, g_milksad_cursor, raw);
result->Set32Bytes(raw);
g_milksad_cursor++;
return;
}
switch(FLAGSEARCHMODE) {
case SEARCHMODE_SEQUENTIAL:
result->Set(range_start);
break;
case SEARCHMODE_RANDOM:
case SEARCHMODE_RSEQ:
result->Rand(range_start, range_end);
break;
case SEARCHMODE_CHAOS:
get_next_key_chaos(result, range_start, range_end);
break;
case SEARCHMODE_GRAVITY:
get_next_key_gravity(result, range_start, range_end);
break;
case SEARCHMODE_SPIRAL:
get_next_key_spiral(result, range_start, range_end);
break;
case SEARCHMODE_REVERSE:
result->Rand(range_start, range_end);
break;
case SEARCHMODE_AUTO:
get_next_key_auto(result, range_start, range_end);
break;
case SEARCHMODE_HILBERT:
case SEARCHMODE_SOBOL:
case SEARCHMODE_HALTON:
case SEARCHMODE_DENSITY: {
double u = 0.0;
if(FLAGSEARCHMODE == SEARCHMODE_HILBERT) research_hilbert_u(g_lds_step++, &u);
else if(FLAGSEARCHMODE == SEARCHMODE_SOBOL) research_sobol_u(g_lds_step++, 0, &u);
else if(FLAGSEARCHMODE == SEARCHMODE_HALTON) {
/* van der Corput base-2 */
uint64_t n = ++g_lds_step;
double inv = 0.5, v = 0.0;
while(n) { if(n & 1ULL) v += inv; n >>= 1; inv *= 0.5; }
u = v;
} else if(FLAGSEARCHMODE == SEARCHMODE_DENSITY)
u = research_density_sample_u(g_lds_step++);
else research_hilbert_u(g_lds_step++, &u);
Int range_size; range_size.Set(range_end); range_size.Sub(range_start);
/* Map u into range via 53-bit fraction of range_size */
Int temp; temp.Set(&range_size);
/* crude: use low 64 of range if fits */
uint64_t rs = range_size.GetInt64();
if(rs == 0) { result->Rand(range_start, range_end); break; }
uint64_t off = (uint64_t)(u * (double)rs);
result->Set(range_start);
Int o; o.SetInt64(off);
result->Add(&o);
if(g_research.mod_step > 1) {
/* ResidueHerd: snap to k ≡ R (mod M) */
uint64_t k = result->GetInt64();
uint64_t M = g_research.mod_step;
uint64_t R = g_research.mod_rem % M;
k = k - (k % M) + R;
result->SetInt64(k);
}
break;
}
default: