Skip to content

Commit

Permalink
v 0.4.8 support for segwit/p2sh addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Mar 24, 2022
1 parent f46f144 commit 082c0a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions WifSolverCuda/lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,15 @@ int isValidHex(char* data) {
return valid;
}

void addressToBase58(char* rmd, char* dst) {
void addressToBase58(char* rmd, char* dst, bool p2sh) {
char digest[60];
size_t pubaddress_size = 40;
digest[0] = 0x00;
if (p2sh) {
digest[0] = 0x05;
}
else {
digest[0] = 0x00;
}
memcpy(digest + 1, rmd, 20);
sha256((uint8_t*)digest, 21, (uint8_t*)digest + 21);
sha256((uint8_t*)digest + 21, 32, (uint8_t*)digest + 21);
Expand Down
2 changes: 1 addition & 1 deletion WifSolverCuda/lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int isValidHex(char* data);
void freetokenizer(Tokenizer* t);
void stringtokenizer(char* data, Tokenizer* t);

void addressToBase58(char* rmd, char* dst);
void addressToBase58(char* rmd, char* dst, bool p2sh);

std::string formatDouble(const char* formatStr, double value);

Expand Down
15 changes: 12 additions & 3 deletions WifSolverCuda/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ string fileStatusRestore;
bool isRestore = false;

bool showDevices = false;
bool p2sh = false;

Secp256K1* secp;


int main(int argc, char** argv)
{
printf("WifSolver 0.4.7\n\n");
printf("WifSolver 0.4.8\n\n");

if (readArgs(argc, argv)) {
showHelp();
Expand Down Expand Up @@ -432,8 +433,13 @@ void processCandidate(Int &toTest) {
}
toTest.SetBase16((char*)toTest.GetBase16().substr(2, 64).c_str());
Point publickey = secp->ComputePublicKey(&toTest);
secp->GetHash160(P2PKH, COMPRESSED, publickey, (unsigned char*)rmdhash);
addressToBase58(rmdhash, address);
if (p2sh) {
secp->GetHash160(P2SH, true, publickey, (unsigned char*)rmdhash);
}
else {
secp->GetHash160(P2PKH, COMPRESSED, publickey, (unsigned char*)rmdhash);
}
addressToBase58(rmdhash, address, p2sh);
if (!TARGET_ADDRESS.empty()) {
if (TARGET_ADDRESS == address) {
RESULT = true;
Expand Down Expand Up @@ -629,6 +635,9 @@ bool readArgs(int argc, char** argv) {
else if (strcmp(argv[a], "-a") == 0) {
a++;
TARGET_ADDRESS = string(argv[a]);
if (argv[a][0] == '3') {
p2sh = true;
}
}
else if (strcmp(argv[a], "-checksum") == 0) {
a++;
Expand Down

0 comments on commit 082c0a3

Please sign in to comment.