Skip to content

Commit

Permalink
OP_CAT deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBEEFCAF3 authored and ajtowns committed May 6, 2024
1 parent 808f9c6 commit 6473ec0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum DeploymentPos : uint16_t {
DEPLOYMENT_TESTDUMMY,
DEPLOYMENT_CHECKTEMPLATEVERIFY, // Deployment of CTV (BIP 119)
DEPLOYMENT_ANYPREVOUT,
DEPLOYMENT_OP_CAT,
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
MAX_VERSION_BITS_DEPLOYMENTS
};
Expand Down
4 changes: 4 additions & 0 deletions src/deploymentinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
/*.name =*/ "anyprevout",
/*.gbt_force =*/ true,
},
{
/*.name =*/ "opcat",
/*.gbt_force =*/ true,
},
};

std::string DeploymentName(Consensus::BuriedDeployment dep)
Expand Down
13 changes: 12 additions & 1 deletion src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class CMainParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = SetupDeployment{.activate = 0x30000000, .abandon = 0, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY] = SetupDeployment{.activate = 0x60007700, .abandon = 0x40007700, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_ANYPREVOUT] = SetupDeployment{.activate = 0x60007600, .abandon = 0x40007600, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_OP_CAT] = SetupDeployment{.activate = 0x62000100, .abandon = 0x42000100, .never = true};

consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000063c4ebd298db40af57541800");
consensus.defaultAssumeValid = uint256S("0x000000000000000000026811d149d4d261995ec5b3f64f439a0a10e1a464af9a"); // 824000
Expand Down Expand Up @@ -245,6 +246,7 @@ class CTestNetParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = SetupDeployment{.activate = 0x30000000, .abandon = 0, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY] = SetupDeployment{.activate = 0x60007700, .abandon = 0x40007700, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_ANYPREVOUT] = SetupDeployment{.activate = 0x60007600, .abandon = 0x40007600, .never = true};
consensus.vDeployments[Consensus::DEPLOYMENT_OP_CAT] = SetupDeployment{.activate = 0x62000100, .abandon = 0x42000100, .never = true};

consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000c59b14e264ba6c15db9");
consensus.defaultAssumeValid = uint256S("0x000000000001323071f38f21ea5aae529ece491eadaccce506a59bcc2d968917"); // 2550000
Expand Down Expand Up @@ -386,6 +388,15 @@ class SigNetParams : public CChainParams {
.activate = 0x60007600,
.abandon = 0x40007600,
};
consensus.vDeployments[Consensus::DEPLOYMENT_OP_CAT] = SetupDeployment{
.year = 2024,
.number = 1,
.revision = 0,
.start = 1704085200, // 2024-01-01
.timeout = 2019704400, // 2034-01-01
.activate = 0x62000100,
.abandon = 0x42000100,
};

RenounceDeployments(options.renounce, consensus.vDeployments);

Expand Down Expand Up @@ -460,7 +471,7 @@ class CRegTestParams : public CChainParams
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY] = SetupDeployment{.start = 0, .timeout = Consensus::HereticalDeployment::NO_TIMEOUT, .activate = 0x30000000, .abandon = 0x50000000};
consensus.vDeployments[Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY] = SetupDeployment{.activate = 0x60007700, .abandon = 0x40007700, .always = true};
consensus.vDeployments[Consensus::DEPLOYMENT_ANYPREVOUT] = SetupDeployment{.activate = 0x60007600, .abandon = 0x40007600, .always = true};

consensus.vDeployments[Consensus::DEPLOYMENT_OP_CAT] = SetupDeployment{.activate = 0x62000100, .abandon = 0x42000100, .always = true};
consensus.nMinimumChainWork = uint256{};
consensus.defaultAssumeValid = uint256{};

Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ UniValue DeploymentInfo(const CBlockIndex* blockindex, const ChainstateManager&
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_TAPROOT);
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY);
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_ANYPREVOUT);
SoftForkDescPushBack(blockindex, softforks, chainman, Consensus::DEPLOYMENT_OP_CAT);
return softforks;
}
} // anon namespace
Expand Down
27 changes: 22 additions & 5 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,18 +1044,30 @@ bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txn
return true;
}

static unsigned int DepDiscourageFlags(const CBlockIndex* tip, const ChainstateManager& chainman, const std::vector<std::pair<Consensus::DeploymentPos,unsigned int>>& depflags)
{
unsigned int result = SCRIPT_VERIFY_NONE;
for (auto [dep, flags] : depflags) {
if (!DeploymentActiveAfter(tip, chainman, dep)) {
result |= flags;
}
}
return result;
}

bool MemPoolAccept::PolicyScriptChecks(const ATMPArgs& args, Workspace& ws)
{
AssertLockHeld(cs_main);
AssertLockHeld(m_pool.cs);
const CTransaction& tx = *ws.m_ptx;
TxValidationState& state = ws.m_state;

const bool ctv_active = DeploymentActiveAfter(m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman, Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY);
const bool apo_active = DeploymentActiveAfter(m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman, Consensus::DEPLOYMENT_ANYPREVOUT);
const unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS
| (ctv_active ? SCRIPT_VERIFY_NONE : SCRIPT_VERIFY_DISCOURAGE_CHECK_TEMPLATE_VERIFY_HASH)
| (apo_active ? SCRIPT_VERIFY_NONE : SCRIPT_VERIFY_DISCOURAGE_ANYPREVOUT);
const unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS |
DepDiscourageFlags(m_active_chainstate.m_chain.Tip(), m_active_chainstate.m_chainman, {
{ Consensus::DEPLOYMENT_CHECKTEMPLATEVERIFY, SCRIPT_VERIFY_DISCOURAGE_CHECK_TEMPLATE_VERIFY_HASH },
{ Consensus::DEPLOYMENT_ANYPREVOUT, SCRIPT_VERIFY_DISCOURAGE_ANYPREVOUT },
{ Consensus::DEPLOYMENT_OP_CAT, SCRIPT_VERIFY_DISCOURAGE_OP_CAT },
});

// Check input scripts and signatures.
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
Expand Down Expand Up @@ -2155,6 +2167,11 @@ unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Chainstat
flags |= SCRIPT_VERIFY_ANYPREVOUT;
}

// Enforce OP_CAT
if (DeploymentActiveAt(block_index, chainman, Consensus::DEPLOYMENT_OP_CAT)) {
flags |= SCRIPT_VERIFY_OP_CAT;
}

return flags;
}

Expand Down
17 changes: 15 additions & 2 deletions test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,10 @@ def _test_getblockchaininfo(self):

def check_signalling_deploymentinfo_result(self, gdi_result, height, blockhash):
assert height >= 144 and height <= 287

assert_equal(gdi_result, {
"hash": blockhash,
"height": height,
"script_flags": ["ANYPREVOUT","CHECKLOCKTIMEVERIFY","CHECKSEQUENCEVERIFY","DEFAULT_CHECK_TEMPLATE_VERIFY_HASH","DERSIG","NULLDUMMY","P2SH","TAPROOT","WITNESS"],
"script_flags": ["ANYPREVOUT","CHECKLOCKTIMEVERIFY","CHECKSEQUENCEVERIFY","DEFAULT_CHECK_TEMPLATE_VERIFY_HASH","DERSIG","NULLDUMMY","OP_CAT","P2SH","TAPROOT","WITNESS"],
"deployments": {
'bip34': {'type': 'buried', 'active': True, 'height': 2},
'bip66': {'type': 'buried', 'active': True, 'height': 3},
Expand Down Expand Up @@ -248,6 +247,20 @@ def check_signalling_deploymentinfo_result(self, gdi_result, height, blockhash):
'active': True,
'height': 0,
},
'opcat': {
'type': 'heretical',
'heretical': {
'binana-id': "BIN-2024-0001-000",
'start_time': -1,
'timeout': 9223372036854775807,
'period': 144,
'status': 'active',
'since': 0,
'status_next': 'active'
},
'height': 0,
'active': True,
},
}
})

Expand Down
3 changes: 3 additions & 0 deletions test/functional/test_framework/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,4 +953,7 @@ def taproot_construct(pubkey, scripts=None, *, keyver=None, treat_internal_as_in
return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked, keyver)

def is_op_success(o):
# assume OP_CAT is activated in tests
if o == OP_CAT:
return False
return o == 0x50 or o == 0x62 or o == 0x89 or o == 0x8a or o == 0x8d or o == 0x8e or (o >= 0x7e and o <= 0x81) or (o >= 0x83 and o <= 0x86) or (o >= 0x95 and o <= 0x99) or (o >= 0xbb and o <= 0xfe)

0 comments on commit 6473ec0

Please sign in to comment.