Skip to content

Commit 9a3b9b9

Browse files
committed
Enforce PAK checks on dynafed proposals
1 parent ffec609 commit 9a3b9b9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/primitives/pak.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class CPAKList
6161
**/
6262
bool ScriptHasValidPAKProof(const CScript& script, const uint256& genesis_hash, const CPAKList& paklist);
6363

64+
CPAKList CreatePAKListFromExtensionSpace(const std::vector<std::vector<unsigned char>>& extension_space);
65+
6466
CPAKList GetActivePAKList(const CBlockIndex* pblockindex, const Consensus::Params& params);
6567

6668
bool IsPAKValidOutput(const CTxOut& txout, const CPAKList& paklist);

src/validation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,16 @@ static bool ContextualCheckDynaFedHeader(const CBlockHeader& block, CValidationS
35183518
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
35193519
}
35203520
}
3521+
3522+
// When enforcing PAK, extension_space must give non-empty PAK list when
3523+
// the vector itself is non-empty. Otherwise this means there were "junk"
3524+
// entries
3525+
if (params.GetEnforcePak()) {
3526+
if (!proposed.m_extension_space.empty() &&
3527+
CreatePAKListFromExtensionSpace(proposed.m_extension_space).IsReject()) {
3528+
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Extension space is not list of valid PAK entries");
3529+
}
3530+
}
35213531
}
35223532
return true;
35233533
}

test/functional/feature_dynafed.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def test_illegal_proposals(self):
133133
assert_raises_rpc_error(-1, "invalid-dyna-fed, proposed signblockscript must be native segwit scriptPubkey", self.nodes[0].getnewblockhex, 0, {"signblockscript":"51", "max_block_witness":100, "fedpegscript":"51", "extension_space":[]})
134134
assert_raises_rpc_error(-1, "invalid-dyna-fed, proposed signblockscript must be native segwit scriptPubkey", self.nodes[0].getnewblockhex, 0, {"signblockscript":"00"+WSH_OP_TRUE, "max_block_witness":100, "fedpegscript":"51", "extension_space":[]})
135135

136+
# Since we're enforcing PAK, extension space entries *must* be 66 bytes
137+
# each 33 of which are serialized compressed pubkeys
138+
assert_raises_rpc_error(-1, "invalid-dyna-fed, Extension space is not list of valid PAK entries", self.nodes[0].getnewblockhex, 0, {"signblockscript":WSH_OP_TRUE, "max_block_witness":100, "fedpegscript":"51", "extension_space":["00"]})
139+
assert_raises_rpc_error(-1, "invalid-dyna-fed, Extension space is not list of valid PAK entries", self.nodes[0].getnewblockhex, 0, {"signblockscript":WSH_OP_TRUE, "max_block_witness":100, "fedpegscript":"51", "extension_space":["", initial_extension[0]]})
140+
136141
def test_no_vote(self):
137142
self.log.info("Testing no-vote epoch...")
138143
go_to_epoch_end(self.nodes[0])
@@ -360,7 +365,7 @@ def test_transition_mempool_eject(self):
360365

361366
# Now have node 1 transition to new pak and fedpegscript
362367
pak_prop["fedpegscript"] = "52"
363-
pak_prop["extension_space"] = ["deadbeef"]
368+
pak_prop["extension_space"] = initial_extension
364369
for _ in range(10):
365370
raw_pool = self.nodes[0].getrawmempool()
366371
assert claim_id in raw_pool

0 commit comments

Comments
 (0)