Skip to content

Commit 2b4899d

Browse files
committed
PAK enforcement via standardness, drop multi-op_return restriction
1 parent 6679823 commit 2b4899d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/chainparams.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class CMainParams : public CChainParams {
153153
consensus.genesis_subsidy = 50*COIN;
154154
consensus.connect_genesis_outputs = false;
155155
anyonecanspend_aremine = false;
156+
enforce_pak = false;
156157

157158
/**
158159
* The message start string is designed to be unlikely to occur in normal data.
@@ -271,6 +272,7 @@ class CTestNetParams : public CChainParams {
271272
consensus.genesis_subsidy = 50*COIN;
272273
consensus.connect_genesis_outputs = false;
273274
anyonecanspend_aremine = false;
275+
enforce_pak = false;
274276

275277
pchMessageStart[0] = 0x0b;
276278
pchMessageStart[1] = 0x11;
@@ -364,6 +366,7 @@ class CRegTestParams : public CChainParams {
364366
consensus.genesis_subsidy = 50*COIN;
365367
consensus.connect_genesis_outputs = false;
366368
anyonecanspend_aremine = false;
369+
enforce_pak = false;
367370

368371
pchMessageStart[0] = 0xfa;
369372
pchMessageStart[1] = 0xbf;
@@ -541,6 +544,9 @@ class CCustomParams : public CRegTestParams {
541544
anyonecanspend_aremine = args.GetBoolArg("-anyonecanspendaremine", true);
542545

543546
consensus.has_parent_chain = args.GetBoolArg("-con_has_parent_chain", true);
547+
548+
enforce_pak = args.GetBoolArg("-enforce_pak", false);
549+
544550
// bitcoin regtest is the parent chain by default
545551
parentGenesisBlockHash = uint256S(args.GetArg("-parentgenesisblockhash", "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
546552
// Either it has a parent chain or not

src/chainparams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class CChainParams
8787
const uint256 ParentGenesisBlockHash() const { return parentGenesisBlockHash; }
8888
bool anyonecanspend_aremine;
8989
const std::string& ParentBech32HRP() const { return parent_bech32_hrp; }
90+
bool GetEnforcePak() const { return enforce_pak; }
9091

9192
protected:
9293
CChainParams() {}
@@ -111,6 +112,7 @@ class CChainParams
111112
// ELEMENTS extra fields:
112113
uint256 parentGenesisBlockHash;
113114
std::string parent_bech32_hrp;
115+
bool enforce_pak;
114116
};
115117

116118
/**

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void SetupChainParamsBaseOptions()
3838
gArgs.AddArg("-con_parent_chain_signblockscript", "Whether parent chain uses pow or signed blocks. If the parent chain uses signed blocks, the challenge (scriptPubKey) script. If not, an empty string. (default: empty script [ie parent uses pow])", false, OptionsCategory::CHAINPARAMS);
3939

4040
gArgs.AddArg("-fedpegscript", "The script for the federated peg.", false, OptionsCategory::CHAINPARAMS);
41+
gArgs.AddArg("-enforce_pak", "Causes standardness checks to enforce Pegout Authorization Key(PAK) validation, and miner to include PAK commitments when configured. Can not be set when acceptnonstdtx is set to true.", false, OptionsCategory::ELEMENTS);
4142
}
4243

4344
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

src/policy/policy.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <tinyformat.h>
1515
#include <util.h>
1616
#include <utilstrencodings.h>
17+
#include <chainparams.h> // Peg-out enforcement
1718

1819

1920
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
@@ -61,6 +62,7 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
6162
if (!Solver(scriptPubKey, whichType, vSolutions))
6263
return false;
6364

65+
CChainParams params = Params();
6466
if (whichType == TX_MULTISIG)
6567
{
6668
unsigned char m = vSolutions.front()[0];
@@ -70,6 +72,10 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
7072
return false;
7173
if (m < 1 || m > n)
7274
return false;
75+
} else if (whichType == TX_NULL_DATA && params.GetEnforcePak() &&
76+
scriptPubKey.IsPegoutScript(Params().ParentGenesisBlockHash()) ) {
77+
// If we're enforcing pak let through larger peg-out scripts
78+
return true;
7379
} else if (whichType == TX_NULL_DATA &&
7480
(!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes))
7581
return false;
@@ -113,6 +119,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason)
113119
}
114120
}
115121

122+
CChainParams params = Params();
116123
unsigned int nDataOut = 0;
117124
txnouttype whichType;
118125
for (const CTxOut& txout : tx.vout) {
@@ -121,9 +128,18 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason)
121128
return false;
122129
}
123130

124-
if (whichType == TX_NULL_DATA)
131+
if (whichType == TX_NULL_DATA) {
132+
}
133+
if (whichType == TX_NULL_DATA) {
125134
nDataOut++;
126-
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
135+
if (params.GetEnforcePak() &&
136+
txout.scriptPubKey.IsPegoutScript(params.ParentGenesisBlockHash()) &&
137+
(!ScriptHasValidPAKProof(txout.scriptPubKey, params.ParentGenesisBlockHash()))) {
138+
// TODO(rebase) CT/CA check for asset type
139+
reason = "invalid-pegout-proof";
140+
return false;
141+
}
142+
} else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
127143
reason = "bare-multisig";
128144
return false;
129145
} else if (IsDust(txout, ::dustRelayFee)) {

0 commit comments

Comments
 (0)