Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elements-0.18] Some minor dynafed improvements #962

Merged
merged 3 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,10 @@ class CLiquidV1Params : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;

// Not active yet.
// Activated from block 1,000,000.
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].bit = 25;
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nStartTime = 1000000;
// Allow blocksigners to delay activation.
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nStartTime = gArgs.GetArg("-con_dyna_deploy_start", 1000000);
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;


Expand Down
2 changes: 2 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
obj.pushKV("current_signblock_asm", ScriptToAsmStr(entry.m_signblockscript));
obj.pushKV("current_signblock_hex", HexStr(entry.m_signblockscript));
obj.pushKV("max_block_witness", (uint64_t)entry.m_signblock_witness_limit);
obj.pushKV("current_fedpeg_program", HexStr(entry.m_fedpeg_program));
obj.pushKV("current_fedpeg_script", HexStr(entry.m_fedpegscript));
UniValue arr(UniValue::VARR);
for (const auto& extension : entry.m_extension_space) {
arr.push_back(HexStr(extension));
Expand Down
89 changes: 51 additions & 38 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3485,49 +3485,62 @@ static bool ContextualCheckDynaFedHeader(const CBlockHeader& block, CValidationS
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "dynamic block header's current parameters do not match expected");
}

// Lastly, enforce rules on proposals.
const DynaFedParamEntry& proposed = dynafed_params.m_proposed;
if (!proposed.IsNull()) {

// signblockscript proposals *must* be segwit versions
int block_version = 0;
std::vector<unsigned char> block_program;
if (!proposed.m_signblockscript.IsWitnessProgram(block_version, block_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed signblockscript must be native segwit scriptPubkey");
}

int fedpeg_version = 0;
std::vector<unsigned char> fedpeg_program;
if (!proposed.m_fedpeg_program.IsWitnessProgram(fedpeg_version, fedpeg_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed fedpegs program must be native segwit scriptPubkey");
}

// for v0, fedpegscript's scriptPubKey must match. v1+ is unencumbered.
if (fedpeg_version == 0) {
uint256 fedpeg_program;
CSHA256().Write(proposed.m_fedpegscript.data(), proposed.m_fedpegscript.size()).Finalize(fedpeg_program.begin());
CScript computed_program = CScript() << OP_0 << ToByteVector(fedpeg_program);
if (computed_program != proposed.m_fedpeg_program) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed v0 segwit fedpegscript must match proposed fedpeg witness program");
// Lastly, enforce rules on proposals if they make changes.
if (!dynafed_params.m_proposed.IsNull()) {
// Compare the new proposed parameters with the current full parameters.
const DynaFedParamEntry current = ComputeNextBlockFullCurrentParameters(pindexPrev, params.GetConsensus());
const DynaFedParamEntry& proposed = dynafed_params.m_proposed;

if (proposed.m_signblockscript != current.m_signblockscript) {
// signblockscript proposals *must* be segwit versions
int block_version = 0;
std::vector<unsigned char> block_program;
if (!proposed.m_signblockscript.IsWitnessProgram(block_version, block_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"proposed signblockscript must be native segwit scriptPubkey"
);
}
}

// fedpegscript proposals *must not* start with OP_DEPTH
// This forbids the first Liquid watchman script which is a hack.
// Use miniscript, which doesn't even have OP_DEPTH.
// We don't encumber future segwit versions as opcodes may change.
if (!proposed.m_fedpegscript.empty() &&
proposed.m_fedpegscript.front() == OP_DEPTH) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
if (proposed.m_fedpeg_program != current.m_fedpeg_program || proposed.m_fedpegscript != current.m_fedpegscript) {
int fedpeg_version = 0;
std::vector<unsigned char> fedpeg_program;
if (!proposed.m_fedpeg_program.IsWitnessProgram(fedpeg_version, fedpeg_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed fedpegs program must be native segwit scriptPubkey");
}

// for v0, fedpegscript's scriptPubKey must match. v1+ is unencumbered.
if (fedpeg_version == 0) {
uint256 fedpeg_program;
CSHA256().Write(proposed.m_fedpegscript.data(), proposed.m_fedpegscript.size()).Finalize(fedpeg_program.begin());
CScript computed_program = CScript() << OP_0 << ToByteVector(fedpeg_program);
if (computed_program != proposed.m_fedpeg_program) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"proposed v0 segwit fedpegscript must match proposed fedpeg witness program"
);
}

// fedpegscript proposals *must not* start with OP_DEPTH
// This forbids the first Liquid watchman script which is a hack.
// Use miniscript, which doesn't even have OP_DEPTH.
// We don't encumber future segwit versions as opcodes may change.
if (!proposed.m_fedpegscript.empty() && proposed.m_fedpegscript.front() == OP_DEPTH) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
}
}
}

// When enforcing PAK, extension_space must give non-empty PAK list when
// the vector itself is non-empty. Otherwise this means there were "junk"
// entries
if (params.GetEnforcePak()) {
if (!proposed.m_extension_space.empty() &&
CreatePAKListFromExtensionSpace(proposed.m_extension_space).IsReject()) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Extension space is not list of valid PAK entries");
if (proposed.m_extension_space != current.m_extension_space) {
// When enforcing PAK, extension_space must give non-empty PAK list when
// the vector itself is non-empty. Otherwise this means there were "junk"
// entries
if (params.GetEnforcePak()) {
if (!proposed.m_extension_space.empty() &&
CreatePAKListFromExtensionSpace(proposed.m_extension_space).IsReject()) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"Extension space is not list of valid PAK entries"
);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_dynafed.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def set_test_params(self):
self.extra_args = [["-con_dyna_deploy_start=1000", "-enforce_pak=1", "-con_parent_chain_signblockscript=51", "-peginconfirmationdepth=1", "-parentscriptprefix=75", "-parent_bech32_hrp=ert"] for i in range(self.num_nodes)]
# second node will not mine transactions
self.extra_args[1].append("-blocksonly=1")
# Make sure nothing breaks if peers have a different activation.
self.extra_args[1][0] = "-con_dyna_deploy_start=937"

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
Expand Down