Skip to content

Commit 1122fc2

Browse files
committed
Add dynafed proposal restrictions
1 parent 69e881a commit 1122fc2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/validation.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,6 +3485,40 @@ static bool ContextualCheckDynaFedHeader(const CBlockHeader& block, CValidationS
34853485
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "dynamic block header's current parameters do not match expected");
34863486
}
34873487

3488+
// Lastly, enforce rules on proposals.
3489+
const DynaFedParamEntry& proposed = dynafed_params.m_proposed;
3490+
if (!proposed.IsNull()) {
3491+
3492+
// signblockscript proposals *must* be segwit versions
3493+
int block_version = 0;
3494+
std::vector<unsigned char> block_program;
3495+
if (!proposed.m_signblockscript.IsWitnessProgram(block_version, block_program)) {
3496+
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed signblockscript must be native segwit scriptPubkey");
3497+
}
3498+
3499+
int fedpeg_version = 0;
3500+
std::vector<unsigned char> fedpeg_program;
3501+
if (!proposed.m_fedpegscript.IsWitnessProgram(fedpeg_version, fedpeg_program)) {
3502+
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed fedpegscript must be native segwit scriptPubkey");
3503+
}
3504+
3505+
// for v0, fedpegscript's scriptPubKey must match. v1+ is unencumbered.
3506+
if (fedpeg_version == 0) {
3507+
CScript computed_program = CScript() << ToByteVector(WitnessV0ScriptHash(proposed.m_fedpegscript));
3508+
if (computed_program != proposed.m_fedpeg_program) {
3509+
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed v0 segwit fedpegscript must match proposed fedpeg witness program");
3510+
}
3511+
3512+
// fedpegscript proposals *must not* start with OP_DEPTH
3513+
// This forbids the first Liquid watchman script which is a hack.
3514+
// Use miniscript, which doesn't even have OP_DEPTH.
3515+
// We don't encumber future segwit versions as opcodes may change.
3516+
if (!proposed.m_fedpegscript.empty() &&
3517+
proposed.m_fedpegscript.front() == OP_DEPTH) {
3518+
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
3519+
}
3520+
}
3521+
}
34883522
return true;
34893523
}
34903524

0 commit comments

Comments
 (0)