Auto merge of #3220 - Eirik0:3209-fix-CheckTransaction, r=str4d

Implement consensus rules about the number of Spend and Output Descriptions in a transaction

Closes #3209.
Part of #3065.
This commit is contained in:
Homu
2018-05-01 07:09:52 -07:00
2 changed files with 48 additions and 3 deletions

View File

@@ -1039,12 +1039,14 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
}
}
// Transactions can contain empty `vin` and `vout` so long as
// either `vjoinsplit` or `vShieldedSpend` are non-empty.
// Transactions containing empty `vin` must have either non-empty
// `vjoinsplit` or non-empty `vShieldedSpend`.
if (tx.vin.empty() && tx.vjoinsplit.empty() && tx.vShieldedSpend.empty())
return state.DoS(10, error("CheckTransaction(): vin empty"),
REJECT_INVALID, "bad-txns-vin-empty");
if (tx.vout.empty() && tx.vjoinsplit.empty() && tx.vShieldedSpend.empty())
// Transactions containing empty `vout` must have either non-empty
// `vjoinsplit` or non-empty `vShieldedOutput`.
if (tx.vout.empty() && tx.vjoinsplit.empty() && tx.vShieldedOutput.empty())
return state.DoS(10, error("CheckTransaction(): vout empty"),
REJECT_INVALID, "bad-txns-vout-empty");
@@ -1169,6 +1171,14 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
return state.DoS(100, error("CheckTransaction(): coinbase has joinsplits"),
REJECT_INVALID, "bad-cb-has-joinsplits");
// A coinbase transaction cannot have spend descriptions or output descriptions
if (tx.vShieldedSpend.size() > 0)
return state.DoS(100, error("CheckTransaction(): coinbase has spend descriptions"),
REJECT_INVALID, "bad-cb-has-spend-description");
if (tx.vShieldedOutput.size() > 0)
return state.DoS(100, error("CheckTransaction(): coinbase has output descriptions"),
REJECT_INVALID, "bad-cb-has-output-description");
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
return state.DoS(100, error("CheckTransaction(): coinbase script size"),
REJECT_INVALID, "bad-cb-length");