2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2015-09-18 11:55:31 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "CryptoNoteCore/CryptoNoteBasicImpl.h"
|
|
|
|
#include "CryptoNoteCore/Account.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteTools.h"
|
|
|
|
#include "CryptoNoteCore/Currency.h"
|
2015-07-15 12:23:00 +00:00
|
|
|
|
|
|
|
#include <Common/Math.h>
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Chaingen.h"
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
using namespace CryptoNote;
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
bool test_transaction_generation_and_ring_signature()
|
|
|
|
{
|
2015-05-27 12:08:46 +00:00
|
|
|
Logging::ConsoleLogger logger;
|
|
|
|
CryptoNote::Currency currency = CryptoNote::CurrencyBuilder(logger).currency();
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc1;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc1.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc2;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc2.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc3;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc3.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc4;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc4.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc5;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc5.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase miner_acc6;
|
2014-03-03 22:07:58 +00:00
|
|
|
miner_acc6.generate();
|
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
std::string add_str = currency.accountAddressAsString(miner_acc3);
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase rv_acc;
|
2014-03-03 22:07:58 +00:00
|
|
|
rv_acc.generate();
|
2015-07-30 15:22:07 +00:00
|
|
|
AccountBase rv_acc2;
|
2014-03-03 22:07:58 +00:00
|
|
|
rv_acc2.generate();
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_1;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 10, 0, miner_acc1.getAccountKeys().address, tx_mine_1);
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_2;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 0, 0, miner_acc2.getAccountKeys().address, tx_mine_2);
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_3;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 0, 0, miner_acc3.getAccountKeys().address, tx_mine_3);
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_4;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 0, 0, miner_acc4.getAccountKeys().address, tx_mine_4);
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_5;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 0, 0, miner_acc5.getAccountKeys().address, tx_mine_5);
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_mine_6;
|
2015-07-30 15:22:07 +00:00
|
|
|
currency.constructMinerTx(0, 0, 0, 0, 0, miner_acc6.getAccountKeys().address, tx_mine_6);
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
//fill inputs entry
|
2015-07-30 15:22:07 +00:00
|
|
|
typedef TransactionSourceEntry::OutputEntry tx_output_entry;
|
|
|
|
std::vector<TransactionSourceEntry> sources;
|
2014-03-03 22:07:58 +00:00
|
|
|
sources.resize(sources.size()+1);
|
2015-07-30 15:22:07 +00:00
|
|
|
TransactionSourceEntry& src = sources.back();
|
2014-03-03 22:07:58 +00:00
|
|
|
src.amount = 70368744177663;
|
|
|
|
{
|
|
|
|
tx_output_entry oe;
|
|
|
|
oe.first = 0;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_1.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
|
|
|
oe.first = 1;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_2.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
|
|
|
oe.first = 2;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_3.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
|
|
|
oe.first = 3;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_4.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
|
|
|
oe.first = 4;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_5.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
|
|
|
oe.first = 5;
|
2015-07-30 15:22:07 +00:00
|
|
|
oe.second = boost::get<KeyOutput>(tx_mine_6.outputs[0].target).key;
|
2014-03-03 22:07:58 +00:00
|
|
|
src.outputs.push_back(oe);
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
src.realTransactionPublicKey = CryptoNote::getTransactionPublicKeyFromExtra(tx_mine_2.extra);
|
|
|
|
src.realOutput = 1;
|
|
|
|
src.realOutputIndexInTransaction = 0;
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
//fill outputs entry
|
2015-07-30 15:22:07 +00:00
|
|
|
TransactionDestinationEntry td;
|
|
|
|
td.addr = rv_acc.getAccountKeys().address;
|
2014-03-03 22:07:58 +00:00
|
|
|
td.amount = 69368744177663;
|
2015-07-30 15:22:07 +00:00
|
|
|
std::vector<TransactionDestinationEntry> destinations;
|
2014-03-03 22:07:58 +00:00
|
|
|
destinations.push_back(td);
|
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx_rc1;
|
2015-07-30 15:22:07 +00:00
|
|
|
bool r = constructTransaction(miner_acc2.getAccountKeys(), sources, destinations, std::vector<uint8_t>(), tx_rc1, 0, logger);
|
2014-03-03 22:07:58 +00:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
Crypto::Hash pref_hash = getObjectHash(*static_cast<TransactionPrefix*>(&tx_rc1));
|
|
|
|
std::vector<const Crypto::PublicKey *> output_keys;
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_1.outputs[0].target).key);
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_2.outputs[0].target).key);
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_3.outputs[0].target).key);
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_4.outputs[0].target).key);
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_5.outputs[0].target).key);
|
|
|
|
output_keys.push_back(&boost::get<KeyOutput>(tx_mine_6.outputs[0].target).key);
|
|
|
|
r = Crypto::check_ring_signature(pref_hash, boost::get<KeyInput>(tx_rc1.inputs[0]).keyImage,
|
2014-08-13 10:51:37 +00:00
|
|
|
output_keys, &tx_rc1.signatures[0][0]);
|
2014-03-03 22:07:58 +00:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "failed to check ring signature");
|
|
|
|
|
|
|
|
std::vector<size_t> outs;
|
|
|
|
uint64_t money = 0;
|
2014-04-02 16:00:17 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
r = lookup_acc_outs(rv_acc.getAccountKeys(), tx_rc1, getTransactionPublicKeyFromExtra(tx_rc1.extra), outs, money);
|
2014-03-03 22:07:58 +00:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
|
|
|
|
CHECK_AND_ASSERT_MES(td.amount == money, false, "wrong money amount in new transaction");
|
|
|
|
money = 0;
|
2015-07-30 15:22:07 +00:00
|
|
|
r = lookup_acc_outs(rv_acc2.getAccountKeys(), tx_rc1, getTransactionPublicKeyFromExtra(tx_rc1.extra), outs, money);
|
2014-03-03 22:07:58 +00:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "failed to lookup_acc_outs");
|
|
|
|
CHECK_AND_ASSERT_MES(0 == money, false, "wrong money amount in new transaction");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_block_creation()
|
|
|
|
{
|
2015-05-27 12:08:46 +00:00
|
|
|
Logging::ConsoleLogger logger;
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t vszs[] = {80,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,472,476,476,475,475,474,475,474,474,475,9391,476,476,475,475,474,475,8819,8301,475,472,4302,5316,14347,16620,19583,19403,19728,19442,19852,19015,19000,19016,19795,19749,18087,19787,19704,19750,19267,19006,19050,19445,19407,19522,19546,19788,19369,19486,19329,19370,18853,19600,19110,19320,19746,19474,19474,19743,19494,19755,19715,19769,19620,19368,19839,19532,23424,28287,30707};
|
|
|
|
std::vector<uint64_t> szs(&vszs[0], &vszs[90]);
|
2015-05-27 12:08:46 +00:00
|
|
|
CryptoNote::Currency currency = CryptoNote::CurrencyBuilder(logger).currency();
|
2014-08-13 10:51:37 +00:00
|
|
|
|
|
|
|
AccountPublicAddress adr;
|
|
|
|
bool r = currency.parseAccountAddressString("272xWzbWsP4cfNFfxY5ETN5moU8x81PKfWPwynrrqsNGDBQGLmD1kCkKCvPeDUXu5XfmZkCrQ53wsWmdfvHBGLNjGcRiDcK", adr);
|
2014-03-03 22:07:58 +00:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "failed to import");
|
2014-08-13 10:51:37 +00:00
|
|
|
Block b;
|
2015-07-30 15:22:07 +00:00
|
|
|
r = currency.constructMinerTx(90, Common::medianValue(szs), 3553616528562147, 33094, 10000000, adr, b.baseTransaction, BinaryArray(), 11);
|
2014-03-03 22:07:58 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool test_transactions()
|
|
|
|
{
|
|
|
|
if(!test_transaction_generation_and_ring_signature())
|
|
|
|
return false;
|
|
|
|
if(!test_block_creation())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|