Skip to content

Commit c977f2b

Browse files
committed
Merge #664: Do non-depth check for peg-in witness where possible
8838e76 Do non-depth check for peg-in witness where possible (Gregory Sanders) Pull request description: The non-depth check is very cheap, and could be made even cheaper in the future given the proper assumptions. Depth checks are only required for `CheckTxInputs`. Tree-SHA512: 46b9214146c49a0a82147927b897e51af98852ecb86a7a6dd220b7daf4a4a443d262dc576f958642e70476f283733e1c7022f3c0c7214d57581a8cbf3a8f0f2c
2 parents 3689bc8 + 8838e76 commit c977f2b

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
@@ -700,12 +700,11 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
700700
// This only checks the UTXO set for already claimed pegins. For mempool conflicts,
701701
// we rely on the GetConflictTx check done above.
702702
if (txin.m_is_pegin) {
703-
// Quick sanity check on witness first.
704-
if (tx.witness.vtxinwit.size() <= i ||
705-
tx.witness.vtxinwit[i].m_pegin_witness.stack.size() < 6 ||
706-
uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]).IsNull() ||
707-
tx.vin[i].prevout.hash.IsNull()) {
708-
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness");
703+
// Peg-in witness is required, check here without validating existence in parent chain
704+
std::string err_msg = "no peg-in witness attached";
705+
if (tx.witness.vtxinwit.size() != tx.vin.size() ||
706+
!IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err_msg, false)) {
707+
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness", err_msg);
709708
}
710709

711710
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)