Skip to content

Commit 3bb9fcc

Browse files
committed
Fixes for Tx Null Data, Segfault Launch Fix, Ring Sig Tests
1 parent 96ca427 commit 3bb9fcc

File tree

4 files changed

+182
-4
lines changed

4 files changed

+182
-4
lines changed

src/main.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
6969
static const unsigned int MAX_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
7070
//static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100; deprecated
7171
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
72-
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 10000; //Was 100, lets handle 10k
72+
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; //Was 10k, lets handle 100
7373
/** Default for -maxorphanblocks, maximum number of orphan blocks kept in memory */
74-
static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 1000; //Default 750, Lets handle 1000
74+
static const unsigned int DEFAULT_MAX_ORPHAN_BLOCKS = 750; //Default 750, Lets handle 1000 maybe?
7575
static const unsigned int MAX_INV_SZ = 50000;
7676
static const int64_t MIN_TX_FEE = 1000;
7777
static const int64_t MIN_TX_FEE_ANON = 10000;

src/test/ringsig_tests.cpp

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#include <boost/test/unit_test.hpp>
2+
3+
#include <boost/atomic.hpp>
4+
5+
#include <openssl/err.h>
6+
#include <openssl/rand.h>
7+
#include <openssl/ec.h>
8+
#include <openssl/bn.h>
9+
#include <openssl/ecdsa.h>
10+
#include <openssl/obj_mac.h>
11+
12+
#include <ctime>
13+
14+
#include "ringsig.h"
15+
#include "main.h"
16+
17+
using namespace boost::chrono;
18+
19+
// test_shadow --log_level=all --run_test=ringsig_tests
20+
21+
clock_t totalGenerate;
22+
clock_t totalVerify;
23+
clock_t start, stop;
24+
25+
void testRingSigs(int nRingSize)
26+
{
27+
uint8_t *pPubkeys = (uint8_t*) malloc(sizeof(uint8_t) * EC_COMPRESSED_SIZE * nRingSize);
28+
uint8_t *pSigc = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);
29+
uint8_t *pSigr = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);
30+
31+
BOOST_REQUIRE(NULL != pPubkeys);
32+
BOOST_REQUIRE(NULL != pSigc);
33+
BOOST_REQUIRE(NULL != pSigr);
34+
35+
CKey key[nRingSize];
36+
for (int i = 0; i < nRingSize; ++i)
37+
{
38+
key[i].MakeNewKey(true);
39+
40+
CPubKey pk = key[i].GetPubKey();
41+
42+
memcpy(&pPubkeys[i * EC_COMPRESSED_SIZE], pk.begin(), EC_COMPRESSED_SIZE);
43+
};
44+
45+
uint256 preimage;
46+
BOOST_CHECK(1 == RAND_bytes((uint8_t*) preimage.begin(), 32));
47+
//BOOST_MESSAGE("Txn preimage: " << HexStr(preimage));
48+
49+
//BOOST_MESSAGE("nRingSize: " << nRingSize);
50+
int iSender = GetRandInt(nRingSize);
51+
//BOOST_MESSAGE("sender: " << iSender);
52+
53+
ec_secret sSpend;
54+
ec_point pkSpend;
55+
ec_point keyImage;
56+
57+
memcpy(&sSpend.e[0], key[iSender].begin(), EC_SECRET_SIZE);
58+
59+
BOOST_REQUIRE(0 == SecretToPublicKey(sSpend, pkSpend));
60+
61+
BOOST_REQUIRE(0 == generateKeyImage(pkSpend, sSpend, keyImage));
62+
63+
start = clock();
64+
BOOST_REQUIRE(0 == generateRingSignature(keyImage, preimage, nRingSize, iSender, sSpend, pPubkeys, pSigc, pSigr));
65+
stop = clock();
66+
totalGenerate += stop - start;
67+
68+
start = clock();
69+
BOOST_REQUIRE(0 == verifyRingSignature(keyImage, preimage, nRingSize, pPubkeys, pSigc, pSigr));
70+
stop = clock();
71+
totalVerify += stop - start;
72+
73+
int sigSize = EC_COMPRESSED_SIZE + EC_SECRET_SIZE + (EC_SECRET_SIZE + EC_SECRET_SIZE + EC_COMPRESSED_SIZE) * nRingSize;
74+
75+
BOOST_MESSAGE("nRingSize " << nRingSize << ", sigSize: " << bytesReadable(sigSize));
76+
77+
if (pPubkeys)
78+
free(pPubkeys);
79+
if (pSigc)
80+
free(pSigc);
81+
if (pSigr)
82+
free(pSigr);
83+
};
84+
85+
void testRingSigABs(int nRingSize)
86+
{
87+
uint8_t *pPubkeys = (uint8_t*) malloc(sizeof(uint8_t) * EC_COMPRESSED_SIZE * nRingSize);
88+
uint8_t *pSigS = (uint8_t*) malloc(sizeof(uint8_t) * EC_SECRET_SIZE * nRingSize);
89+
90+
BOOST_CHECK(NULL != pPubkeys);
91+
BOOST_CHECK(NULL != pSigS);
92+
93+
CKey key[nRingSize];
94+
for (int i = 0; i < nRingSize; ++i)
95+
{
96+
key[i].MakeNewKey(true);
97+
98+
CPubKey pk = key[i].GetPubKey();
99+
100+
memcpy(&pPubkeys[i * EC_COMPRESSED_SIZE], pk.begin(), EC_COMPRESSED_SIZE);
101+
};
102+
103+
uint256 preimage;
104+
BOOST_CHECK(1 == RAND_bytes((uint8_t*) preimage.begin(), 32));
105+
//BOOST_MESSAGE("Txn preimage: " << HexStr(preimage));
106+
107+
int iSender = GetRandInt(nRingSize);
108+
//BOOST_MESSAGE("sender: " << iSender);
109+
110+
ec_point pSigC;
111+
112+
ec_secret sSpend;
113+
ec_point pkSpend;
114+
ec_point keyImage;
115+
116+
memcpy(&sSpend.e[0], key[iSender].begin(), EC_SECRET_SIZE);
117+
118+
BOOST_CHECK(0 == SecretToPublicKey(sSpend, pkSpend));
119+
120+
BOOST_REQUIRE(0 == generateKeyImage(pkSpend, sSpend, keyImage));
121+
122+
start = clock();
123+
BOOST_REQUIRE(0 == generateRingSignatureAB(keyImage, preimage, nRingSize, iSender, sSpend, pPubkeys, pSigC, pSigS));
124+
stop = clock();
125+
totalGenerate += stop - start;
126+
127+
start = clock();
128+
BOOST_REQUIRE(0 == verifyRingSignatureAB(keyImage, preimage, nRingSize, pPubkeys, pSigC, pSigS));
129+
stop = clock();
130+
totalVerify += stop - start;
131+
132+
int sigSize = EC_COMPRESSED_SIZE + EC_SECRET_SIZE + EC_SECRET_SIZE + (EC_SECRET_SIZE + EC_COMPRESSED_SIZE) * nRingSize;
133+
134+
BOOST_MESSAGE("nRingSize " << nRingSize << ", sigSize: " << bytesReadable(sigSize));
135+
136+
if (pPubkeys)
137+
free(pPubkeys);
138+
if (pSigS)
139+
free(pSigS);
140+
141+
};
142+
143+
BOOST_AUTO_TEST_SUITE(ringsig_tests)
144+
145+
BOOST_AUTO_TEST_CASE(ringsig)
146+
{
147+
BOOST_REQUIRE(0 == initialiseRingSigs());
148+
149+
BOOST_MESSAGE("testRingSigs");
150+
151+
for (int k = 1; k < 4; ++k)
152+
{
153+
//BOOST_MESSAGE("ringSize " << (k % 126 + 2));
154+
testRingSigs(k % 126 + 2);
155+
};
156+
//testRingSigs(16);
157+
158+
BOOST_MESSAGE("totalGenerate " << (double(totalGenerate) / CLOCKS_PER_SEC));
159+
BOOST_MESSAGE("totalVerify " << (double(totalVerify) / CLOCKS_PER_SEC));
160+
161+
totalGenerate = 0;
162+
totalVerify = 0;
163+
BOOST_MESSAGE("testRingSigABs");
164+
165+
for (int k = 0; k < 32; ++k)
166+
{
167+
//BOOST_MESSAGE("ringSize " << (k % 126 + 2));
168+
//testRingSigABs(k % 126 + 2);
169+
};
170+
//testRingSigABs(16);
171+
172+
BOOST_MESSAGE("totalGenerate " << (double(totalGenerate) / CLOCKS_PER_SEC));
173+
BOOST_MESSAGE("totalVerify " << (double(totalVerify) / CLOCKS_PER_SEC));
174+
175+
BOOST_CHECK(0 == finaliseRingSigs());
176+
}
177+
178+
BOOST_AUTO_TEST_SUITE_END()

src/txdb-leveldb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CTxDB::CTxDB(const char* pszMode)
7979
bool fCreate = strchr(pszMode, 'c');
8080

8181
options = GetOptions();
82-
options.create_if_missing = fCreate;
82+
options.create_if_missing = true; //fCreate
8383
options.filter_policy = leveldb::NewBloomFilterPolicy(10);
8484

8585
init_blockindex(options); // Init directory

src/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
980980
if (::IsMine(*this, txout.scriptPubKey))
981981
{
982982
CTxDestination address;
983-
if (!ExtractDestination(txout.scriptPubKey, address))
983+
if (!ExtractDestination(txout.scriptPubKey, address) && txout.scriptPubKey[0] != OP_RETURN) //Fix Null TX Data
984984
return true;
985985

986986
LOCK(cs_wallet);

0 commit comments

Comments
 (0)