Skip to content

Commit

Permalink
Fix possible state corruption when connecting blocks with lelantus/si…
Browse files Browse the repository at this point in the history
…gma (#1365)

* Fix possible corruption of Lelantus state

* Fixed possible corruption of Sigma state
  • Loading branch information
psolstice committed Nov 23, 2023
1 parent 02cd0e2 commit 9b4e7ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/lelantus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ bool CheckLelantusJoinSplitTransaction(
anonymity_sets[idAndHash.first] = anonymity_set;
}

const std::vector<uint32_t>& ids = joinsplit->getCoinGroupIds();
for (const auto& id: ids) {
if (!anonymity_sets.count(id))
return state.DoS(100,
error("CheckLelantusJoinSplitTransaction: No anonymity set found."));
}

BatchProofContainer* batchProofContainer = BatchProofContainer::get_instance();
bool useBatching = batchProofContainer->fCollectProofs && !isVerifyDB && !isCheckWallet && lelantusTxInfo && !lelantusTxInfo->fInfoIsComplete;

Expand Down Expand Up @@ -941,15 +948,17 @@ bool ConnectBlockLelantus(
)) {
return false;
}
}

if (!fJustCheck) {
if (!fJustCheck) {
BOOST_FOREACH(auto& serial, pblock->lelantusTxInfo->spentSerials) {
pindexNew->lelantusSpentSerials.insert(serial);
lelantusState.AddSpend(serial.first, serial.second);
}
}

if (fJustCheck)
else {
return true;
}

const auto& params = ::Params().GetConsensus();
CHash256 hash;
Expand Down Expand Up @@ -1359,9 +1368,8 @@ void CLelantusState::RemoveBlock(CBlockIndex *index) {
// roll back coin group updates
for (auto &coins : index->lelantusMintedPubCoins)
{
if (coinGroups.count(coins.first) == 0) {
throw std::invalid_argument("Group Id does not exist");
}
if (coinGroups.count(coins.first) == 0)
continue;

LelantusCoinGroupInfo& coinGroup = coinGroups[coins.first];
auto nMintsToForget = coins.second.size();
Expand Down
8 changes: 5 additions & 3 deletions src/sigma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,15 +643,17 @@ bool ConnectBlockSigma(
)) {
return false;
}
}

if (!fJustCheck) {
if (!fJustCheck) {
BOOST_FOREACH(auto& serial, pblock->sigmaTxInfo->spentSerials) {
pindexNew->sigmaSpentSerials.insert(serial);
sigmaState.AddSpend(serial.first, serial.second.denomination, serial.second.coinGroupId);
}
}

if (fJustCheck)
else {
return true;
}

sigmaState.AddMintsToStateAndBlockIndex(pindexNew, pblock);
}
Expand Down

0 comments on commit 9b4e7ef

Please sign in to comment.