Skip to content

Commit

Permalink
Solved Issue 56 , added mutex to bloom filter add function fro multhr…
Browse files Browse the repository at this point in the history
…ead add
  • Loading branch information
albertobsd committed Apr 20, 2021
1 parent 7fdf0d6 commit 0cb614f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Version development
# Version 0.1.20210420 secp256k1
- Solved Issues 49, 50 51
See:
https://github.com/albertobsd/keyhunt/issues/51
https://github.com/albertobsd/keyhunt/issues/50
https://github.com/albertobsd/keyhunt/issues/49


- Solved Issues 56 https://github.com/albertobsd/keyhunt/issues/56
- Added mutex to the bloom filter for multithread writing

# Version 0.1.20210412 secp256k1
- Full migration from libgmp to secp256k1
Expand Down
12 changes: 10 additions & 2 deletions bloom/bloom.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <inttypes.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>

#include "bloom.h"
#include "../xxhash/xxhash.h"
Expand Down Expand Up @@ -161,7 +162,11 @@ int bloom_check(struct bloom * bloom, const void * buffer, int len)

int bloom_add(struct bloom * bloom, const void * buffer, int len)
{
return bloom_check_add(bloom, buffer, len, 1);
int r;
pthread_mutex_lock(&bloom->mutex);
r =bloom_check_add(bloom, buffer, len, 1);
pthread_mutex_unlock(&bloom->mutex);
return r;
}


Expand Down Expand Up @@ -254,14 +259,17 @@ int bloom_savecustom(struct bloom * bloom, char * filename) {
if(fwrite(bloom,1,sizeof(struct bloom),fd_str) != sizeof(struct bloom) ) {
fclose(fd_str);
fclose(fd_dat);
fprintf(stderr,"fwrite bloom\n");
exit(0);
return 1;
}
if(fwrite(bloom->bf,1, bloom->bytes,fd_dat) !=bloom->bytes) {
fclose(fd_str);
fclose(fd_dat);
fprintf(stderr,"fwrite bloom->bf\n");
exit(0);
return 1;
}

fclose(fd_str);
fclose(fd_dat);
return 0;
Expand Down
1 change: 1 addition & 0 deletions bloom/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct bloom
uint8_t minor;
double bpe;
uint8_t *bf;
pthread_mutex_t mutex;
};
/*
Customs
Expand Down
18 changes: 13 additions & 5 deletions keyhunt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct tothread {
};

struct bPload {
int threadid;
uint32_t threadid;
uint64_t from;
uint64_t to;
uint64_t counter;
Expand Down Expand Up @@ -287,7 +287,7 @@ int main(int argc, char **argv) {
printf("-t tn\t\tThreads number, must be positive integer\n");
printf("-v va\t\tSearch for vanity Address, only with -m address\n");
printf("-w\t\tMark the input file as RAW data xpoint fixed 32 byte each point. Valid only with -m xpoint\n");
printf("-z\t\tSave and load bloom bloomfilter from File\n");
//printf("-z\t\tSave and load bloom bloomfilter from File\n");
printf("\t\tUse the hexcharstoraw tool to create a raw file from your current hexadecimal file\n");
printf("\nExample\n\n");
printf("%s -t 16 -r 00000001:FFFFFFFF -s 0\n\n",argv[0]);
Expand Down Expand Up @@ -530,6 +530,9 @@ int main(int argc, char **argv) {
}
if(FLAGRANGE) {
n_range_start.SetBase16(range_start);
if(n_range_start.IsZero()) {
n_range_start.AddOne();
}
n_range_end.SetBase16(range_end);
if(n_range_start.IsEqual(&n_range_end) == false ) {
if( n_range_start.IsLower(&secp->order) && n_range_end.IsLowerOrEqual(&secp->order) ) {
Expand Down Expand Up @@ -1288,24 +1291,26 @@ int main(int argc, char **argv) {
if(i < NTHREADS -1) {
temp[i].from = BASE +1;
temp[i].to = BASE + PERTHREAD;
BASE+=PERTHREAD;
}
else {
temp[i].from = BASE + 1;
temp[i].to = BASE + PERTHREAD + PERTHREAD_R;
BASE+=(PERTHREAD + PERTHREAD_R);
}
if(FLAGDEBUG) printf("[I] %lu to %lu\n",temp[i].from,temp[i].to);
s = pthread_create(&tid[i],NULL,thread_bPload,(void *)&temp[i]);
BASE+=PERTHREAD;
}
}
total_precalculated = 0;
do {
sleep_ms(100);
sleep(1);
total_precalculated = 0;
for(i = 0; i < NTHREADS; i++) {
total_precalculated+=temp[i].counter;
}
printf("\r[+] processing %lu/%lu bP points : %i%%",total_precalculated,bsgs_m,(int) (((double)total_precalculated/(double)bsgs_m)*100));
fflush(stdout);
} while(total_precalculated < bsgs_m);

for(i = 0; i < NTHREADS; i++) {
Expand Down Expand Up @@ -2622,6 +2627,9 @@ void *thread_bPload(void *vargp) {
j_counter = tt->from -1;

nbStep = (tt->to - (tt->from-1)) / CPU_GRP_SIZE;
if( ((tt->to - (tt->from-1)) % CPU_GRP_SIZE ) != 0) {
nbStep++;
}
km.Add((uint64_t)(CPU_GRP_SIZE / 2));
startP = secp->ComputePublicKey(&km);
grp->Set(dx);
Expand Down Expand Up @@ -2715,8 +2723,8 @@ void *thread_bPload(void *vargp) {
if(i_counter < tt->to) {
bloom_add(&bloom_bP[((uint8_t)rawvalue[0])], rawvalue ,BSGS_BUFFERXPOINTLENGTH);
tt->counter++;
i_counter++;
}
i_counter++;
}
// Next start point (startP + GRP_SIZE*G)
pp = startP;
Expand Down

0 comments on commit 0cb614f

Please sign in to comment.