Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
365df024bc | ||
|
|
c7388aacf8 | ||
|
|
c1392f15be | ||
|
|
05a975a424 | ||
|
|
cf68e084fe | ||
|
|
b2dda538c8 | ||
|
|
366b8bc358 | ||
|
|
2049056cfd | ||
|
|
721ce42f57 | ||
|
|
c7a1c1278b | ||
|
|
c2785585dc | ||
|
|
f94c40ff5c | ||
|
|
498221e0b1 | ||
|
|
76db08733f |
19
blkmaker.c
19
blkmaker.c
@ -170,20 +170,19 @@ static int64_t blktxn_set_gentx_weight(struct blktxn_t * const gentx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
|
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
|
||||||
if (tmpl->cbtxn && !(*inout_newcb && (tmpl->mutations & BMM_GENERATE)))
|
const bool replace_existing = *inout_newcb;
|
||||||
|
*inout_newcb = false;
|
||||||
|
|
||||||
|
if (tmpl->cbtxn && !(replace_existing && (tmpl->mutations & BMM_GENERATE)))
|
||||||
{
|
{
|
||||||
*inout_newcb = false;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tmpl->cbvalue) {
|
if (!tmpl->has_cbvalue) {
|
||||||
// TODO: Figure it out from the existing cbtxn
|
// TODO: Figure it out from the existing cbtxn
|
||||||
*inout_newcb = false;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*inout_newcb = true;
|
|
||||||
|
|
||||||
if (scriptsz >= 0xfd)
|
if (scriptsz >= 0xfd)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -280,6 +279,7 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
|
|||||||
|
|
||||||
tmpl->mutations |= BMM_CBAPPEND | BMM_CBSET | BMM_GENERATE;
|
tmpl->mutations |= BMM_CBAPPEND | BMM_CBSET | BMM_GENERATE;
|
||||||
|
|
||||||
|
*inout_newcb = true;
|
||||||
return tmpl->cbvalue;
|
return tmpl->cbvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,6 +545,9 @@ ssize_t blkmk_append_coinbase_safe2(blktemplate_t * const tmpl, const void * con
|
|||||||
if (extranoncesz < sizeof(unsigned int))
|
if (extranoncesz < sizeof(unsigned int))
|
||||||
extranoncesz = sizeof(unsigned int);
|
extranoncesz = sizeof(unsigned int);
|
||||||
}
|
}
|
||||||
|
if (tmpl->cbtxn->datasz <= cbScriptSigLen || tmpl->cbtxn->datasz <= cbScriptSigLen + tmpl->cbtxn->data[cbScriptSigLen]) {
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
if (extranoncesz > libblkmaker_coinbase_size_limit || tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit || extranoncesz + tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit) {
|
if (extranoncesz > libblkmaker_coinbase_size_limit || tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit || extranoncesz + tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit) {
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
@ -795,7 +798,9 @@ bool blkmk_get_mdata(blktemplate_t * const tmpl, void * const buf, const size_t
|
|||||||
free(*out_cbtxn);
|
free(*out_cbtxn);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memcpy(*out_branches, tmpl->_mrklbranch, branches_bytesz);
|
if (branches_bytesz) {
|
||||||
|
memcpy(*out_branches, tmpl->_mrklbranch, branches_bytesz);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BLKMAKER_VERSION (7L)
|
#define BLKMAKER_VERSION (8L)
|
||||||
#define BLKMAKER_MAX_BLOCK_VERSION (0x3fffffff)
|
#define BLKMAKER_MAX_BLOCK_VERSION (0x3fffffff)
|
||||||
#define BLKMAKER_MAX_PRERULES_BLOCK_VERSION (4)
|
#define BLKMAKER_MAX_PRERULES_BLOCK_VERSION (4)
|
||||||
|
|
||||||
|
|||||||
@ -416,7 +416,14 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
|||||||
return "Unrecognized block version, and not allowed to reduce or force it";
|
return "Unrecognized block version, and not allowed to reduce or force it";
|
||||||
}
|
}
|
||||||
|
|
||||||
GETNUM_O2(cbvalue, coinbasevalue, uint64_t);
|
if ((v = json_object_get(json, "coinbasevalue")) && json_is_number(v)) {
|
||||||
|
const double tmpd = json_number_value(v);
|
||||||
|
const uint64_t tmp = tmpd;
|
||||||
|
if (tmpd == tmp) {
|
||||||
|
tmpl->has_cbvalue = true;
|
||||||
|
tmpl->cbvalue = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GETSTR(workid, workid);
|
GETSTR(workid, workid);
|
||||||
|
|
||||||
@ -464,7 +471,7 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
|||||||
tmpl->cbtxn = calloc(1, sizeof(*tmpl->cbtxn));
|
tmpl->cbtxn = calloc(1, sizeof(*tmpl->cbtxn));
|
||||||
if ((s = parse_txn(tmpl->cbtxn, v, 0)))
|
if ((s = parse_txn(tmpl->cbtxn, v, 0)))
|
||||||
return s;
|
return s;
|
||||||
} else if (!tmpl->cbvalue) {
|
} else if (!tmpl->has_cbvalue) {
|
||||||
return "Missing either coinbasetxn or coinbasevalue";
|
return "Missing either coinbasetxn or coinbasevalue";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -158,6 +158,8 @@ typedef struct {
|
|||||||
libblkmaker_hash_t *_witnessmrklroot;
|
libblkmaker_hash_t *_witnessmrklroot;
|
||||||
int64_t weightlimit;
|
int64_t weightlimit;
|
||||||
int64_t txns_weight;
|
int64_t txns_weight;
|
||||||
|
|
||||||
|
bool has_cbvalue;
|
||||||
} blktemplate_t;
|
} blktemplate_t;
|
||||||
|
|
||||||
extern void blktxn_init(struct blktxn_t *);
|
extern void blktxn_init(struct blktxn_t *);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ dnl * under the terms of the standard MIT license. See COPYING for more details
|
|||||||
|
|
||||||
AC_INIT(
|
AC_INIT(
|
||||||
[libblkmaker],
|
[libblkmaker],
|
||||||
[0.5.3],
|
[0.6.0],
|
||||||
[luke_libblkmaker@dashjr.org],
|
[luke_libblkmaker@dashjr.org],
|
||||||
[libblkmaker],
|
[libblkmaker],
|
||||||
[http://gitorious.org/bitcoin/libblkmaker])
|
[http://gitorious.org/bitcoin/libblkmaker])
|
||||||
@ -19,7 +19,7 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
|||||||
LT_INIT([disable-static])
|
LT_INIT([disable-static])
|
||||||
|
|
||||||
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
||||||
AC_SUBST([LIBBLKMAKER_SO_VERSION], [7:0:1])
|
AC_SUBST([LIBBLKMAKER_SO_VERSION], [8:0:0])
|
||||||
AC_SUBST([LIBBLKMAKER_API_VERSION], [0.1])
|
AC_SUBST([LIBBLKMAKER_API_VERSION], [0.1])
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Name: @PACKAGE_NAME@_jansson
|
|||||||
Description: Bitcoin block maker library.
|
Description: Bitcoin block maker library.
|
||||||
Version: @PACKAGE_VERSION@
|
Version: @PACKAGE_VERSION@
|
||||||
URL: @PACKAGE_URL@
|
URL: @PACKAGE_URL@
|
||||||
Libs: -L${libdir} -lblkmaker-@LIBBLKMAKER_API_VERSION@ -lblkmaker_jansson-@LIBBLKMAKER_API_VERSION@
|
Libs: -L${libdir} -lblkmaker_jansson-@LIBBLKMAKER_API_VERSION@ -lblkmaker-@LIBBLKMAKER_API_VERSION@
|
||||||
Cflags: -I${includedir}/libblkmaker-@LIBBLKMAKER_API_VERSION@
|
Cflags: -I${includedir}/libblkmaker-@LIBBLKMAKER_API_VERSION@
|
||||||
|
Requires: jansson
|
||||||
Requires.private: libbase58
|
Requires.private: libbase58
|
||||||
|
|||||||
44
test.c
44
test.c
@ -219,6 +219,7 @@ static void blktmpl_jansson_simple() {
|
|||||||
assert(tmpl->prevblk[i] == 0x77777777);
|
assert(tmpl->prevblk[i] == 0x77777777);
|
||||||
}
|
}
|
||||||
assert(!tmpl->prevblk[7]);
|
assert(!tmpl->prevblk[7]);
|
||||||
|
assert(tmpl->has_cbvalue);
|
||||||
assert(tmpl->cbvalue == 512);
|
assert(tmpl->cbvalue == 512);
|
||||||
|
|
||||||
// Check clear values
|
// Check clear values
|
||||||
@ -249,6 +250,13 @@ static void blktmpl_jansson_simple() {
|
|||||||
blktmpl_free(tmpl);
|
blktmpl_free(tmpl);
|
||||||
tmpl = blktmpl_create();
|
tmpl = blktmpl_create();
|
||||||
|
|
||||||
|
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":2,\"height\":3,\"bits\":\"1d00ffff\",\"curtime\":777,\"previousblockhash\":\"0000000077777777777777777777777777777777777777777777777777777777\",\"coinbasevalue\":0}", simple_time_rcvd));
|
||||||
|
assert(tmpl->has_cbvalue);
|
||||||
|
assert(tmpl->cbvalue == 0);
|
||||||
|
|
||||||
|
blktmpl_free(tmpl);
|
||||||
|
tmpl = blktmpl_create();
|
||||||
|
|
||||||
assert(blktmpl_add_jansson_str(tmpl, "{\"height\":3,\"bits\":\"1d00ffff\",\"curtime\":777,\"previousblockhash\":\"0000000077777777777777777777777777777777777777777777777777777777\",\"coinbasevalue\":512}", simple_time_rcvd));
|
assert(blktmpl_add_jansson_str(tmpl, "{\"height\":3,\"bits\":\"1d00ffff\",\"curtime\":777,\"previousblockhash\":\"0000000077777777777777777777777777777777777777777777777777777777\",\"coinbasevalue\":512}", simple_time_rcvd));
|
||||||
blktmpl_free(tmpl);
|
blktmpl_free(tmpl);
|
||||||
tmpl = blktmpl_create();
|
tmpl = blktmpl_create();
|
||||||
@ -287,6 +295,7 @@ static void blktmpl_jansson_bip22_required() {
|
|||||||
assert(tmpl->prevblk[i] == 0xa7777777);
|
assert(tmpl->prevblk[i] == 0xa7777777);
|
||||||
}
|
}
|
||||||
assert(!tmpl->prevblk[7]);
|
assert(!tmpl->prevblk[7]);
|
||||||
|
assert(tmpl->has_cbvalue);
|
||||||
assert(tmpl->cbvalue == 640);
|
assert(tmpl->cbvalue == 640);
|
||||||
assert(tmpl->sigoplimit == 100);
|
assert(tmpl->sigoplimit == 100);
|
||||||
assert(tmpl->sizelimit == 1000);
|
assert(tmpl->sizelimit == 1000);
|
||||||
@ -475,6 +484,7 @@ static void test_blktmpl_jansson_floaty() {
|
|||||||
assert(tmpl->prevblk[i] == 0x77777777);
|
assert(tmpl->prevblk[i] == 0x77777777);
|
||||||
}
|
}
|
||||||
assert(!tmpl->prevblk[7]);
|
assert(!tmpl->prevblk[7]);
|
||||||
|
assert(tmpl->has_cbvalue);
|
||||||
assert(tmpl->cbvalue == 512);
|
assert(tmpl->cbvalue == 512);
|
||||||
|
|
||||||
assert(tmpl->txncount == 2);
|
assert(tmpl->txncount == 2);
|
||||||
@ -534,6 +544,7 @@ static void test_blktmpl_jansson_floaty() {
|
|||||||
assert(tmpl->prevblk[i] == 0x77777777);
|
assert(tmpl->prevblk[i] == 0x77777777);
|
||||||
}
|
}
|
||||||
assert(!tmpl->prevblk[7]);
|
assert(!tmpl->prevblk[7]);
|
||||||
|
assert(!tmpl->has_cbvalue);
|
||||||
assert(!tmpl->cbvalue);
|
assert(!tmpl->cbvalue);
|
||||||
|
|
||||||
assert(tmpl->expires == 33);
|
assert(tmpl->expires == 33);
|
||||||
@ -1122,6 +1133,7 @@ static void test_blkmk_init_generation() {
|
|||||||
assert(!blkmk_init_generation(tmpl, NULL, 0));
|
assert(!blkmk_init_generation(tmpl, NULL, 0));
|
||||||
tmpl->height = 4;
|
tmpl->height = 4;
|
||||||
assert(blkmk_init_generation(tmpl, NULL, 0) == 640);
|
assert(blkmk_init_generation(tmpl, NULL, 0) == 640);
|
||||||
|
tmpl->has_cbvalue = false;
|
||||||
tmpl->cbvalue = 0;
|
tmpl->cbvalue = 0;
|
||||||
newcb = true;
|
newcb = true;
|
||||||
// Unknown cbvalue needs to either fail, or figure it out from an existing cbtxn (which we don't support yet)
|
// Unknown cbvalue needs to either fail, or figure it out from an existing cbtxn (which we don't support yet)
|
||||||
@ -1237,6 +1249,38 @@ static void test_blkmk_append_coinbase_safe() {
|
|||||||
assert(blkmk_init_generation3(tmpl, NULL, 0, &newcb));
|
assert(blkmk_init_generation3(tmpl, NULL, 0, &newcb));
|
||||||
assert(blkmk_append_coinbase_safe2(tmpl, "\x05" "testx", 6, 0, true) == 5);
|
assert(blkmk_append_coinbase_safe2(tmpl, "\x05" "testx", 6, 0, true) == 5);
|
||||||
|
|
||||||
|
blktmpl_free(tmpl);
|
||||||
|
tmpl = blktmpl_create();
|
||||||
|
|
||||||
|
// Gen tx is cut off immediately after the coinbase.
|
||||||
|
// We don't *really* care that this works since it's not Bitcoin, but we need to make sure it doesn't corrupt memory or crash
|
||||||
|
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07010404deadbeef\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
|
||||||
|
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) >= 1);
|
||||||
|
assert(tmpl->cbtxn);
|
||||||
|
assert(tmpl->cbtxn->datasz == 50);
|
||||||
|
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff\x08\x01\x04\x04\xde\xad\xbe\xef\x58", tmpl->cbtxn->datasz));
|
||||||
|
|
||||||
|
blktmpl_free(tmpl);
|
||||||
|
tmpl = blktmpl_create();
|
||||||
|
|
||||||
|
// Gen tx is cut off INSIDE the coinbase.
|
||||||
|
// Again, we need to make sure it doesn't corrupt memory or crash
|
||||||
|
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07010404deadbe\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
|
||||||
|
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) <= 0);
|
||||||
|
assert(tmpl->cbtxn);
|
||||||
|
assert(tmpl->cbtxn->datasz == 48);
|
||||||
|
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff\x07\x01\x04\x04\xde\xad\xbe", tmpl->cbtxn->datasz));
|
||||||
|
|
||||||
|
blktmpl_free(tmpl);
|
||||||
|
tmpl = blktmpl_create();
|
||||||
|
|
||||||
|
// Gen tx is cut off BEFORE the coinbase
|
||||||
|
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
|
||||||
|
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) <= 0);
|
||||||
|
assert(tmpl->cbtxn);
|
||||||
|
assert(tmpl->cbtxn->datasz == 41);
|
||||||
|
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff", tmpl->cbtxn->datasz));
|
||||||
|
|
||||||
blktmpl_free(tmpl);
|
blktmpl_free(tmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user