Skip to content
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ For Arch:

sudo pacman -Syu base-devel cmake pkgconf curl jansson libsodium libmicrohttpd psmisc

For Clear Linux:

sudo swupd bundle-add c-basic cmake pkgconf devpkg-curl devpkg-jansson devpkg-libsodium devpkg-libmicrohttpd psmisc

For FreeBSD:

sudo pkg install cmake pkgconf curl jansson libsodium libmicrohttpd argp-standalone libepoll-shim
Expand Down
1 change: 1 addition & 0 deletions src/datum_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ int datum_api_config_post(struct MHD_Connection * const connection, char * const
const char * const checkboxes = json_string_value(j_checkboxes);
const size_t checkboxes_len = json_string_length(j_checkboxes);
const char *p = checkboxes;
if (!p) p = "";
char buf[0x100];
while (p[0] != '\0') {
const char *p2 = strchr(p, ' ');
Expand Down
2 changes: 1 addition & 1 deletion src/datum_blocktemplates.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void *datum_gateway_template_thread(void *args) {
if (t && !datum_blocktemplates_abw_ready(t,
datum_protocol_is_active(),
datum_protocol_abw_required())) {
DLOG_DEBUG("Retaining current work until a BLAKE2b anti-withholding assignment is active");
DLOG_DEBUG("Retaining current work until an anti-withholding assignment is active");
t = NULL;
}

Expand Down
5 changes: 4 additions & 1 deletion src/datum_coinbaser.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ int datum_coinbaser_v2_parse(T_DATUM_STRATUM_JOB *s, unsigned char *coinbaser, i
// 0 outputs possible
DLOG_WARN("Coinbaser length is invalid (too short). Using default/empty");
s->available_coinbase_outputs_count = 0;
if (must_free) free(coinbaser);
return 0;
}

Expand All @@ -794,10 +795,11 @@ int datum_coinbaser_v2_parse(T_DATUM_STRATUM_JOB *s, unsigned char *coinbaser, i
if (cidx + 8 + 1 > cblen) {
DLOG_ERROR("Coinbaser length is invalid (mid-parsing). Using default/empty");
s->available_coinbase_outputs_count = 0;
if (must_free) free(coinbaser);
return 0;
}
outval = upk_u64le(coinbaser, cidx); cidx+=8;
if ((outval + tally) > s->coinbase_value) {
if (outval > s->coinbase_value - tally) {
// we can't include this value, since it would put us over our total available!
// this shouldn't happen, however...
break;
Expand All @@ -806,6 +808,7 @@ int datum_coinbaser_v2_parse(T_DATUM_STRATUM_JOB *s, unsigned char *coinbaser, i
if (slen < 2 || slen > 64 || cidx + slen > cblen) {
DLOG_ERROR("Script length (%d) is invalid. Using default/empty", slen);
s->available_coinbase_outputs_count = 0;
if (must_free) free(coinbaser);
return 0;
}

Expand Down
14 changes: 14 additions & 0 deletions src/datum_coinbaser_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ static void datum_blake2b_coinbase_limit_tests(void) {
datum_test(datum_stratum_coinbase_fit_to_template(1000, 0, &job) == 866);
}

static void datum_coinbaser_value_overflow_tests(void) {
T_DATUM_STRATUM_JOB job = {.coinbase_value = UINT64_C(5000000000)};
unsigned char response[] = {
1,
1, 0, 0, 0, 0, 0, 0, 0, 2, 0x51, 0x51,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 2, 0x51, 0x51,
};

datum_test(datum_coinbaser_v2_parse(&job, response, sizeof(response), false) == 1);
datum_test(job.available_coinbase_outputs_count == 1);
datum_test(job.available_coinbase_outputs[0].value_sats == 1);
}

void datum_coinbaser_tests(void) {
datum_prime_id_64bit_tests();
datum_blake2b_coinbase_limit_tests();
datum_coinbaser_value_overflow_tests();
}
24 changes: 12 additions & 12 deletions src/datum_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ static bool datum_protocol_abw_mark_handled_exact(
int datum_protocol_abw_candidate_receipt(int len, unsigned char *data) {
if (len != 35 || data[0] != DATUM_ABW_DRAFT_REVISION ||
data[1] >= DATUM_ABW_ASSIGNMENT_SLOTS || data[34] != 0xFE) {
DLOG_ERROR("Invalid BLAKE2b anti-withholding candidate receipt");
DLOG_ERROR("Invalid anti-withholding candidate receipt");
return 0;
}
const uint8_t assignment_id = data[1] + 1;
Expand All @@ -1024,7 +1024,7 @@ int datum_protocol_abw_candidate_receipt(int len, unsigned char *data) {
int datum_protocol_abw_candidate_release(int len, unsigned char *data) {
if (len != 35 || data[0] != DATUM_ABW_DRAFT_REVISION ||
data[1] >= DATUM_ABW_ASSIGNMENT_SLOTS || data[34] != 0xFE) {
DLOG_ERROR("Invalid BLAKE2b anti-withholding candidate release");
DLOG_ERROR("Invalid anti-withholding candidate release");
return 0;
}
if (!datum_config.mining_abw_verify_all_shares_on_disclosure) {
Expand All @@ -1036,7 +1036,7 @@ int datum_protocol_abw_candidate_release(int len, unsigned char *data) {
int datum_protocol_abw_activation(int len, unsigned char *data) {
if (len != 3 || data[0] != DATUM_ABW_DRAFT_REVISION ||
data[1] >= DATUM_ABW_ASSIGNMENT_SLOTS || data[2] != 0xFE) {
DLOG_ERROR("Invalid BLAKE2b anti-withholding activation");
DLOG_ERROR("Invalid anti-withholding activation");
return 0;
}
const uint8_t assignment_id = data[1] + 1;
Expand All @@ -1059,7 +1059,7 @@ int datum_protocol_abw_assignment_notice(int len, unsigned char *data) {
if (len != 36 || data[0] != DATUM_ABW_DRAFT_REVISION ||
(data[1] & ~DATUM_ABW_ASSIGNMENT_ACTIVE) ||
data[2] >= DATUM_ABW_ASSIGNMENT_SLOTS || data[35] != 0xFE) {
DLOG_ERROR("Invalid BLAKE2b anti-withholding assignment notice");
DLOG_ERROR("Invalid anti-withholding assignment notice");
return 0;
}
const uint8_t assignment_id = data[2] + 1;
Expand All @@ -1072,7 +1072,7 @@ int datum_protocol_abw_assignment_notice(int len, unsigned char *data) {
}
pthread_mutex_unlock(&datum_abw_mutex);
if (!installed) {
DLOG_ERROR("Could not retain BLAKE2b anti-withholding assignment");
DLOG_ERROR("Could not retain anti-withholding assignment");
}
if (installed && (data[1] & DATUM_ABW_ASSIGNMENT_ACTIVE)) {
datum_blocktemplates_notifynew(NULL, 0);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ int datum_protocol_abw_reveal(int len, unsigned char *data) {
if (len != 19 || data[0] != DATUM_ABW_DRAFT_REVISION ||
data[18] != 0xFE || data[1] >= DATUM_ABW_ASSIGNMENT_SLOTS ||
!datum_blake2b_xor_key_hash(key_hash, data + 2)) {
DLOG_ERROR("Invalid BLAKE2b anti-withholding reveal");
DLOG_ERROR("Invalid anti-withholding reveal");
return 0;
}
const uint8_t assignment_id = data[1] + 1;
Expand All @@ -1165,7 +1165,7 @@ int datum_protocol_abw_reveal(int len, unsigned char *data) {
}
pthread_mutex_unlock(&datum_abw_mutex);
if (has_pending) {
DLOG_ERROR("BLAKE2b anti-withholding reveal has proofs without a commitment");
DLOG_ERROR("Anti-withholding reveal has proofs without a commitment");
return 0;
}
DLOG_DEBUG("Ignored disclosure for an ABW slot not held by this session");
Expand All @@ -1177,7 +1177,7 @@ int datum_protocol_abw_reveal(int len, unsigned char *data) {
assignment_id, key_hash);
pthread_mutex_unlock(&datum_abw_mutex);
if (!commitment_matched) {
DLOG_ERROR("BLAKE2b anti-withholding reveal did not match its commitment");
DLOG_ERROR("Anti-withholding reveal did not match its commitment");
return 0;
}
size_t submitted = 0;
Expand All @@ -1201,15 +1201,15 @@ int datum_protocol_abw_reveal(int len, unsigned char *data) {
}
if (!datum_submitblock_trigger_owned(block_request, block_hash)) {
free(block_request);
DLOG_ERROR("Could not queue a revealed BLAKE2b block for local submission");
DLOG_ERROR("Could not queue a revealed block for local submission");
continue;
}
submitted++;
DLOG_WARN("DATUM server revealed a verified BLAKE2b block key for candidate %s",
DLOG_WARN("DATUM server revealed a verified block key for candidate %s",
block_hash);
}
if (!submitted) {
DLOG_INFO("DATUM server retired BLAKE2b assignment slot %u",
DLOG_INFO("DATUM server retired ABW assignment slot %u",
(unsigned)(assignment_id - 1));
}
if (retired_active) datum_blocktemplates_notifynew(NULL, 0);
Expand Down Expand Up @@ -2670,7 +2670,7 @@ int datum_protocol_pow_submit(
}
if (pow.abw_assignment_id && !datum_protocol_abw_cache_candidate(
&pow, full_cb_tx, full_cb_tx_size, raw_pow_hash)) {
DLOG_ERROR("BLAKE2b anti-withholding candidate cache is full");
DLOG_ERROR("Anti-withholding candidate cache is full");
return -1;
}

Expand Down
Loading
Loading