Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible state corruption when connecting blocks with lelantus/sigma #1365

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading