Skip to content

Commit

Permalink
coderabbitai comment applied
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Dec 4, 2024
1 parent 401a88f commit 76bc9ec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,25 +1784,25 @@ CAmount getzerocoinpoolbalance()

CAmount getCVE17144amount()
{
// as the attack happened at block 293526,
// get the block
// CVE-2018-17144 was a critical bug that allowed double-spending of inputs
// in the same transaction. This function calculates the total amount of coins
// that were created due to this vulnerability at block 293526.
LOCK(cs_main);
if (chainActive.Height() < 293526) {
throw std::runtime_error("Chain height is less than 293,526.");
}

if (!Params().GetConsensus().IsMain()) {
throw std::runtime_error("It is not on right chain, atack happened on mainnet");
throw std::runtime_error("Attack only occurred on mainnet");
}

CBlockIndex *atackedBlock = chainActive[293526];
CBlock block;
if (!ReadBlockFromDisk(block, atackedBlock, ::Params().GetConsensus())) {
throw std::runtime_error(std::string("can't read block from disk, "));
throw std::runtime_error("Failed to read block 293526 from disk");
}
CAmount amount = 0;
for (CTransactionRef tx : block.vtx) {
std::set<COutPoint> vInOutPoints;
if (!tx->IsCoinBase() && !tx->HasNoRegularInputs()) {
std::set<COutPoint> vInOutPoints;
for (const auto& txin : tx->vin)
Expand All @@ -1813,6 +1813,9 @@ CAmount getCVE17144amount()
if (!GetTransaction(txin.prevout.hash, tx, Params().GetConsensus(), hashBlock, true)) {
continue;
}
if (txin.prevout.n >= tx->vout.size()) {
continue; // Skip if output index is out of bounds
}
amount += tx->vout[txin.prevout.n].nValue;
}
}
Expand Down

0 comments on commit 76bc9ec

Please sign in to comment.