fuzz_tests: refactor and add OSS-Fuzz compatibility

This commit is contained in:
moneromooo-monero 2020-05-15 17:17:24 +00:00
parent 77a008f714
commit 81773f55a4
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
16 changed files with 232 additions and 538 deletions

View file

@ -34,71 +34,26 @@
#include "wallet/wallet2.h"
#include "fuzzer.h"
class ColdTransactionFuzzer: public Fuzzer
{
public:
ColdTransactionFuzzer(): wallet(cryptonote::TESTNET) {}
virtual int init();
virtual int run(const std::string &filename);
static tools::wallet2 wallet;
private:
tools::wallet2 wallet;
};
int ColdTransactionFuzzer::init()
{
BEGIN_INIT_SIMPLE_FUZZER()
static const char * const spendkey_hex = "0b4f47697ec99c3de6579304e5f25c68b07afbe55b71d99620bf6cbf4e45a80f";
crypto::secret_key spendkey;
epee::string_tools::hex_to_pod(spendkey_hex, spendkey);
try
{
wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
}
catch (const std::exception &e)
{
std::cerr << "Error on ColdTransactionFuzzer::init: " << e.what() << std::endl;
return 1;
}
return 0;
}
wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
wallet.set_subaddress_lookahead(1, 1);
wallet.generate("", "", spendkey, true, false);
END_INIT_SIMPLE_FUZZER()
int ColdTransactionFuzzer::run(const std::string &filename)
{
std::string s;
if (!epee::file_io_utils::load_file_to_string(filename, s))
{
std::cout << "Error: failed to load file " << filename << std::endl;
return 1;
}
s = std::string("\x01\x16serialization::archive") + s;
try
{
tools::wallet2::unsigned_tx_set exported_txs;
std::stringstream iss;
iss << s;
boost::archive::portable_binary_iarchive ar(iss);
ar >> exported_txs;
std::vector<tools::wallet2::pending_tx> ptx;
bool success = wallet.sign_tx(exported_txs, "/tmp/cold-transaction-test-signed", ptx);
std::cout << (success ? "signed" : "error") << std::endl;
}
catch (const std::exception &e)
{
std::cerr << "Failed to sign transaction: " << e.what() << std::endl;
return 1;
}
return 0;
}
int main(int argc, const char **argv)
{
TRY_ENTRY();
ColdTransactionFuzzer fuzzer;
return run_fuzzer(argc, argv, fuzzer);
CATCH_ENTRY_L0("main", 1);
}
BEGIN_SIMPLE_FUZZER()
std::string s = std::string("\x01\x16serialization::archive") + std::string((const char*)buf, len);
tools::wallet2::unsigned_tx_set exported_txs;
std::stringstream iss;
iss << s;
boost::archive::portable_binary_iarchive ar(iss);
ar >> exported_txs;
std::vector<tools::wallet2::pending_tx> ptx;
bool success = wallet.sign_tx(exported_txs, "/tmp/cold-transaction-test-signed", ptx);
std::cout << (success ? "signed" : "error") << std::endl;
END_SIMPLE_FUZZER()