Skip to content

Commit 9454d33

Browse files
committed
Merge #665: [0.17 backport] Do non-depth check for peg-in witness where possible #664
880945d Do non-depth check for peg-in witness where possible (Gregory Sanders) Pull request description: Backport of #664. Tree-SHA512: 1f88753b167b23ba6a861c97fdab7eb4cdfaec80cbbc472b3918132b93d918e163e269e0f477c640f96c81967c5f8562ef0eb116e63eed3b3e2b78f557f61f97
2 parents 8b93cee + 880945d commit 9454d33

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/consensus/tx_verify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
162162
CTxOut prevout;
163163
if (tx.vin[i].m_is_pegin) {
164164
std::string err;
165-
if (tx.witness.vtxinwit.size() <= i || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, true)) {
165+
// Make sure witness exists and is properly formatted
166+
if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, false)) {
166167
continue;
167168
}
168169
prevout = GetPeginOutputFromWitness(tx.witness.vtxinwit[i].m_pegin_witness);

src/validation.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,11 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
689689
// This only checks the UTXO set for already claimed pegins. For mempool conflicts,
690690
// we rely on the GetConflictTx check done above.
691691
if (txin.m_is_pegin) {
692-
// Quick sanity check on witness first.
693-
if (tx.witness.vtxinwit.size() <= i ||
694-
tx.witness.vtxinwit[i].m_pegin_witness.stack.size() < 6 ||
695-
uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]).IsNull() ||
696-
tx.vin[i].prevout.hash.IsNull()) {
697-
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness");
692+
// Peg-in witness is required, check here without validating existence in parent chain
693+
std::string err_msg = "no peg-in witness attached";
694+
if (tx.witness.vtxinwit.size() != tx.vin.size() ||
695+
!IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err_msg, false)) {
696+
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness", err_msg);
698697
}
699698

700699
std::pair<uint256, COutPoint> pegin = std::make_pair(uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]), tx.vin[i].prevout);

0 commit comments

Comments
 (0)