Skip to content

Commit 1241343

Browse files
committed
testproposedblock: Reject blocks with non-matching pak commitments
1 parent 47ea638 commit 1241343

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/rpc/mining.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ UniValue testproposedblock(const JSONRPCRequest& request)
12541254
"\nChecks a block proposal for validity, and that it extends chaintip\n"
12551255
"\nArguments:\n"
12561256
"1. \"blockhex\" (string, required) The hex-encoded block from getnewblockhex\n"
1257-
"2. \"acceptnonstd\" (bool, optional) If set false, returns error if block contains non-standard transaction. Default is set via `-acceptnonstdtxn`\n"
1257+
"2. \"acceptnonstd\" (bool, optional) If set false, returns error if block contains non-standard transaction. Default is set via `-acceptnonstdtxn`. If PAK enforcement is set, block commitment mismatches with configuration PAK lists are rejected as well.\n"
12581258
"\nResult\n"
12591259
"\nExamples:\n"
12601260
+ HelpExampleCli("testproposedblock", "<hex>")
@@ -1287,6 +1287,25 @@ UniValue testproposedblock(const JSONRPCRequest& request)
12871287
const CChainParams& chainparams = Params();
12881288
const bool acceptnonstd = !request.params[1].isNull() ? request.params[1].get_bool() : gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
12891289
if (!acceptnonstd) {
1290+
1291+
// Get PAK commitment, if any
1292+
boost::optional<CPAKList> paklist_block = GetPAKKeysFromCommitment(*block.vtx[0]);
1293+
1294+
// Possible PAK commitment mismatch between blocks and config
1295+
if (chainparams.GetEnforcePak() && g_paklist_config) {
1296+
if(paklist_block) {
1297+
if (*paklist_block != *g_paklist_config) {
1298+
throw JSONRPCError(RPC_VERIFY_ERROR, "Proposal PAK commitment and config PAK do not match.");
1299+
}
1300+
// else it may be an unnecessary commitment but that's ok.
1301+
} else {
1302+
// Waiting for block that has commitment to config list
1303+
if (*g_paklist_config != g_paklist_blockchain) {
1304+
throw JSONRPCError(RPC_VERIFY_ERROR, "Proposal does not have required PAK commitment.");
1305+
}
1306+
}
1307+
}
1308+
12901309
for (auto& transaction : block.vtx) {
12911310
if (transaction->IsCoinBase()) continue;
12921311
std::string reason;

0 commit comments

Comments
 (0)