@@ -1506,9 +1506,9 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
1506
1506
// SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
1507
1507
// need to turn both off, and compare against just turning off CLEANSTACK
1508
1508
// to see if the failure is specifically due to witness validation.
1509
- if (CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , txdata) &&
1509
+ if (tx. wit . IsNull () && CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , txdata) &&
1510
1510
!CheckInputs (tx, state, view, true , scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true , txdata)) {
1511
- // Only the witness is wrong , so the transaction itself may be fine.
1511
+ // Only the witness is missing , so the transaction itself may be fine.
1512
1512
state.SetCorruptionPossible ();
1513
1513
}
1514
1514
return false ;
@@ -5505,7 +5505,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5505
5505
else if (!fMissingInputs2 )
5506
5506
{
5507
5507
int nDos = 0 ;
5508
- if (stateDummy.IsInvalid (nDos) && nDos > 0 && (!state. CorruptionPossible () || State (fromPeer)-> fHaveWitness ) )
5508
+ if (stateDummy.IsInvalid (nDos) && nDos > 0 )
5509
5509
{
5510
5510
// Punish peer that gave us an invalid orphan tx
5511
5511
Misbehaving (fromPeer, nDos);
@@ -5516,7 +5516,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5516
5516
// Probably non-standard or insufficient fee/priority
5517
5517
LogPrint (" mempool" , " removed orphan tx %s\n " , orphanHash.ToString ());
5518
5518
vEraseQueue.push_back (orphanHash);
5519
- if (!stateDummy.CorruptionPossible ()) {
5519
+ if (orphanTx.wit .IsNull () && !stateDummy.CorruptionPossible ()) {
5520
+ // Do not use rejection cache for witness transactions or
5521
+ // witness-stripped transactions, as they can have been malleated.
5522
+ // See https://github.com/bitcoin/bitcoin/issues/8279 for details.
5520
5523
assert (recentRejects);
5521
5524
recentRejects->insert (orphanHash);
5522
5525
}
@@ -5554,7 +5557,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5554
5557
LogPrint (" mempool" , " not keeping orphan with rejected parents %s\n " ,tx.GetHash ().ToString ());
5555
5558
}
5556
5559
} else {
5557
- if (!state.CorruptionPossible ()) {
5560
+ if (tx.wit .IsNull () && !state.CorruptionPossible ()) {
5561
+ // Do not use rejection cache for witness transactions or
5562
+ // witness-stripped transactions, as they can have been malleated.
5563
+ // See https://github.com/bitcoin/bitcoin/issues/8279 for details.
5558
5564
assert (recentRejects);
5559
5565
recentRejects->insert (tx.GetHash ());
5560
5566
}
@@ -5586,9 +5592,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5586
5592
if (state.GetRejectCode () < REJECT_INTERNAL) // Never send AcceptToMemoryPool's internal codes over P2P
5587
5593
pfrom->PushMessage (NetMsgType::REJECT, strCommand, (unsigned char )state.GetRejectCode (),
5588
5594
state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), inv.hash );
5589
- if (nDoS > 0 && (!state.CorruptionPossible () || State (pfrom->id )->fHaveWitness )) {
5590
- // When a non-witness-supporting peer gives us a transaction that would
5591
- // be accepted if witness validation was off, we can't blame them for it.
5595
+ if (nDoS > 0 ) {
5592
5596
Misbehaving (pfrom->GetId (), nDoS);
5593
5597
}
5594
5598
}
0 commit comments