Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,177 Lines • ▼ Show 20 Lines | if (!tx.IsCoinBase()) { | ||||
assert(is_spent); | assert(is_spent); | ||||
} | } | ||||
} | } | ||||
// Add outputs. | // Add outputs. | ||||
AddCoins(view, tx, nHeight); | AddCoins(view, tx, nHeight); | ||||
} | } | ||||
bool TransactionMetricsAccumulator::CheckedAccumulate( | |||||
ScriptExecutionMetrics metrics) { | |||||
// Sanity check: | |||||
// An input is at least 41 bytes large, and can contain up to | |||||
// MAX_OPS_PER_SCRIPT operations. Make sure the worst case can't overflow. | |||||
constexpr auto maxinputs_metrics = | |||||
std::numeric_limits<CounterType>::max() / MAX_OPS_PER_SCRIPT; | |||||
deadalnix: You are checking against what you promise the world to do, not what you actual do. | |||||
constexpr auto maxinputs_tx = MAX_TX_SIZE / 41; | |||||
static_assert(maxinputs_metrics > maxinputs_tx, | |||||
"metrics accumulator sigchecks mustn't overflow"); | |||||
CounterType accum_before = | |||||
nSigChecks.fetch_add(metrics.nSigChecks, std::memory_order_relaxed); | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis will always add, which isn't what you want. You want something like: int txSigCheck = nSigChecks.load(); while(txSigCHeck <= MAX_TX_SIGCHECKS_COUNT) { int newTxSigCheck = txSigCheck + metrics.nSigChecks; if (nSigChecks.compare_exchange_weak(txSigCheck, newTxSigCheck) { return newTxSigCheck <= MAX_TX_SIGCHECKS_COUNT; } } return false; deadalnix: This will always add, which isn't what you want. You want something like:
```
int txSigCheck =… | |||||
return (accum_before + metrics.nSigChecks) <= MAX_TX_SIGCHECKS_COUNT; | |||||
} | |||||
bool CScriptCheck::operator()() { | bool CScriptCheck::operator()() { | ||||
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; | const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; | ||||
return VerifyScript(scriptSig, scriptPubKey, nFlags, | if (!VerifyScript(scriptSig, scriptPubKey, nFlags, | ||||
CachingTransactionSignatureChecker(ptxTo, nIn, amount, | CachingTransactionSignatureChecker(ptxTo, nIn, amount, | ||||
cacheStore, txdata), | cacheStore, txdata), | ||||
metrics, &error); | metrics, &error)) { | ||||
// error is filled in | |||||
return false; | |||||
} | |||||
if (pTxAccumulator && !pTxAccumulator->CheckedAccumulate(metrics)) { | |||||
error = ScriptError::TX_METRICS_LIMIT_EXCEEDED; | |||||
return false; | |||||
} | |||||
return true; | |||||
} | } | ||||
int GetSpendHeight(const CCoinsViewCache &inputs) { | int GetSpendHeight(const CCoinsViewCache &inputs) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *pindexPrev = LookupBlockIndex(inputs.GetBestBlock()); | CBlockIndex *pindexPrev = LookupBlockIndex(inputs.GetBestBlock()); | ||||
return pindexPrev->nHeight + 1; | return pindexPrev->nHeight + 1; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 4,486 Lines • Show Last 20 Lines |
You are checking against what you promise the world to do, not what you actual do.