Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
Update: Add overflow and coinbase TX catches
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoCoderz committed Jul 9, 2021
1 parent 56df7b7 commit 8ac1b94
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DigitalNote.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = DigitalNote-qt
VERSION = 1.0.3.9
VERSION = 1.0.4.0
INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor
QT += core gui widgets network printsupport
DEFINES += ENABLE_WALLET
Expand All @@ -25,7 +25,7 @@ BDB_LIB_PATH=C:/deps/db-6.2.32.NC/build_unix
OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.2u/include
OPENSSL_LIB_PATH=C:/deps/openssl-1.0.2u
MINIUPNPC_INCLUDE_PATH=C:/deps/
MINIUPNPC_LIB_PATH=C:/deps/miniupnpc
MINIUPNPC_LIB_PATH=C:/deps/miniupnpc-2.1
QRENCODE_INCLUDE_PATH=C:/deps/qrencode-4.0.2
QRENCODE_LIB_PATH=C:/deps/qrencode-4.0.2/.libs
SECP256K1_INCLUDE_PATH=C:/deps/secp256k1/include
Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 3
#define CLIENT_VERSION_BUILD 9
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 0

// Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
17 changes: 14 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,12 +1666,18 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes
const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const
{
MapPrevTx::const_iterator mi = inputs.find(input.prevout.hash);
if (mi == inputs.end())
if (mi == inputs.end()) {
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.hash not found");
}

const CTransaction& txPrev = (mi->second).second;
if (input.prevout.n >= txPrev.vout.size())
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.n out of range");
// Don't allow oversized outputs
if (input.prevout.n >= txPrev.vout.size()) {
// Skip if input is 0 (coinbase tx!)
if(!input.prevout.IsNull()) {
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.n out of range");
}
}

return txPrev.vout[input.prevout.n];
}
Expand Down Expand Up @@ -2959,6 +2965,11 @@ bool CBlock::AcceptBlock()
tx_outputs_values += tx.GetValueOut();
}

// Verify we haven't overflowed CAmount value or had NULL inputs/outpus in the block
if((tx_inputs_values + tx_threshold) <= 0) {
return DoS(100, error("AcceptBlock() : block contains a tx input that is less that output"));
}

// Ensure input/output sanity of transactions in the block
if((tx_inputs_values + tx_threshold) < tx_outputs_values)
{
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static const int DATABASE_VERSION = 70509;
//
// network protocol versioning
//
static const int PROTOCOL_VERSION = 62030;
static const int PROTOCOL_VERSION = 62031;

// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand Down

0 comments on commit 8ac1b94

Please sign in to comment.