Skip to content

Commit

Permalink
Merge pull request #262 from carsenk/v3.3.9.7
Browse files Browse the repository at this point in the history
Fixes for Tx Null Data, Segfault Launch Fix, Ring Sig Tests
  • Loading branch information
metaspartan authored Jan 19, 2020
2 parents 96ca427 + 3bb9fcc commit 5c830a2
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const unsigned int MAX_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
//static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100; deprecated
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 10000; //Was 100, lets handle 10k
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; //Was 10k, lets handle 100
/** Default for -maxorphanblocks, maximum number of orphan blocks kept in memory */
static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 1000; //Default 750, Lets handle 1000
static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 750; //Default 750, Lets handle 1000 maybe?
static const unsigned int MAX_INV_SZ = 50000;
static const int64_t MIN_TX_FEE = 1000;
static const int64_t MIN_TX_FEE_ANON = 10000;
Expand Down
178 changes: 178 additions & 0 deletions src/test/ringsig_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include <boost/test/unit_test.hpp>

#include <boost/atomic.hpp>

#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>

#include <ctime>

#include "ringsig.h"
#include "main.h"

using namespace boost::chrono;

// test_shadow --log_level=all --run_test=ringsig_tests

clock_t totalGenerate;
clock_t totalVerify;
clock_t start, stop;

void testRingSigs(int nRingSize)
{
uint8_t *pPubkeys = (uint8_t*) malloc(sizeof(uint8_t) * EC_COMPRESSED_SIZE * nRingSize);
uint8_t *pSigc = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);
uint8_t *pSigr = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);

BOOST_REQUIRE(NULL != pPubkeys);
BOOST_REQUIRE(NULL != pSigc);
BOOST_REQUIRE(NULL != pSigr);

CKey key[nRingSize];
for (int i = 0; i < nRingSize; ++i)
{
key[i].MakeNewKey(true);

CPubKey pk = key[i].GetPubKey();

memcpy(&pPubkeys[i * EC_COMPRESSED_SIZE], pk.begin(), EC_COMPRESSED_SIZE);
};

uint256 preimage;
BOOST_CHECK(1 == RAND_bytes((uint8_t*) preimage.begin(), 32));
//BOOST_MESSAGE("Txn preimage: " << HexStr(preimage));

//BOOST_MESSAGE("nRingSize: " << nRingSize);
int iSender = GetRandInt(nRingSize);
//BOOST_MESSAGE("sender: " << iSender);

ec_secret sSpend;
ec_point pkSpend;
ec_point keyImage;

memcpy(&sSpend.e[0], key[iSender].begin(), EC_SECRET_SIZE);

BOOST_REQUIRE(0 == SecretToPublicKey(sSpend, pkSpend));

BOOST_REQUIRE(0 == generateKeyImage(pkSpend, sSpend, keyImage));

start = clock();
BOOST_REQUIRE(0 == generateRingSignature(keyImage, preimage, nRingSize, iSender, sSpend, pPubkeys, pSigc, pSigr));
stop = clock();
totalGenerate += stop - start;

start = clock();
BOOST_REQUIRE(0 == verifyRingSignature(keyImage, preimage, nRingSize, pPubkeys, pSigc, pSigr));
stop = clock();
totalVerify += stop - start;

int sigSize = EC_COMPRESSED_SIZE + EC_SECRET_SIZE + (EC_SECRET_SIZE + EC_SECRET_SIZE + EC_COMPRESSED_SIZE) * nRingSize;

BOOST_MESSAGE("nRingSize " << nRingSize << ", sigSize: " << bytesReadable(sigSize));

if (pPubkeys)
free(pPubkeys);
if (pSigc)
free(pSigc);
if (pSigr)
free(pSigr);
};

void testRingSigABs(int nRingSize)
{
uint8_t *pPubkeys = (uint8_t*) malloc(sizeof(uint8_t) * EC_COMPRESSED_SIZE * nRingSize);
uint8_t *pSigS = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);

BOOST_CHECK(NULL != pPubkeys);
BOOST_CHECK(NULL != pSigS);

CKey key[nRingSize];
for (int i = 0; i < nRingSize; ++i)
{
key[i].MakeNewKey(true);

CPubKey pk = key[i].GetPubKey();

memcpy(&pPubkeys[i * EC_COMPRESSED_SIZE], pk.begin(), EC_COMPRESSED_SIZE);
};

uint256 preimage;
BOOST_CHECK(1 == RAND_bytes((uint8_t*) preimage.begin(), 32));
//BOOST_MESSAGE("Txn preimage: " << HexStr(preimage));

int iSender = GetRandInt(nRingSize);
//BOOST_MESSAGE("sender: " << iSender);

ec_point pSigC;

ec_secret sSpend;
ec_point pkSpend;
ec_point keyImage;

memcpy(&sSpend.e[0], key[iSender].begin(), EC_SECRET_SIZE);

BOOST_CHECK(0 == SecretToPublicKey(sSpend, pkSpend));

BOOST_REQUIRE(0 == generateKeyImage(pkSpend, sSpend, keyImage));

start = clock();
BOOST_REQUIRE(0 == generateRingSignatureAB(keyImage, preimage, nRingSize, iSender, sSpend, pPubkeys, pSigC, pSigS));
stop = clock();
totalGenerate += stop - start;

start = clock();
BOOST_REQUIRE(0 == verifyRingSignatureAB(keyImage, preimage, nRingSize, pPubkeys, pSigC, pSigS));
stop = clock();
totalVerify += stop - start;

int sigSize = EC_COMPRESSED_SIZE + EC_SECRET_SIZE + EC_SECRET_SIZE + (EC_SECRET_SIZE + EC_COMPRESSED_SIZE) * nRingSize;

BOOST_MESSAGE("nRingSize " << nRingSize << ", sigSize: " << bytesReadable(sigSize));

if (pPubkeys)
free(pPubkeys);
if (pSigS)
free(pSigS);

};

BOOST_AUTO_TEST_SUITE(ringsig_tests)

BOOST_AUTO_TEST_CASE(ringsig)
{
BOOST_REQUIRE(0 == initialiseRingSigs());

BOOST_MESSAGE("testRingSigs");

for (int k = 1; k < 4; ++k)
{
//BOOST_MESSAGE("ringSize " << (k % 126 + 2));
testRingSigs(k % 126 + 2);
};
//testRingSigs(16);

BOOST_MESSAGE("totalGenerate " << (double(totalGenerate) / CLOCKS_PER_SEC));
BOOST_MESSAGE("totalVerify " << (double(totalVerify) / CLOCKS_PER_SEC));

totalGenerate = 0;
totalVerify = 0;
BOOST_MESSAGE("testRingSigABs");

for (int k = 0; k < 32; ++k)
{
//BOOST_MESSAGE("ringSize " << (k % 126 + 2));
//testRingSigABs(k % 126 + 2);
};
//testRingSigABs(16);

BOOST_MESSAGE("totalGenerate " << (double(totalGenerate) / CLOCKS_PER_SEC));
BOOST_MESSAGE("totalVerify " << (double(totalVerify) / CLOCKS_PER_SEC));

BOOST_CHECK(0 == finaliseRingSigs());
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion src/txdb-leveldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CTxDB::CTxDB(const char* pszMode)
bool fCreate = strchr(pszMode, 'c');

options = GetOptions();
options.create_if_missing = fCreate;
options.create_if_missing = true; //fCreate
options.filter_policy = leveldb::NewBloomFilterPolicy(10);

init_blockindex(options); // Init directory
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
if (::IsMine(*this, txout.scriptPubKey))
{
CTxDestination address;
if (!ExtractDestination(txout.scriptPubKey, address))
if (!ExtractDestination(txout.scriptPubKey, address) && txout.scriptPubKey[0] != OP_RETURN) //Fix Null TX Data
return true;

LOCK(cs_wallet);
Expand Down

0 comments on commit 5c830a2

Please sign in to comment.