Add check that vpubs are not both nonzero and test it.
This commit is contained in:
@@ -3,11 +3,18 @@ bin_PROGRAMS += zcash-gtest
|
|||||||
# tool for generating our public parameters
|
# tool for generating our public parameters
|
||||||
zcash_gtest_SOURCES = \
|
zcash_gtest_SOURCES = \
|
||||||
gtest/main.cpp \
|
gtest/main.cpp \
|
||||||
gtest/test_tautology.cpp
|
gtest/test_tautology.cpp \
|
||||||
|
gtest/test_checktransaction.cpp
|
||||||
|
|
||||||
zcash_gtest_LDADD = \
|
zcash_gtest_LDADD = -lgtest $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
|
||||||
-lgtest \
|
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1)
|
||||||
$(LIBBITCOIN_UTIL)
|
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_check: zcash-gtest FORCE
|
||||||
./zcash-gtest
|
./zcash-gtest
|
||||||
|
|||||||
26
src/gtest/test_checktransaction.cpp
Normal file
26
src/gtest/test_checktransaction.cpp
Normal file
@@ -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
20
src/main.cpp
@@ -881,26 +881,36 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
|
|||||||
// Ensure that pour values are well-formed
|
// Ensure that pour values are well-formed
|
||||||
BOOST_FOREACH(const CPourTx& pour, tx.vpour)
|
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"),
|
return state.DoS(100, error("CheckTransaction(): pour.vpub_old negative"),
|
||||||
REJECT_INVALID, "bad-txns-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"),
|
return state.DoS(100, error("CheckTransaction(): pour.vpub_new negative"),
|
||||||
REJECT_INVALID, "bad-txns-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"),
|
return state.DoS(100, error("CheckTransaction(): pour.vpub_old too high"),
|
||||||
REJECT_INVALID, "bad-txns-vpub_old-toolarge");
|
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"),
|
return state.DoS(100, error("CheckTransaction(): pour.vpub_new too high"),
|
||||||
REJECT_INVALID, "bad-txns-vpub_new-toolarge");
|
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;
|
nValueOut += pour.vpub_new;
|
||||||
if (!MoneyRange(nValueOut))
|
if (!MoneyRange(nValueOut)) {
|
||||||
return state.DoS(100, error("CheckTransaction(): txout total out of range"),
|
return state.DoS(100, error("CheckTransaction(): txout total out of range"),
|
||||||
REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user