Browse Source

Add check that vpubs are not both nonzero and test it.

metaverse
Taylor Hornby 8 years ago
parent
commit
6ad4db2253
  1. 15
      src/Makefile.gtest.include
  2. 26
      src/gtest/test_checktransaction.cpp
  3. 20
      src/main.cpp

15
src/Makefile.gtest.include

@ -3,11 +3,18 @@ bin_PROGRAMS += zcash-gtest
# tool for generating our public parameters
zcash_gtest_SOURCES = \
gtest/main.cpp \
gtest/test_tautology.cpp
gtest/test_tautology.cpp \
gtest/test_checktransaction.cpp
zcash_gtest_LDADD = \
-lgtest \
$(LIBBITCOIN_UTIL)
zcash_gtest_LDADD = -lgtest $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1)
if ENABLE_WALLET
zcash_gtest_LDADD += $(LIBBITCOIN_WALLET)
endif
zcash_gtest_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZEROCASH) $(LIBZEROCASH_LIBS)
zcash_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
zcash-gtest_check: zcash-gtest FORCE
./zcash-gtest

26
src/gtest/test_checktransaction.cpp

@ -0,0 +1,26 @@
#include <gtest/gtest.h>
#include "main.h"
#include "primitives/transaction.h"
#include "consensus/validation.h"
TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
CMutableTransaction tx;
tx.nVersion = 2;
{
// Ensure that values within the pour are well-formed.
CMutableTransaction newTx(tx);
CValidationState state;
state.SetPerformPourVerification(false); // don't verify the snark
newTx.vpour.push_back(CPourTx());
CPourTx *pourtx = &newTx.vpour[0];
pourtx->vpub_old = 1;
pourtx->vpub_new = 1;
EXPECT_FALSE(CheckTransaction(newTx, state));
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
}
}

20
src/main.cpp

@ -881,26 +881,36 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
// Ensure that pour values are well-formed
BOOST_FOREACH(const CPourTx& pour, tx.vpour)
{
if (pour.vpub_old < 0)
if (pour.vpub_old < 0) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_old negative"),
REJECT_INVALID, "bad-txns-vpub_old-negative");
}
if (pour.vpub_new < 0)
if (pour.vpub_new < 0) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_new negative"),
REJECT_INVALID, "bad-txns-vpub_new-negative");
}
if (pour.vpub_old > MAX_MONEY)
if (pour.vpub_old > MAX_MONEY) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_old too high"),
REJECT_INVALID, "bad-txns-vpub_old-toolarge");
}
if (pour.vpub_new > MAX_MONEY)
if (pour.vpub_new > MAX_MONEY) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_new too high"),
REJECT_INVALID, "bad-txns-vpub_new-toolarge");
}
if (pour.vpub_new != 0 && pour.vpub_old != 0) {
return state.DoS(100, error("CheckTransaction(): pour.vpub_new and pour.vpub_old both nonzero"),
REJECT_INVALID, "bad-txns-vpubs-both-nonzero");
}
nValueOut += pour.vpub_new;
if (!MoneyRange(nValueOut))
if (!MoneyRange(nValueOut)) {
return state.DoS(100, error("CheckTransaction(): txout total out of range"),
REJECT_INVALID, "bad-txns-txouttotal-toolarge");
}
}

Loading…
Cancel
Save