Skip to content

Commit fdfd999

Browse files
committed
[zPIV[Unit Test] Possible redundant denomination validation.
1 parent 507f7c8 commit fdfd999

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/test/zerocoin_transactions_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ BOOST_AUTO_TEST_CASE(zerocoin_public_spend_test)
109109
BOOST_CHECK_MESSAGE(publicSpendTest.HasValidSignature(), "Failed to validate public spend signature");
110110
BOOST_CHECK_MESSAGE(spend->HasValidSignature(), "Failed to validate spend signature");
111111

112+
// Verify that fails with a different denomination
113+
in.nSequence = 500;
114+
PublicCoinSpend publicSpend2(ZCParams);
115+
BOOST_CHECK_MESSAGE(!ZPIVModule::validateInput(in, out, tx, publicSpend2), "Different denomination");
116+
112117
}
113118

114119
BOOST_AUTO_TEST_SUITE_END()

src/zpiv/zpivmodule.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ namespace ZPIVModule {
103103
bool validateInput(const CTxIn &in, const CTxOut &prevOut, const CTransaction &tx, PublicCoinSpend &publicSpend) {
104104
// Now prove that the commitment value opens to the input
105105
if (!parseCoinSpend(in, tx, prevOut, publicSpend)) {
106-
std::cout << "parse failed" << std::endl;
107106
return false;
108107
}
109-
// TODO: Validate that the prev out has the same spend denom?
108+
if (libzerocoin::ZerocoinDenominationToAmount(
109+
libzerocoin::IntToZerocoinDenomination(in.nSequence)) != prevOut.nValue) {
110+
return error("PublicCoinSpend validateInput :: input nSequence different to prevout value\n");
111+
}
112+
110113
return publicSpend.validate();
111114
}
112115

0 commit comments

Comments
 (0)