2016-04-13 15:52:24 -07:00
|
|
|
#include <gtest/gtest.h>
|
2016-06-15 16:01:55 -07:00
|
|
|
#include <gmock/gmock.h>
|
2016-06-23 15:35:31 -07:00
|
|
|
#include <sodium.h>
|
2016-04-13 15:52:24 -07:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "primitives/transaction.h"
|
|
|
|
#include "consensus/validation.h"
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
|
|
|
|
CMutableTransaction tx;
|
|
|
|
tx.nVersion = 2;
|
|
|
|
|
|
|
|
{
|
2016-07-14 15:51:36 -07:00
|
|
|
// Ensure that values within the joinsplit are well-formed.
|
2016-04-13 15:52:24 -07:00
|
|
|
CMutableTransaction newTx(tx);
|
|
|
|
CValidationState state;
|
|
|
|
|
2016-07-10 22:08:20 -07:00
|
|
|
newTx.vjoinsplit.push_back(JSDescription());
|
2016-04-13 15:52:24 -07:00
|
|
|
|
2016-07-14 15:51:36 -07:00
|
|
|
JSDescription *jsdesc = &newTx.vjoinsplit[0];
|
|
|
|
jsdesc->vpub_old = 1;
|
|
|
|
jsdesc->vpub_new = 1;
|
2016-04-13 15:52:24 -07:00
|
|
|
|
2016-06-23 15:35:31 -07:00
|
|
|
EXPECT_FALSE(CheckTransactionWithoutProofVerification(newTx, state));
|
2016-04-13 15:52:24 -07:00
|
|
|
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 16:01:55 -07:00
|
|
|
|
|
|
|
class MockCValidationState : public CValidationState {
|
|
|
|
public:
|
|
|
|
MOCK_METHOD5(DoS, bool(int level, bool ret,
|
|
|
|
unsigned char chRejectCodeIn, std::string strRejectReasonIn,
|
|
|
|
bool corruptionIn));
|
|
|
|
MOCK_METHOD3(Invalid, bool(bool ret,
|
|
|
|
unsigned char _chRejectCode, std::string _strRejectReason));
|
|
|
|
MOCK_METHOD1(Error, bool(std::string strRejectReasonIn));
|
|
|
|
MOCK_CONST_METHOD0(IsValid, bool());
|
|
|
|
MOCK_CONST_METHOD0(IsInvalid, bool());
|
|
|
|
MOCK_CONST_METHOD0(IsError, bool());
|
|
|
|
MOCK_CONST_METHOD1(IsInvalid, bool(int &nDoSOut));
|
|
|
|
MOCK_CONST_METHOD0(CorruptionPossible, bool());
|
|
|
|
MOCK_CONST_METHOD0(GetRejectCode, unsigned char());
|
|
|
|
MOCK_CONST_METHOD0(GetRejectReason, std::string());
|
|
|
|
};
|
|
|
|
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CMutableTransaction GetValidTransaction() {
|
|
|
|
CMutableTransaction mtx;
|
|
|
|
mtx.vin.resize(2);
|
2016-06-23 15:59:00 -07:00
|
|
|
mtx.vin[0].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
|
2016-06-22 16:25:35 -07:00
|
|
|
mtx.vin[0].prevout.n = 0;
|
2016-06-23 15:59:00 -07:00
|
|
|
mtx.vin[1].prevout.hash = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
|
2016-06-22 16:25:35 -07:00
|
|
|
mtx.vin[1].prevout.n = 0;
|
|
|
|
mtx.vout.resize(2);
|
|
|
|
// mtx.vout[0].scriptPubKey =
|
|
|
|
mtx.vout[0].nValue = 0;
|
|
|
|
mtx.vout[1].nValue = 0;
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit.resize(2);
|
|
|
|
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
|
|
|
mtx.vjoinsplit[0].nullifiers.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000001");
|
|
|
|
mtx.vjoinsplit[1].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000002");
|
|
|
|
mtx.vjoinsplit[1].nullifiers.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000003");
|
2016-06-23 15:35:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
2016-06-22 16:25:35 -07:00
|
|
|
return mtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, valid_transaction) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
MockCValidationState state;
|
2016-06-23 15:35:31 -07:00
|
|
|
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vin_empty) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit.resize(0);
|
2016-06-22 16:25:35 -07:00
|
|
|
mtx.vin.resize(0);
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
2016-06-15 16:01:55 -07:00
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-15 16:01:55 -07:00
|
|
|
}
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vout_empty) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit.resize(0);
|
2016-06-22 16:25:35 -07:00
|
|
|
mtx.vout.resize(0);
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_oversize) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
|
|
|
|
mtx.vin[0].scriptSig = CScript();
|
|
|
|
// 18 * (520char + DROP) + OP_1 = 9433 bytes
|
|
|
|
std::vector<unsigned char> vchData(520);
|
2016-07-14 11:17:01 -07:00
|
|
|
for (unsigned int i = 0; i < 4000; ++i)
|
2016-06-22 16:25:35 -07:00
|
|
|
mtx.vin[0].scriptSig << vchData << OP_DROP;
|
|
|
|
mtx.vin[0].scriptSig << OP_1;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-oversize", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vout_negative) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vout[0].nValue = -1;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vout_toolarge) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vout[0].nValue = MAX_MONEY + 1;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_outputs) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vout[0].nValue = MAX_MONEY;
|
|
|
|
mtx.vout[1].nValue = 1;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_txouttotal_toolarge_joinsplit) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vout[0].nValue = 1;
|
2016-09-05 11:18:43 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_old = MAX_MONEY;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
2016-09-05 11:18:43 -07:00
|
|
|
TEST(checktransaction_tests, bad_txns_txintotal_toolarge_joinsplit) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vjoinsplit[0].vpub_new = MAX_MONEY - 1;
|
|
|
|
mtx.vjoinsplit[1].vpub_new = MAX_MONEY - 1;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-txintotal-toolarge", false)).Times(1);
|
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
2016-06-22 16:25:35 -07:00
|
|
|
TEST(checktransaction_tests, bad_txns_vpub_old_negative) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_old = -1;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_old-negative", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vpub_new_negative) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_new = -1;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_new-negative", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vpub_old_toolarge) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_old = MAX_MONEY + 1;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_old-toolarge", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vpub_new_toolarge) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_new = MAX_MONEY + 1;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpub_new-toolarge", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_vpubs_both_nonzero) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].vpub_old = 1;
|
|
|
|
mtx.vjoinsplit[0].vpub_new = 1;
|
2016-06-22 16:25:35 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-vpubs-both-nonzero", false)).Times(1);
|
2016-06-23 15:35:31 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
2016-06-22 16:25:35 -07:00
|
|
|
}
|
2016-06-23 15:59:00 -07:00
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_inputs_duplicate) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vin[1].prevout.hash = mtx.vin[0].prevout.hash;
|
|
|
|
mtx.vin[1].prevout.n = mtx.vin[0].prevout.n;
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate", false)).Times(1);
|
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
2016-07-14 15:51:36 -07:00
|
|
|
TEST(checktransaction_tests, bad_joinsplits_nullifiers_duplicate_same_joinsplit) {
|
2016-06-23 15:59:00 -07:00
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
|
|
|
mtx.vjoinsplit[0].nullifiers.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
2016-06-23 15:59:00 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
2016-07-14 15:51:36 -07:00
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-joinsplits-nullifiers-duplicate", false)).Times(1);
|
2016-06-23 15:59:00 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
2016-07-14 15:51:36 -07:00
|
|
|
TEST(checktransaction_tests, bad_joinsplits_nullifiers_duplicate_different_joinsplit) {
|
2016-06-23 15:59:00 -07:00
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
|
|
|
mtx.vjoinsplit[1].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
2016-06-23 15:59:00 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
2016-07-14 15:51:36 -07:00
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-joinsplits-nullifiers-duplicate", false)).Times(1);
|
2016-06-23 15:59:00 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
2016-07-14 15:51:36 -07:00
|
|
|
TEST(checktransaction_tests, bad_cb_has_joinsplits) {
|
2016-06-23 15:59:00 -07:00
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
// Make it a coinbase.
|
|
|
|
mtx.vin.resize(1);
|
|
|
|
mtx.vin[0].prevout.SetNull();
|
|
|
|
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit.resize(1);
|
2016-06-23 15:59:00 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
EXPECT_TRUE(tx.IsCoinBase());
|
|
|
|
|
|
|
|
MockCValidationState state;
|
2016-07-14 15:51:36 -07:00
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-cb-has-joinsplits", false)).Times(1);
|
2016-06-23 15:59:00 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_cb_empty_scriptsig) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
// Make it a coinbase.
|
|
|
|
mtx.vin.resize(1);
|
|
|
|
mtx.vin[0].prevout.SetNull();
|
|
|
|
|
2016-07-14 13:16:59 -07:00
|
|
|
mtx.vjoinsplit.resize(0);
|
2016-06-23 15:59:00 -07:00
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
EXPECT_TRUE(tx.IsCoinBase());
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-cb-length", false)).Times(1);
|
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_prevout_null) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.vin[1].prevout.SetNull();
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
EXPECT_FALSE(tx.IsCoinBase());
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null", false)).Times(1);
|
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(checktransaction_tests, bad_txns_invalid_joinsplit_signature) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
mtx.joinSplitSig[0] += 1;
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|
2016-06-23 17:22:20 -07:00
|
|
|
|
|
|
|
TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
|
|
|
CMutableTransaction mtx = GetValidTransaction();
|
|
|
|
|
2016-08-18 15:38:20 -07:00
|
|
|
// Check that the signature is valid before we add L
|
|
|
|
{
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
MockCValidationState state;
|
|
|
|
EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state));
|
|
|
|
}
|
|
|
|
|
2016-06-23 17:22:20 -07:00
|
|
|
// Copied from libsodium/crypto_sign/ed25519/ref10/open.c
|
|
|
|
static const unsigned char L[32] =
|
|
|
|
{ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
|
|
|
|
0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
|
|
|
|
|
|
|
|
// Add L to S, which starts at mtx.joinSplitSig[32].
|
|
|
|
unsigned int s = 0;
|
|
|
|
for (size_t i = 0; i < 32; i++) {
|
|
|
|
s = mtx.joinSplitSig[32 + i] + L[i] + (s >> 8);
|
|
|
|
mtx.joinSplitSig[32 + i] = s & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTransaction tx(mtx);
|
|
|
|
|
|
|
|
MockCValidationState state;
|
2016-08-18 15:38:20 -07:00
|
|
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
2016-06-23 17:22:20 -07:00
|
|
|
CheckTransactionWithoutProofVerification(tx, state);
|
|
|
|
}
|