| 866 | } |
| 867 | |
| 868 | bool CheckTransaction(const CTransaction& tx, CValidationState& state) |
| 869 | { |
| 870 | // Basic checks that don't depend on any context |
| 871 | if (tx.vin.empty()) |
| 872 | return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty"); |
| 873 | |
| 874 | if (tx.vout.empty()) |
| 875 | return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty"); |
| 876 | |
| 877 | // Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability) |
| 878 | if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MAX_BLOCK_BASE_SIZE) |
| 879 | return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize"); |
| 880 | |
| 881 | // Check for negative or overflow output values |
| 882 | CAmount nValueOut = 0; |
| 883 | for (const auto& txout : tx.vout) { |
| 884 | if (txout.nValue < 0) |
| 885 | return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative"); |
| 886 | |
| 887 | if (txout.nValue > MAX_MONEY) |
| 888 | return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge"); |
| 889 | |
| 890 | nValueOut += txout.nValue; |
| 891 | if (!MoneyRange(nValueOut)) |
| 892 | return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge"); |
| 893 | |
| 894 | /////////////////////////////////////////////////////////// // lux |
| 895 | if (txout.scriptPubKey.HasOpCall() || txout.scriptPubKey.HasOpCreate()) { |
| 896 | std::vector<valtype> vSolutions; |
| 897 | txnouttype whichType; |
| 898 | if (!Solver(txout.scriptPubKey, whichType, vSolutions, true)) { |
| 899 | return state.DoS(100, false, REJECT_INVALID, "bad-txns-contract-nonstandard"); |
| 900 | } |
| 901 | } |
| 902 | /////////////////////////////////////////////////////////// |
| 903 | } |
| 904 | |
| 905 | |
| 906 | // Check for duplicate inputs |
| 907 | set<COutPoint> vInOutPoints; |
| 908 | for (const CTxIn& txin : tx.vin) { |
| 909 | if (vInOutPoints.count(txin.prevout)) |
| 910 | return state.DoS(100, error("CheckTransaction() : duplicate inputs"), |
| 911 | REJECT_INVALID, "bad-txns-inputs-duplicate"); |
| 912 | vInOutPoints.insert(txin.prevout); |
| 913 | } |
| 914 | |
| 915 | if (tx.IsCoinBase()) { |
| 916 | if (/*tx.vin[0].scriptSig.size() < 2 || */ tx.vin[0].scriptSig.size() > 150) |
| 917 | return state.DoS(100, false, REJECT_INVALID, "bad-cb-length"); |
| 918 | } else { |
| 919 | for (const CTxIn& txin : tx.vin) |
| 920 | if (txin.prevout.IsNull()) |
| 921 | return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null"); |
| 922 | } |
| 923 | |
| 924 | return true; |
| 925 | } |
no test coverage detected