Skip to content

Commit e57f648

Browse files
jamesobRob1Ham
authored andcommitted
consensus: add a CSFS deployment for regtest only
(cherry picked from commit 765a674)
1 parent 8feb587 commit e57f648

File tree

8 files changed

+46
-5
lines changed

8 files changed

+46
-5
lines changed

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum DeploymentPos : uint16_t {
3333
DEPLOYMENT_TESTDUMMY,
3434
DEPLOYMENT_TAPROOT, // Deployment of Schnorr/Taproot (BIPs 340-342)
3535
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
36+
DEPLOYMENT_CSFS, // Deployment of CHECKSIGFROMSTACK (BIP 348) (regtest only)
3637
MAX_VERSION_BITS_DEPLOYMENTS
3738
};
3839
constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }

src/deploymentinfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
1717
/*.name =*/ "taproot",
1818
/*.gbt_force =*/ true,
1919
},
20+
{
21+
/*.name =*/ "csfs",
22+
/*.gbt_force =*/ true,
23+
},
2024
};
2125

2226
std::string DeploymentName(Consensus::BuriedDeployment dep)

src/kernel/chainparams.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ class CRegTestParams : public CChainParams
591591
consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
592592
consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].min_activation_height = 0; // No activation delay
593593

594+
consensus.vDeployments[Consensus::DEPLOYMENT_CSFS].bit = 1;
595+
consensus.vDeployments[Consensus::DEPLOYMENT_CSFS].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
596+
consensus.vDeployments[Consensus::DEPLOYMENT_CSFS].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
597+
consensus.vDeployments[Consensus::DEPLOYMENT_CSFS].min_activation_height = 0; // No activation delay
598+
594599
consensus.nMinimumChainWork = uint256{};
595600
consensus.defaultAssumeValid = uint256{};
596601

src/rpc/blockchain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,10 @@ UniValue DeploymentInfo(const CBlockIndex* blockindex, const ChainstateManager&
18491849
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_SEGWIT);
18501850
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_TESTDUMMY);
18511851
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_TAPROOT);
1852+
1853+
if (chainman.GetParams().GetChainType() == ChainType::REGTEST) {
1854+
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_CSFS);
1855+
}
18521856
return softforks;
18531857
}
18541858
} // anon namespace

src/test/versionbits_tests.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,13 @@ BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
434434
// not take precedence over STARTED/LOCKED_IN. So all softforks on
435435
// the same bit might overlap, even when non-overlapping start-end
436436
// times are picked.
437-
const uint32_t dep_mask{vbcache.Mask(chainParams->GetConsensus(), dep)};
437+
const uint32_t dep_mask{uint32_t{1} << chainParams->GetConsensus().vDeployments[dep].bit};
438+
439+
if (chain_type != ChainType::REGTEST && dep == Consensus::DEPLOYMENT_CSFS) {
440+
// CSFS only exists as a deployment on regtest, so skip over it for other
441+
// chains.
442+
continue;
443+
}
438444
BOOST_CHECK(!(chain_all_vbits & dep_mask));
439445
chain_all_vbits |= dep_mask;
440446
check_computeblockversion(vbcache, chainParams->GetConsensus(), dep);

src/validation.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,13 @@ bool MemPoolAccept::PolicyScriptChecks(const ATMPArgs& args, Workspace& ws)
15001500
const CTransaction& tx = *ws.m_ptx;
15011501
TxValidationState& state = ws.m_state;
15021502

1503-
const unsigned int scriptVerifyFlags = PolicyScriptVerifyFlags(args.m_ignore_rejects);
1503+
unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;
1504+
1505+
// CHECKSIGFROMSTACK (BIP348) is always active on regtest, but no other chain.
1506+
if (args.m_chainparams.GetChainType() == ChainType::REGTEST) {
1507+
scriptVerifyFlags |= SCRIPT_VERIFY_CHECKSIGFROMSTACK;
1508+
scriptVerifyFlags &= ~SCRIPT_VERIFY_DISCOURAGE_CHECKSIGFROMSTACK;
1509+
}
15041510

15051511
// Check input scripts and signatures.
15061512
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -2687,6 +2693,11 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Ch
26872693
flags = it->second;
26882694
}
26892695

2696+
// Enforce CHECKSIGFROMSTACK (BIP348)
2697+
if (DeploymentActiveAt(block_index, chainman, Consensus::DEPLOYMENT_CSFS)) {
2698+
flags |= SCRIPT_VERIFY_CHECKSIGFROMSTACK;
2699+
}
2700+
26902701
// Enforce the DERSIG (BIP66) rule
26912702
if (DeploymentActiveAt(block_index, chainman, Consensus::DEPLOYMENT_DERSIG)) {
26922703
flags |= SCRIPT_VERIFY_DERSIG;

test/functional/feature_taproot.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,6 @@ def predict_sigops_ratio(n, dummy_size):
11801180
opcode = CScriptOp(opval)
11811181
if is_op_success(opcode):
11821182
continue
1183-
if opcode in OP_SUCCESS_OVERRIDES:
1184-
# TODO: remove this once CHECKSIGFROMSTACK gets a regtest deployment.
1185-
continue
11861183
scripts = [
11871184
("normal", CScript([OP_RETURN, opcode] + [OP_NOP] * 75)),
11881185
("op_success", CScript([OP_RETURN, CScriptOp(0x50)]))

test/functional/rpc_blockchain.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ def check_signalling_deploymentinfo_result(self, gdi_result, height, blockhash,
251251
},
252252
'height': 0,
253253
'active': True
254+
},
255+
'csfs': {
256+
'type': 'bip9',
257+
'bip9': {
258+
'start_time': -1,
259+
'timeout': 9223372036854775807,
260+
'min_activation_height': 0,
261+
'status': 'active',
262+
'status_next': 'active',
263+
'since': 0,
264+
},
265+
'height': 0,
266+
'active': True
254267
}
255268
}
256269
})

0 commit comments

Comments
 (0)