Skip to content

Commit 0a47505

Browse files
DuddinoFuzzbawls
authored andcommitted
Fix Exchange address activation
Github-Pull: #2908 Rebased-From: 6c01283
1 parent 9cb85c6 commit 0a47505

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

src/consensus/tx_verify.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCol
116116
}
117117

118118
bool hasExchangeUTXOs = tx.HasExchangeAddr();
119-
int nTxHeight = chainActive.Height();
120-
if (hasExchangeUTXOs && !Params().GetConsensus().NetworkUpgradeActive(nTxHeight, Consensus::UPGRADE_V5_6))
121-
return state.DoS(100, false, REJECT_INVALID, "bad-exchange-address-not-started");
122119

123120
if (tx.IsCoinBase()) {
124121
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 150)

src/policy/policy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE
4545
SCRIPT_VERIFY_NULLDUMMY |
4646
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
4747
SCRIPT_VERIFY_CLEANSTACK |
48-
SCRIPT_VERIFY_LOW_S;
48+
SCRIPT_VERIFY_LOW_S |
49+
SCRIPT_VERIFY_EXCHANGEADDR;
4950

5051
/** For convenience, standard but not mandatory verify flags. */
5152
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;

src/sapling/sapling_validation.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state, CAmount&
3333

3434
// From here, all of the checks are done in v3+ transactions.
3535

36-
// if the tx has shielded data, cannot be a coinstake, coinbase, zcspend and zcmint or exchange address
37-
if (tx.IsCoinStake() || tx.IsCoinBase() || tx.HasZerocoinSpendInputs() || tx.HasZerocoinMintOutputs() || tx.HasExchangeAddr())
36+
// if the tx has shielded data, cannot be a coinstake, coinbase, zcspend and zcmint
37+
if (tx.IsCoinStake() || tx.IsCoinBase() || tx.HasZerocoinSpendInputs() || tx.HasZerocoinMintOutputs())
3838
return state.DoS(100, error("%s: Sapling version with invalid data", __func__),
3939
REJECT_INVALID, "bad-txns-invalid-sapling");
4040

@@ -160,6 +160,12 @@ bool ContextualCheckTransaction(
160160

161161
if (hasShieldedData) {
162162
uint256 dataToBeSigned;
163+
164+
if (tx.HasExchangeAddr() && Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_6)) {
165+
return state.DoS(100, error("%s: Sapling version with invalid data", __func__),
166+
REJECT_INVALID, "bad-txns-exchange-addr-has-sapling");
167+
}
168+
163169
// Empty output script.
164170
CScript scriptCode;
165171
try {

src/script/interpreter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
334334
break;
335335

336336
case OP_EXCHANGEADDR:
337+
// Not enabled, treat as OP_UNKNOWN
338+
if (!(flags & SCRIPT_VERIFY_EXCHANGEADDR)) {
339+
return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
340+
}
337341
if (!script.IsPayToExchangeAddress())
338342
return set_error(serror, SCRIPT_ERR_EXCHANGEADDRVERIFY);
339343
break;

src/script/interpreter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ enum
8080
// Verify CHECKLOCKTIMEVERIFY
8181
//
8282
// See BIP65 for details.
83-
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9)
83+
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9),
84+
85+
// Verify OP_EXCHANGEADDR.
86+
// Treat as UNKNOWN before 5.6 activation
87+
SCRIPT_VERIFY_EXCHANGEADDR = (1U << 10),
8488
};
8589

8690
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);

src/test/transaction_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static std::map<std::string, unsigned int> mapFlagNames = {
4747
{std::string("DISCOURAGE_UPGRADABLE_NOPS"), (unsigned int)SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS},
4848
{std::string("CLEANSTACK"), (unsigned int)SCRIPT_VERIFY_CLEANSTACK},
4949
{std::string("CHECKLOCKTIMEVERIFY"), (unsigned int)SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY},
50+
{std::string("EXCHANGEADDRVERIFY"), (unsigned int)SCRIPT_VERIFY_EXCHANGEADDR},
5051
};
5152

5253
unsigned int ParseScriptFlags(std::string strFlags)

src/validation.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,15 @@ static bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state,
569569
}
570570

571571
bool fCLTVIsActivated = consensus.NetworkUpgradeActive(chainHeight, Consensus::UPGRADE_BIP65);
572-
572+
bool exchangeAddrActivated = consensus.NetworkUpgradeActive(chainHeight, Consensus::UPGRADE_V5_6);
573573
// Check against previous transactions
574574
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
575575
int flags = STANDARD_SCRIPT_VERIFY_FLAGS;
576576
if (fCLTVIsActivated)
577577
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
578+
if (exchangeAddrActivated)
579+
flags |= SCRIPT_VERIFY_EXCHANGEADDR;
580+
578581

579582
PrecomputedTransactionData precomTxData(tx);
580583
if (!CheckInputs(tx, state, view, true, flags, true, precomTxData)) {
@@ -593,6 +596,8 @@ static bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state,
593596
flags = MANDATORY_SCRIPT_VERIFY_FLAGS;
594597
if (fCLTVIsActivated)
595598
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
599+
if (exchangeAddrActivated)
600+
flags |= SCRIPT_VERIFY_EXCHANGEADDR;
596601
if (!CheckInputs(tx, state, view, true, flags, true, precomTxData)) {
597602
return error("%s: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s, %s",
598603
__func__, hash.ToString(), FormatStateMessage(state));
@@ -1496,8 +1501,10 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
14961501

14971502
// If scripts won't be checked anyways, don't bother seeing if CLTV is activated
14981503
bool fCLTVIsActivated = false;
1504+
bool exchangeAddrActivated = false;
14991505
if (fScriptChecks && pindex->pprev) {
15001506
fCLTVIsActivated = consensus.NetworkUpgradeActive(pindex->pprev->nHeight, Consensus::UPGRADE_BIP65);
1507+
exchangeAddrActivated = consensus.NetworkUpgradeActive(pindex->pprev->nHeight, Consensus::UPGRADE_V5_6);
15011508
}
15021509

15031510
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : nullptr);
@@ -1575,6 +1582,8 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15751582
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG;
15761583
if (fCLTVIsActivated)
15771584
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
1585+
if (exchangeAddrActivated)
1586+
flags |= SCRIPT_VERIFY_EXCHANGEADDR;
15781587

15791588
bool fCacheResults = fJustCheck; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */
15801589
if (!CheckInputs(tx, state, view, fScriptChecks, flags, fCacheResults, precomTxData[i], nScriptCheckThreads ? &vChecks : nullptr))

0 commit comments

Comments
 (0)