From 24ff5fa1e24731e2425ea82ab22643c7f3a21640 Mon Sep 17 00:00:00 2001 From: Jonathan Toomim Date: Thu, 27 Aug 2020 01:57:18 -0700 Subject: [PATCH] Correct BIP34 height encodings for heights 1-16 --- cpu-miner.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cpu-miner.c b/cpu-miner.c index 46db161..394978b 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -468,12 +468,18 @@ static bool gbt_work_decode(const json_t *val, struct work *work) le32enc((uint32_t *)(cbtx+37), 0xffffffff); /* prev txout index */ cbtx_size = 43; /* BIP 34: height in coinbase */ - for (n = work->height; n; n >>= 8) { - cbtx[cbtx_size++] = n & 0xff; - if (n < 0x100 && n >= 0x80) - cbtx[cbtx_size++] = 0; + if (work->height >= 1 && work->height <= 16) { + /* Use OP_1-OP_16 to conform to Bitcoin's implementation. */ + cbtx[42] = work->height + 0x50; + cbtx[cbtx_size++] = 0x00; /* OP_0; pads to 2 bytes */ + } else { + for (n = work->height; n; n >>= 8) { + cbtx[cbtx_size++] = n & 0xff; + if (n < 0x100 && n >= 0x80) + cbtx[cbtx_size++] = 0; + } + cbtx[42] = cbtx_size - 43; } - cbtx[42] = cbtx_size - 43; cbtx[41] = cbtx_size - 42; /* scriptsig length */ le32enc((uint32_t *)(cbtx+cbtx_size), 0xffffffff); /* sequence */ cbtx_size += 4;