Split JoinSplit proof verification out of CheckTransaction.

This commit is contained in:
Taylor Hornby
2016-06-23 16:35:31 -06:00
parent cea9f58791
commit 948d4e6c10
6 changed files with 62 additions and 44 deletions

View File

@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <sodium.h>
#include "main.h"
#include "primitives/transaction.h"
@@ -13,7 +14,6 @@ TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
// 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());
@@ -21,7 +21,7 @@ TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
pourtx->vpub_old = 1;
pourtx->vpub_new = 1;
EXPECT_FALSE(CheckTransaction(newTx, state));
EXPECT_FALSE(CheckTransactionWithoutProofVerification(newTx, state));
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
}
}
@@ -31,8 +31,6 @@ public:
MOCK_METHOD5(DoS, bool(int level, bool ret,
unsigned char chRejectCodeIn, std::string strRejectReasonIn,
bool corruptionIn));
MOCK_METHOD1(SetPerformPourVerification, bool(bool pourVerifyIn));
MOCK_METHOD0(PerformPourVerification, bool());
MOCK_METHOD3(Invalid, bool(bool ret,
unsigned char _chRejectCode, std::string _strRejectReason));
MOCK_METHOD1(Error, bool(std::string strRejectReasonIn));
@@ -62,6 +60,30 @@ CMutableTransaction GetValidTransaction() {
mtx.vpour[0].serials.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
mtx.vpour[1].serials.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
mtx.vpour[1].serials.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000003");
// Generate an ephemeral keypair.
uint256 joinSplitPubKey;
unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES];
crypto_sign_keypair(joinSplitPubKey.begin(), joinSplitPrivKey);
mtx.joinSplitPubKey = joinSplitPubKey;
// Compute the correct hSig.
// TODO: #966.
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
// Empty output script.
CScript scriptCode;
CTransaction signTx(mtx);
uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL);
if (dataToBeSigned == one) {
throw std::runtime_error("SignatureHash failed");
}
// Add the signature
assert(crypto_sign_detached(&mtx.joinSplitSig[0], NULL,
dataToBeSigned.begin(), 32,
joinSplitPrivKey
) == 0);
return mtx;
}
@@ -69,7 +91,7 @@ TEST(checktransaction_tests, valid_transaction) {
CMutableTransaction mtx = GetValidTransaction();
CTransaction tx(mtx);
MockCValidationState state;
EXPECT_TRUE(CheckTransaction(tx, state));
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
}
TEST(checktransaction_tests, bad_txns_vin_empty) {
@@ -80,7 +102,7 @@ TEST(checktransaction_tests, bad_txns_vin_empty) {
CTransaction tx(mtx);
MockCValidationState state;
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vout_empty) {
@@ -92,7 +114,7 @@ TEST(checktransaction_tests, bad_txns_vout_empty) {
MockCValidationState state;
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_oversize) {
@@ -109,7 +131,7 @@ TEST(checktransaction_tests, bad_txns_oversize) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-oversize", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vout_negative) {
@@ -120,7 +142,7 @@ TEST(checktransaction_tests, bad_txns_vout_negative) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vout_toolarge) {
@@ -131,7 +153,7 @@ TEST(checktransaction_tests, bad_txns_vout_toolarge) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_outputs) {
@@ -143,7 +165,7 @@ TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_outputs) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_joinsplit) {
@@ -155,7 +177,7 @@ TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_joinsplit) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vpub_old_negative) {
@@ -166,7 +188,7 @@ TEST(checktransaction_tests, bad_txns_vpub_old_negative) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_old-negative", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vpub_new_negative) {
@@ -177,7 +199,7 @@ TEST(checktransaction_tests, bad_txns_vpub_new_negative) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_new-negative", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vpub_old_toolarge) {
@@ -188,7 +210,7 @@ TEST(checktransaction_tests, bad_txns_vpub_old_toolarge) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_old-toolarge", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vpub_new_toolarge) {
@@ -199,7 +221,7 @@ TEST(checktransaction_tests, bad_txns_vpub_new_toolarge) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_new-toolarge", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}
TEST(checktransaction_tests, bad_txns_vpubs_both_nonzero) {
@@ -211,5 +233,5 @@ TEST(checktransaction_tests, bad_txns_vpubs_both_nonzero) {
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpubs-both-nonzero", false)).Times(1);
CheckTransaction(tx, state);
CheckTransactionWithoutProofVerification(tx, state);
}