Permalink
Browse files

preventing DoS attacks using invalid proposals that are also valid tr…

…ansactions
  • Loading branch information...
IgorDurovic committed Apr 26, 2018
1 parent a4aabf8 commit f2051c2ae4b688aace5cc756278586985de2e44f
Showing with 50 additions and 48 deletions.
  1. +2 −48 .gitignore
  2. +11 −0 src/main.cpp
  3. +36 −0 src/voteproposalmanager.cpp
  4. +1 −0 src/voteproposalmanager.h
View
@@ -47,60 +47,14 @@ src/qt/.deps
src/qt/.dirstamp
src/qt/bitcoin.moc
src/qt/bitcoinamountfield.moc
src/qt/moc_aboutdialog.cpp
src/qt/moc_addressbookpage.cpp
src/qt/moc_addresstablemodel.cpp
src/qt/moc_askpassphrasedialog.cpp
src/qt/moc_bip38tooldialog.cpp
src/qt/moc_bitcoinaddressvalidator.cpp
src/qt/moc_bitcoinamountfield.cpp
src/qt/moc_bitcoingui.cpp
src/qt/moc_bitcoinunits.cpp
src/qt/moc_clientmodel.cpp
src/qt/moc_coincontroldialog.cpp
src/qt/moc_coincontroltreewidget.cpp
src/qt/moc_csvmodelwriter.cpp
src/qt/moc_editaddressdialog.cpp
src/qt/moc_guiutil.cpp
src/qt/moc_macdockiconhandler.cpp
src/qt/moc_monitoreddatamapper.cpp
src/qt/moc_notificator.cpp
src/qt/moc_optionsdialog.cpp
src/qt/moc_optionsmodel.cpp
src/qt/moc_overviewpage.cpp
src/qt/moc_qrcodedialog.cpp
src/qt/moc_qvalidatedlineedit.cpp
src/qt/moc_qvaluecombobox.cpp
src/qt/moc_rpcconsole.cpp
src/qt/moc_sendcoinsdialog.cpp
src/qt/moc_sendcoinsentry.cpp
src/qt/moc_signverifymessagedialog.cpp
src/qt/moc_transactiondesc.cpp
src/qt/moc_transactiondescdialog.cpp
src/qt/moc_transactionfilterproxy.cpp
src/qt/moc_transactiontablemodel.cpp
src/qt/moc_transactionview.cpp
src/qt/moc_walletmodel.cpp
src/qt/moc_*
src/qt/overviewpage.moc
src/qt/rpcconsole.moc
Makefile.in
src/config/bitcoin-config.h
src/config/bitcoin-config.h.in
src/config/stamp-h1
src/qt/forms/ui_aboutdialog.h
src/qt/forms/ui_addressbookpage.h
src/qt/forms/ui_askpassphrasedialog.h
src/qt/forms/ui_bip38tooldialog.h
src/qt/forms/ui_coincontroldialog.h
src/qt/forms/ui_editaddressdialog.h
src/qt/forms/ui_optionsdialog.h
src/qt/forms/ui_overviewpage.h
src/qt/forms/ui_qrcodedialog.h
src/qt/forms/ui_rpcconsole.h
src/qt/forms/ui_sendcoinsdialog.h
src/qt/forms/ui_sendcoinsentry.h
src/qt/forms/ui_signverifymessagedialog.h
src/qt/forms/ui_transactiondescdialog.h
src/qt/forms/ui_*
config.log
config.status
libtool
View
@@ -711,6 +711,17 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs,
if (ptxOld)
EraseFromWallets(ptxOld->GetHash());
// If the transaction is a proposal then verify validity
if (tx.IsProposal()) {
CVoteProposal proposal;
ProposalFromTransaction(tx, proposal);
// Verify that the proposal is valid
if(!proposalManager.CheckProposal(proposal)) {
return error("CTxMemPool::accept() : Invalid Proposal %s", hash.ToString().substr(0,10).c_str());
}
}
printf("CTxMemPool::accept() : accepted %s (poolsz %lu)\n",
hash.ToString().substr(0,10).c_str(),
mapTx.size());
@@ -7,6 +7,42 @@
using namespace std;
bool CVoteProposalManager::CheckProposal(const CVoteProposal &proposal)
{
// If the proposal is already in the blockchain then it's guaranteed to be valid
if (mapProposalData.count(proposal.GetHash()) != 0) {
return true;
}
// Proposal name length must be between 1 and MAX_CHAR_NAME (inclusive)
if (proposal.GetName().empty() || proposal.GetName().size() > MAX_CHAR_NAME) {
return false;
}
// Proposal description length must be between 1 and MAX_CHAR_ABSTRACT (inclusive)
if (proposal.GetDescription().empty() || proposal.GetDescription().size() > MAX_CHAR_ABSTRACT) {
return false;
}
// Proposal voting period cannot start before or at the current height or after MAX_BLOCKS_IN_FUTURE
if (proposal.GetStartHeight() <= nBestHeight || proposal.GetStartHeight() > nBestHeight + MAX_BLOCKS_IN_FUTURE) {
return false;
}
// Proposal voting period length must be between 1 and MAX_CHECKSPAN (inclusive)
if (!proposal.GetCheckSpan() || proposal.GetCheckSpan() > MAX_CHECKSPAN) {
return false;
}
// Check to see if there is room on the blockchain for this proposal
VoteLocation location;
if (!GetNextLocation(proposal.GetBitCount(), proposal.GetStartHeight(), proposal.GetCheckSpan(), location)) {
return false;
}
return true;
}
//! Add a proposal to the manager. Note that it must not have conflicts in its scheduling.
bool CVoteProposalManager::Add(const CVoteProposal& proposal)
{
@@ -28,6 +28,7 @@ class CVoteProposalManager
std::map<uint256, VoteLocation> GetActive(int nHeight);
bool GetNextLocation(int nBitCount, int nStartHeight, int nCheckSpan, VoteLocation& location);
std::map<uint256, CProposalMetaData> GetAllProposals() const { return mapProposalData; };
bool CheckProposal (const CVoteProposal& proposal);
};
#endif //HYPERSTAKE_VOTEPROPOSALMANAGER_H

0 comments on commit f2051c2

Please sign in to comment.