Add Orchard value balance checks.
This commit is contained in:
parent
5bfdbb4c74
commit
22854f7998
43
src/main.cpp
43
src/main.cpp
|
@ -1455,13 +1455,13 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for non-zero valueBalanceSapling when there are no Sapling inputs or outputs
|
// Check for non-zero valueBalanceSapling when there are no Sapling inputs or outputs
|
||||||
if (tx.vShieldedSpend.empty() && tx.vShieldedOutput.empty() && tx.GetValueBalanceSapling() != 0) { // XXX value balance ffi
|
if (tx.vShieldedSpend.empty() && tx.vShieldedOutput.empty() && tx.GetValueBalanceSapling() != 0) {
|
||||||
return state.DoS(100, error("CheckTransaction(): tx.valueBalanceSapling has no sources or sinks"),
|
return state.DoS(100, error("CheckTransaction(): tx.valueBalanceSapling has no sources or sinks"),
|
||||||
REJECT_INVALID, "bad-txns-valuebalance-nonzero");
|
REJECT_INVALID, "bad-txns-valuebalance-nonzero");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for overflow valueBalanceSapling XXX rename to sapling value balance, add orchard value balance checks
|
// Check for overflow valueBalanceSapling
|
||||||
if (tx.GetValueBalanceSapling() > MAX_MONEY || tx.GetValueBalanceSapling() < -MAX_MONEY) { // XXX need value balance ffi
|
if (tx.GetValueBalanceSapling() > MAX_MONEY || tx.GetValueBalanceSapling() < -MAX_MONEY) {
|
||||||
return state.DoS(100, error("CheckTransaction(): abs(tx.valueBalanceSapling) too large"),
|
return state.DoS(100, error("CheckTransaction(): abs(tx.valueBalanceSapling) too large"),
|
||||||
REJECT_INVALID, "bad-txns-valuebalance-toolarge");
|
REJECT_INVALID, "bad-txns-valuebalance-toolarge");
|
||||||
}
|
}
|
||||||
|
@ -1476,6 +1476,30 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto valueBalanceOrchard = orchard_bundle.GetValueBalance();
|
||||||
|
|
||||||
|
// Check for non-zero valueBalanceOrchard when there are no Orchard inputs or outputs
|
||||||
|
if (!orchard_bundle.SpendsEnabled() && !orchard_bundle.OutputsEnabled() && valueBalanceOrchard != 0) {
|
||||||
|
return state.DoS(100, error("CheckTransaction(): tx.valueBalanceOrchard has no sources or sinks"),
|
||||||
|
REJECT_INVALID, "bad-txns-valuebalance-nonzero");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for overflow valueBalanceOrchard
|
||||||
|
if (valueBalanceOrchard > MAX_MONEY || valueBalanceOrchard < -MAX_MONEY) {
|
||||||
|
return state.DoS(100, error("CheckTransaction(): abs(tx.valueBalanceOrchard) too large"),
|
||||||
|
REJECT_INVALID, "bad-txns-valuebalance-toolarge");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valueBalanceOrchard <= 0) {
|
||||||
|
// NB: negative valueBalanceOrchard "takes" money from the transparent value pool just as outputs do
|
||||||
|
nValueOut += -valueBalanceOrchard;
|
||||||
|
|
||||||
|
if (!MoneyRange(nValueOut)) {
|
||||||
|
return state.DoS(100, error("CheckTransaction(): txout total out of range"),
|
||||||
|
REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that joinsplit values are well-formed
|
// Ensure that joinsplit values are well-formed
|
||||||
for (const JSDescription& joinsplit : tx.vJoinSplit)
|
for (const JSDescription& joinsplit : tx.vJoinSplit)
|
||||||
{
|
{
|
||||||
|
@ -1532,12 +1556,22 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
|
||||||
// NB: positive valueBalanceSapling "adds" money to the transparent value pool, just as inputs do
|
// NB: positive valueBalanceSapling "adds" money to the transparent value pool, just as inputs do
|
||||||
nValueIn += tx.GetValueBalanceSapling();
|
nValueIn += tx.GetValueBalanceSapling();
|
||||||
|
|
||||||
|
if (!MoneyRange(nValueIn)) {
|
||||||
|
return state.DoS(100, error("CheckTransaction(): txin total out of range"),
|
||||||
|
REJECT_INVALID, "bad-txns-txintotal-toolarge");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also check for Orchard
|
||||||
|
if (valueBalanceOrchard >= 0) {
|
||||||
|
// NB: positive valueBalanceOrchard "adds" money to the transparent value pool, just as inputs do
|
||||||
|
nValueIn += valueBalanceOrchard;
|
||||||
|
|
||||||
if (!MoneyRange(nValueIn)) {
|
if (!MoneyRange(nValueIn)) {
|
||||||
return state.DoS(100, error("CheckTransaction(): txin total out of range"),
|
return state.DoS(100, error("CheckTransaction(): txin total out of range"),
|
||||||
REJECT_INVALID, "bad-txns-txintotal-toolarge");
|
REJECT_INVALID, "bad-txns-txintotal-toolarge");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XXX add orchard block, similar to sapling
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for duplicate inputs
|
// Check for duplicate inputs
|
||||||
|
@ -1578,7 +1612,6 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
|
||||||
vSaplingNullifiers.insert(spend_desc.nullifier);
|
vSaplingNullifiers.insert(spend_desc.nullifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XXX similar for orchard
|
|
||||||
|
|
||||||
// Check for duplicate orchard nullifiers in this transaction
|
// Check for duplicate orchard nullifiers in this transaction
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue