From 2d6a261ffb448f8dc20574f6456a94e012865316 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 1 May 2015 00:12:04 +1000 Subject: [PATCH 1/5] Increase version to 0.8.8 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b5f51ef0..41f9e748 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(ckpool, 0.8.7, kernel@kolivas.org) +AC_INIT(ckpool, 0.8.8, kernel@kolivas.org) AC_CANONICAL_SYSTEM AC_CONFIG_MACRO_DIR([m4]) From b66f207a9fac0373570a218cad70b73b0212c90e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 15 Jun 2015 14:44:16 +1000 Subject: [PATCH 2/5] Add a braindead check to avoid trying to generate to a script address --- src/stratifier.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/stratifier.c b/src/stratifier.c index c18ed5d0..3a2e0246 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -4456,6 +4456,13 @@ static void read_poolstats(ckpool_t *ckp) } } +/* Braindead check to see if this btcaddress is an M of N script address which + * is currently unsupported as a generation address. */ +static bool script_address(const char *btcaddress) +{ + return btcaddress[0] == '3'; +} + int stratifier(proc_instance_t *pi) { pthread_t pth_blockupdate, pth_statsupdate, pth_heartbeat; @@ -4483,6 +4490,10 @@ int stratifier(proc_instance_t *pi) LOGEMERG("Fatal: btcaddress invalid according to bitcoind"); goto out; } + if (script_address(ckp->btcaddress)) { + LOGEMERG("Fatal: btcaddress valid but unsupported M of N 3x address"); + goto out; + } /* Store this for use elsewhere */ hex2bin(scriptsig_header_bin, scriptsig_header, 41); From 6cd2778477913176da4fe0d608932ffcff34f82b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 15 Jun 2015 15:55:23 +1000 Subject: [PATCH 3/5] Add a helper function for converting an M of N script address to a transaction --- src/libckpool.c | 15 ++++++++++++--- src/libckpool.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 09bfa9a2..beccb011 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1503,7 +1503,7 @@ static const int b58tobin_tbl[] = { 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 }; -/* b58bin should always be at least 25 bytes long and already checked to be +/* b58bin should always be at least 21 bytes long and already checked to be * valid. */ void b58tobin(char *b58bin, const char *b58) { @@ -1619,9 +1619,8 @@ char *http_base64(const char *src) void address_to_pubkeytxn(char *pkh, const char *addr) { - char b58bin[25]; + char b58bin[25] = {}; - memset(b58bin, 0, 25); b58tobin(b58bin, addr); pkh[0] = 0x76; pkh[1] = 0xa9; @@ -1631,6 +1630,16 @@ void address_to_pubkeytxn(char *pkh, const char *addr) pkh[24] = 0xac; } +void address_to_scripttxn(char *pkh, const char *addr) +{ + char b58bin[23] = {}; + + b58tobin(b58bin, addr); + pkh[0] = 0xa9; + memcpy(&pkh[1], &b58bin[1], 20); + pkh[22] = 0x87; +} + /* For encoding nHeight into coinbase, return how many bytes were used */ int ser_number(uchar *s, int32_t val) { diff --git a/src/libckpool.h b/src/libckpool.h index 0180606c..dc28e18d 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -537,6 +537,7 @@ int safecmp(const char *a, const char *b); bool cmdmatch(const char *buf, const char *cmd); void address_to_pubkeytxn(char *pkh, const char *addr); +void address_to_scripttxn(char *pkh, const char *addr); int ser_number(uchar *s, int32_t val); int get_sernumber(uchar *s); bool fulltest(const uchar *hash, const uchar *target); From 2aa93069cc76117e1c5474847ac3d0944e95da12 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 15 Jun 2015 16:14:51 +1000 Subject: [PATCH 4/5] Implement rudimentary untested address to script transaction support in the generation code --- src/libckpool.c | 4 ++-- src/stratifier.c | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index beccb011..25b5389c 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1503,7 +1503,7 @@ static const int b58tobin_tbl[] = { 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 }; -/* b58bin should always be at least 21 bytes long and already checked to be +/* b58bin should always be at least 24 bytes long and already checked to be * valid. */ void b58tobin(char *b58bin, const char *b58) { @@ -1632,7 +1632,7 @@ void address_to_pubkeytxn(char *pkh, const char *addr) void address_to_scripttxn(char *pkh, const char *addr) { - char b58bin[23] = {}; + char b58bin[25] = {}; b58tobin(b58bin, addr); pkh[0] = 0xa9; diff --git a/src/stratifier.c b/src/stratifier.c index 3a2e0246..0d3382de 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -330,7 +330,9 @@ static const char *ckdb_seq_names[] = { struct stratifier_data { char pubkeytxnbin[25]; + int pubkeytxnlen; char donkeytxnbin[25]; + int donkeytxnlen; pool_stats_t stats; /* Protects changes to pool stats */ @@ -542,18 +544,18 @@ static void generate_coinbase(const ckpool_t *ckp, workbase_t *wb) *u64 = htole64(g64); wb->coinb2len += 8; - wb->coinb2bin[wb->coinb2len++] = 25; - memcpy(wb->coinb2bin + wb->coinb2len, sdata->pubkeytxnbin, 25); - wb->coinb2len += 25; + wb->coinb2bin[wb->coinb2len++] = sdata->pubkeytxnlen; + memcpy(wb->coinb2bin + wb->coinb2len, sdata->pubkeytxnbin, sdata->pubkeytxnlen); + wb->coinb2len += sdata->pubkeytxnlen; if (ckp->donvalid) { u64 = (uint64_t *)&wb->coinb2bin[wb->coinb2len]; *u64 = htole64(d64); wb->coinb2len += 8; - wb->coinb2bin[wb->coinb2len++] = 25; - memcpy(wb->coinb2bin + wb->coinb2len, sdata->donkeytxnbin, 25); - wb->coinb2len += 25; + wb->coinb2bin[wb->coinb2len++] = sdata->donkeytxnlen; + memcpy(wb->coinb2bin + wb->coinb2len, sdata->donkeytxnbin, sdata->donkeytxnlen); + wb->coinb2len += sdata->donkeytxnlen; } wb->coinb2len += 4; // Blank lock @@ -4490,18 +4492,26 @@ int stratifier(proc_instance_t *pi) LOGEMERG("Fatal: btcaddress invalid according to bitcoind"); goto out; } - if (script_address(ckp->btcaddress)) { - LOGEMERG("Fatal: btcaddress valid but unsupported M of N 3x address"); - goto out; - } /* Store this for use elsewhere */ hex2bin(scriptsig_header_bin, scriptsig_header, 41); - address_to_pubkeytxn(sdata->pubkeytxnbin, ckp->btcaddress); + if (script_address(ckp->btcaddress)) { + address_to_scripttxn(sdata->pubkeytxnbin, ckp->btcaddress); + sdata->pubkeytxnlen = 23; + } else { + address_to_pubkeytxn(sdata->pubkeytxnbin, ckp->btcaddress); + sdata->pubkeytxnlen = 25; + } if (test_address(ckp, ckp->donaddress)) { ckp->donvalid = true; - address_to_pubkeytxn(sdata->donkeytxnbin, ckp->donaddress); + if (script_address(ckp->donaddress)) { + sdata->donkeytxnlen = 23; + address_to_scripttxn(sdata->donkeytxnbin, ckp->donaddress); + } else { + sdata->donkeytxnlen = 25; + address_to_pubkeytxn(sdata->donkeytxnbin, ckp->donaddress); + } } } From 39e1e07749b8835258e68ab89ce91c59871114ca Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 15 Jun 2015 16:33:44 +1000 Subject: [PATCH 5/5] Add push 20 bytes to stack in address_to_scripttxn --- src/libckpool.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 25b5389c..398b1a1c 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1503,7 +1503,7 @@ static const int b58tobin_tbl[] = { 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 }; -/* b58bin should always be at least 24 bytes long and already checked to be +/* b58bin should always be at least 25 bytes long and already checked to be * valid. */ void b58tobin(char *b58bin, const char *b58) { @@ -1636,7 +1636,8 @@ void address_to_scripttxn(char *pkh, const char *addr) b58tobin(b58bin, addr); pkh[0] = 0xa9; - memcpy(&pkh[1], &b58bin[1], 20); + pkh[1] = 0x14; + memcpy(&pkh[2], &b58bin[1], 20); pkh[22] = 0x87; }