Skip to content

Commit 4f15ea1

Browse files
committed
Check transaction count early in submitblock.
There is no point in even hashing a submitted block which doesn't have a coinbase transaction. This also results in more useful error reporting on corrupted input. Thanks to rawodb for the bug report.
1 parent ada0caa commit 4f15ea1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/rpc/mining.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ UniValue submitblock(const JSONRPCRequest& request)
744744
if (!DecodeHexBlk(block, request.params[0].get_str()))
745745
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
746746

747+
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
748+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase");
749+
}
750+
747751
uint256 hash = block.GetHash();
748752
bool fBlockPresent = false;
749753
{

0 commit comments

Comments
 (0)