Skip to content

Commit

Permalink
Calculate instead of hardcoded numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Dec 3, 2024
1 parent b9ef752 commit 5019320
Showing 1 changed file with 60 additions and 49 deletions.
109 changes: 60 additions & 49 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,60 @@ UniValue getspentinfo(const JSONRPCRequest& request)
return obj;
}

CAmount getzerocoinpoolbalance()
{
CAmount nTotalAmount = 0;

// Iterate over all mints
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
if (GetAddressIndex(uint160(), AddressType::zerocoinMint, addressIndex)) {
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}
addressIndex.clear();

// Iterate over all spends
if (GetAddressIndex(uint160(), AddressType::zerocoinSpend, addressIndex)) {
for (std::vector < std::pair < CAddressIndexKey, CAmount > > ::const_iterator it = addressIndex.begin();
it != addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}

return nTotalAmount;
}

CAmount getCVE17144amount()
{
// as the attack happened at block 293526,
// get the block
CBlockIndex *mintBlock = chainActive[293526];
CBlock block;
if (!ReadBlockFromDisk(block, mintBlock, ::Params().GetConsensus())) {
throw std::runtime_error(std::string("can't read block 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)
{
if (!vInOutPoints.insert(txin.prevout).second) {
CTransactionRef tx;
uint256 hashBlock;
if (!GetTransaction(txin.prevout.hash, tx, Params().GetConsensus(), hashBlock, true)) {
continue;
}
amount += tx->vout[txin.prevout.n].nValue;
}
}
}
}
return amount;
}

UniValue gettotalsupply(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 0)
Expand All @@ -1780,9 +1834,9 @@ UniValue gettotalsupply(const JSONRPCRequest& request)
if(!pblocktree->ReadTotalSupply(total))
throw JSONRPCError(RPC_DATABASE_ERROR, "Cannot read the total supply from the database. This functionality requires -addressindex to be enabled. Enabling -addressindex requires reindexing.");

total += 49839700000000; // The actual amount of coins forged during the Zerocoin attacks (the negative balance after the pool closed), you can verify the number by calling getzerocoinpoolbalance rpc
total += 3131972000000; // The remaining amount of forged coins during CVE-2018-17144 attacks, after subtracting locked coins and burnt Coins sent to unrecoverable address https://explorer.firo.org/tx/0b53178c1b22bae4c04ef943ee6d6d30f2483327fe9beb54952951592e8ce368

total -= getzerocoinpoolbalance(); //498,397.00000000 The actual amount of coins forged during the Zerocoin attacks (the negative balance after the pool closed),
total += getCVE17144amount(); //320,841.99803185 The cmount of forged coins during CVE-2018-17144 attacks,
total -= 16810168037465;// burnt Coins sent to unrecoverable address https://explorer.firo.org/tx/0b53178c1b22bae4c04ef943ee6d6d30f2483327fe9beb54952951592e8ce368
UniValue result(UniValue::VOBJ);
result.push_back(Pair("total", total));

Expand All @@ -1805,26 +1859,7 @@ UniValue getzerocoinpoolbalance(const JSONRPCRequest& request)
+ HelpExampleRpc("getzerocoinpoolbalance", "")
);

CAmount nTotalAmount = 0;

// Iterate over all mints
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
if (GetAddressIndex(uint160(), AddressType::zerocoinMint, addressIndex)) {
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}
addressIndex.clear();

// Iterate over all spends
if (GetAddressIndex(uint160(), AddressType::zerocoinSpend, addressIndex)) {
for (std::vector < std::pair < CAddressIndexKey, CAmount > > ::const_iterator it = addressIndex.begin();
it != addressIndex.end(); it++) {
nTotalAmount += it->second;
}
}

return UniValue(nTotalAmount);
return getzerocoinpoolbalance();
}

UniValue getCVE17144amount(const JSONRPCRequest& request)
Expand All @@ -1842,32 +1877,8 @@ UniValue getCVE17144amount(const JSONRPCRequest& request)
+ HelpExampleCli("getCVE17144amount", "")
+ HelpExampleRpc("getCVE17144amount", "")
);
// as the attack happened at block 293526,
// get the block
CBlockIndex *mintBlock = chainActive[293526];
CBlock block;
if (!ReadBlockFromDisk(block, mintBlock, ::Params().GetConsensus())) {
throw std::runtime_error(std::string("can't read block 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)
{
if (!vInOutPoints.insert(txin.prevout).second) {
CTransactionRef tx;
uint256 hashBlock;
if (!GetTransaction(txin.prevout.hash, tx, Params().GetConsensus(), hashBlock, true)) {
continue;
}
amount += tx->vout[txin.prevout.n].nValue;
}
}
}
}
return amount;

return getCVE17144amount();
}

UniValue getinfoex(const JSONRPCRequest& request)
Expand Down

0 comments on commit 5019320

Please sign in to comment.