Skip to content

Commit

Permalink
Merge #665: [0.17 backport] Do non-depth check for peg-in witness whe…
Browse files Browse the repository at this point in the history
…re possible #664

880945d Do non-depth check for peg-in witness where possible (Gregory Sanders)

Pull request description:

  Backport of #664.

Tree-SHA512: 1f88753b167b23ba6a861c97fdab7eb4cdfaec80cbbc472b3918132b93d918e163e269e0f477c640f96c81967c5f8562ef0eb116e63eed3b3e2b78f557f61f97
  • Loading branch information
instagibbs committed Jun 13, 2019
2 parents 8b93cee + 880945d commit 9454d33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
CTxOut prevout;
if (tx.vin[i].m_is_pegin) {
std::string err;
if (tx.witness.vtxinwit.size() <= i || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, true)) {
// Make sure witness exists and is properly formatted
if (tx.witness.vtxinwit.size() != tx.vin.size() || !IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err, false)) {
continue;
}
prevout = GetPeginOutputFromWitness(tx.witness.vtxinwit[i].m_pegin_witness);
Expand Down
11 changes: 5 additions & 6 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,11 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
// This only checks the UTXO set for already claimed pegins. For mempool conflicts,
// we rely on the GetConflictTx check done above.
if (txin.m_is_pegin) {
// Quick sanity check on witness first.
if (tx.witness.vtxinwit.size() <= i ||
tx.witness.vtxinwit[i].m_pegin_witness.stack.size() < 6 ||
uint256(tx.witness.vtxinwit[i].m_pegin_witness.stack[2]).IsNull() ||
tx.vin[i].prevout.hash.IsNull()) {
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness");
// Peg-in witness is required, check here without validating existence in parent chain
std::string err_msg = "no peg-in witness attached";
if (tx.witness.vtxinwit.size() != tx.vin.size() ||
!IsValidPeginWitness(tx.witness.vtxinwit[i].m_pegin_witness, tx.vin[i].prevout, err_msg, false)) {
return state.Invalid(false, REJECT_INVALID, "pegin-no-witness", err_msg);
}

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

0 comments on commit 9454d33

Please sign in to comment.