Skip to content

Commit

Permalink
Always check for duplicate anchor sigs (#706)
Browse files Browse the repository at this point in the history
* Always check for duplicate anchor sigs

* Update anchor test to always exclude dupes. Remove height arg.
  • Loading branch information
Bushstar authored Oct 22, 2021
1 parent d651501 commit 470cfd5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/masternodes/anchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,21 @@ CAnchor CAnchor::Create(const std::vector<CAnchorAuthMessage> & auths, CTxDestin
return {};
}

bool CAnchor::CheckAuthSigs(CTeam const & team, const uint32_t height) const
bool CAnchor::CheckAuthSigs(CTeam const & team) const
{
// Sigs must meet quorum size.
auto quorum = GetMinAnchorQuorum(team);
const auto quorum = GetMinAnchorQuorum(team);
if (sigs.size() < quorum) {
return error("%s: Anchor auth team quorum not met. Min quorum: %d sigs size %d", __func__, GetMinAnchorQuorum(team), sigs.size());
}

auto uniqueKeys = CheckSigs(GetSignHash(), sigs, team);
if (height >= Params().GetConsensus().EunosPayaHeight && uniqueKeys < quorum) {
return error("%s: Anchor auth team unique key quorum not met. Min quorum: %d keys size %d", __func__, GetMinAnchorQuorum(team), uniqueKeys);
// Number of unique sigs must meet the required quorum.
const auto uniqueKeys = CheckSigs(GetSignHash(), sigs, team);
if (uniqueKeys < quorum) {
return error("%s: Anchor auth team unique key quorum not met. Min quorum: %d keys size %d", __func__, quorum, uniqueKeys);
}

return uniqueKeys;
return true;
}

const CAnchorAuthIndex::Auth * CAnchorAuthIndex::GetAuth(uint256 const & msgHash) const
Expand Down Expand Up @@ -545,7 +546,7 @@ void CAnchorIndex::CheckPendingAnchors()
}

// Validate the anchor sigs
if (!rec.anchor.CheckAuthSigs(*anchorTeam, anchorCreationHeight)) {
if (!rec.anchor.CheckAuthSigs(*anchorTeam)) {
LogPrint(BCLog::ANCHORING, "Signature validation fails. Deleting anchor txHash %s\n", rec.txHash.ToString());
deletePending.insert(rec.txHash);
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/anchors.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class CAnchor : public CAnchorData
{}

static CAnchor Create(std::vector<CAnchorAuthMessage> const & auths, CTxDestination const & rewardDest);
bool CheckAuthSigs(CTeam const & team, const uint32_t height) const;
bool CheckAuthSigs(CTeam const & team) const;

ADD_SERIALIZE_METHODS;

Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3176,7 +3176,7 @@ ResVal<uint256> ApplyAnchorRewardTxPlus(CCustomCSView & mnview, CTransaction con
finMsg.sigs.size(), quorum);
}

if (anchorHeight >= Params().GetConsensus().EunosPayaHeight && uniqueKeys < quorum) {
if (uniqueKeys < quorum) {
return Res::ErrDbg("bad-ar-sigs-quorum", "anchor unique keys (%d) < min quorum (%) ",
uniqueKeys, quorum);
}
Expand Down
13 changes: 9 additions & 4 deletions src/test/anchor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,16 @@ BOOST_AUTO_TEST_CASE(Test_AnchorMsgCount)
anchor.sigs.push_back(authMsg.GetSignature());
}

// Double sig should included
BOOST_CHECK_EQUAL(anchor.CheckAuthSigs(team, 0), true);

// Double sig should excluded
BOOST_CHECK_EQUAL(anchor.CheckAuthSigs(team, std::numeric_limits<int>::max()), false);
BOOST_CHECK_EQUAL(anchor.CheckAuthSigs(team), false);

// Add one more signature
CAnchorAuthMessage authMsg{data};
authMsg.SignWithKey(signers.back());
anchor.sigs.push_back(authMsg.GetSignature());

// Should now meet quorum of unique keys
BOOST_CHECK_EQUAL(anchor.CheckAuthSigs(team), true);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 470cfd5

Please sign in to comment.