Skip to content

Commit 1d185aa

Browse files
Merge pull request #5 from KomodoPlatform/dev
Dev
2 parents aad6c7f + 42a2cb6 commit 1d185aa

39 files changed

+420
-295
lines changed

COPYING

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Copyright (c) 2009-2017 The Bitcoin Core developers
22
Copyright (c) 2009-2018 Bitcoin Developers
33
Copyright (c) 2016-2017 The Zcash developers
4-
Copyright (c) 2016-2019 The Komodo developers
4+
Copyright (c) 2016-2020 The Komodo developers
55
Copyright (c) 2018 The VerusCoin developers
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy

src/Makefile.gtest.include

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2016-2020 The Zcash developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
14

25
TESTS += komodo-gtest
36
bin_PROGRAMS += komodo-gtest

src/Makefile.test.include

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ BITCOIN_TESTS =\
9797
test/skiplist_tests.cpp \
9898
test/test_bitcoin.cpp \
9999
test/test_bitcoin.h \
100-
test/timedata_tests.cpp \
101100
test/torcontrol_tests.cpp \
102101
test/transaction_tests.cpp \
103102
test/uint256_tests.cpp \

src/ac/wlc

-2
This file was deleted.

src/addrman.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
268268

269269
if (pinfo) {
270270
// periodically update nTime
271-
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
271+
bool fCurrentlyOnline = (GetTime() - addr.nTime < 24 * 60 * 60);
272272
int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
273273
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
274274
pinfo->nTime = std::max((int64_t)0, addr.nTime - nTimePenalty);

src/addrman.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ class CAddrInfo : public CAddress
112112
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
113113

114114
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
115-
bool IsTerrible(int64_t nNow = GetAdjustedTime()) const;
115+
bool IsTerrible(int64_t nNow = GetTime()) const;
116116

117117
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
118-
double GetChance(int64_t nNow = GetAdjustedTime()) const;
118+
double GetChance(int64_t nNow = GetTime()) const;
119119

120120
};
121121

@@ -530,7 +530,7 @@ class CAddrMan
530530
}
531531

532532
//! Mark an entry as accessible.
533-
void Good(const CService &addr, int64_t nTime = GetAdjustedTime())
533+
void Good(const CService &addr, int64_t nTime = GetTime())
534534
{
535535
{
536536
LOCK(cs);
@@ -541,7 +541,7 @@ class CAddrMan
541541
}
542542

543543
//! Mark an entry as connection attempted to.
544-
void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime())
544+
void Attempt(const CService &addr, int64_t nTime = GetTime())
545545
{
546546
{
547547
LOCK(cs);
@@ -580,7 +580,7 @@ class CAddrMan
580580
}
581581

582582
//! Mark an entry as currently-connected-to.
583-
void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
583+
void Connected(const CService &addr, int64_t nTime = GetTime())
584584
{
585585
{
586586
LOCK(cs);

src/alert.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ uint256 CAlert::GetHash() const
117117

118118
bool CAlert::IsInEffect() const
119119
{
120-
return (GetAdjustedTime() < nExpiration);
120+
return (GetTime() < nExpiration);
121121
}
122122

123123
bool CAlert::Cancels(const CAlert& alert) const
@@ -152,7 +152,7 @@ bool CAlert::RelayTo(CNode* pnode) const
152152
{
153153
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
154154
AppliesToMe() ||
155-
GetAdjustedTime() < nRelayUntil)
155+
GetTime() < nRelayUntil)
156156
{
157157
pnode->PushMessage("alert", *this);
158158
return true;

src/assetchains.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
},
100100
{
101101
"ac_name": "MESH",
102-
"ac_supply": "1000007"
102+
"ac_supply": "1000007",
103+
"ac_ccactivate": "320000"
103104
},
104105
{
105106
"ac_name": "MGW",
@@ -245,10 +246,6 @@
245246
"185.64.105.111"
246247
]
247248
},
248-
{
249-
"ac_name": "WLC",
250-
"ac_supply": "210000000"
251-
},
252249
{
253250
"ac_name": "WLC21",
254251
"ac_supply": "21000000",

src/assetchains.old

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ echo $pubkey
1414
./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=95.213.238.98 $1 &
1515
./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=95.213.238.98 &
1616
./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=95.213.238.98 $1 &
17-
~/hush3/src/komodod -pubkey=$pubkey -ac_name=HUSH3 -ac_sapling=1 -ac_reward=0,1125000000,562500000 -ac_halving=129,340000,840000 -ac_end=128,340000,5422111 -ac_eras=3 -ac_blocktime=150 -ac_cc=2 -ac_ccenable=228,234,235,236,241 -ac_founders=1 -ac_supply=6178674 -ac_perc=11111111 -clientname=GoldenSandtrout -addnode=188.165.212.101 -addnode=136.243.227.142 -addnode=5.9.224.250 -ac_cclib=hush3 -ac_script=76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac &
1817
./komodod -pubkey=$pubkey -ac_name=ILN -ac_supply=10000000000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=51.75.122.83 &
1918
./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=95.213.238.98 $1 &
2019
./komodod -pubkey=$pubkey -ac_name=K64 -ac_supply=64000777 -ac_reward=0 -ac_staked=10 -addnode=18.197.20.211 &
2120
./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 &
2221
./komodod -pubkey=$pubkey -ac_name=KSB -ac_supply=1000000000 -ac_end=1 -ac_public=1 -addnode=37.187.225.231 &
2322
./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=95.213.238.98 $1 &
24-
./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -addnode=95.213.238.98 $1 &
23+
./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -ac_ccactivate=320000 -addnode=95.213.238.98 $1 &
2524
./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=95.213.238.98 $1 &
2625
./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=95.217.44.58 -addnode=138.201.136.145 &
2726
./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=95.213.238.98 $1 &
@@ -40,7 +39,6 @@ echo $pubkey
4039
./komodod -pubkey=$pubkey -ac_name=THC -ac_supply=251253103 -ac_reward=360000000,300000000,240000000,180000000,150000000,90000000,0 -ac_staked=100 -ac_eras=7 -ac_end=500001,1000001,1500001,2000001,2500001,4500001,0 -ac_perc=233333333 -ac_cc=2 -ac_ccenable=229,236,240 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_cbmaturity=1 -ac_sapling=1 -addnode=157.230.45.184 -addnode=165.22.52.123 -earlytxid=7e4a76259e99c9379551389e9f757fc5f46c33ae922a8644dc2b187af2a6adc1 &
4140
~/VerusCoin/src/verusd -pubkey=$pubkey &
4241
./komodod -pubkey=$pubkey -ac_public=1 -ac_name=VOTE2020 -ac_supply=123651638 -addnode=95.213.238.98 &
43-
./komodod -pubkey=$pubkey -ac_name=WLC -ac_supply=210000000 -addnode=95.213.238.98 $1 &
4442
./komodod -pubkey=$pubkey -ac_name=WLC21 -ac_supply=21000000 -ac_reward=190258751 -ac_staked=90 -ac_public=1 -addnode=37.187.225.231 -addnode=51.38.38.134 &
4543
./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 &
4644
./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -ac_sapling=5000000 -addnode=51.68.215.104 &

src/cryptoconditions/src/anon.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ static void anonToJSON(const CC *cond, cJSON *params) {
5353
}
5454

5555

56-
static unsigned char *anonFingerprint(const CC *cond) {
57-
unsigned char *out = calloc(1, 32);
58-
//fprintf(stderr,"anon fingerprint %p %p\n",out,cond->fingerprint);
56+
static void anonFingerprint(const CC *cond, uint8_t *out) {
5957
memcpy(out, cond->fingerprint, 32);
60-
return out;
6158
}
6259

6360

src/cryptoconditions/src/cryptoconditions.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void appendUriSubtypes(uint32_t mask, unsigned char *buf) {
6262

6363

6464
char *cc_conditionUri(const CC *cond) {
65-
unsigned char *fp = cond->type->fingerprint(cond);
66-
if (!fp) return NULL;
65+
unsigned char *fp = calloc(1, 32);
66+
cond->type->fingerprint(cond, fp);
6767

6868
unsigned char *encoded = base64_encode(fp, 32);
6969

@@ -116,13 +116,13 @@ uint32_t fromAsnSubtypes(const ConditionTypes_t types) {
116116
size_t cc_conditionBinary(const CC *cond, unsigned char *buf) {
117117
Condition_t *asn = calloc(1, sizeof(Condition_t));
118118
asnCondition(cond, asn);
119+
size_t out = 0;
119120
asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000);
120-
if (rc.encoded == -1) {
121-
fprintf(stderr, "CONDITION NOT ENCODED\n");
122-
return 0;
123-
}
121+
if (rc.encoded == -1) goto end;
122+
out = rc.encoded;
123+
end:
124124
ASN_STRUCT_FREE(asn_DEF_Condition, asn);
125-
return rc.encoded;
125+
return out;
126126
}
127127

128128

@@ -144,10 +144,12 @@ void asnCondition(const CC *cond, Condition_t *asn) {
144144
// This may look a little weird - we dont have a reference here to the correct
145145
// union choice for the condition type, so we just assign everything to the threshold
146146
// type. This works out nicely since the union choices have the same binary interface.
147+
147148
CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256;
148149
choice->cost = cc_getCost(cond);
149-
choice->fingerprint.buf = cond->type->fingerprint(cond);
150150
choice->fingerprint.size = 32;
151+
choice->fingerprint.buf = calloc(1, 32);
152+
cond->type->fingerprint(cond, choice->fingerprint.buf);
151153
choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond));
152154
}
153155

src/cryptoconditions/src/ed25519.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
struct CCType CC_Ed25519Type;
2626

2727

28-
static unsigned char *ed25519Fingerprint(const CC *cond) {
28+
static void ed25519Fingerprint(const CC *cond, uint8_t *out) {
2929
Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t));
30-
//fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey);
3130
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32);
32-
return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp);
31+
hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp, out);
3332
}
3433

3534

src/cryptoconditions/src/eval.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
struct CCType CC_EvalType;
2626

2727

28-
static unsigned char *evalFingerprint(const CC *cond) {
29-
unsigned char *hash = calloc(1, 32);
30-
//fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code);
31-
sha256(cond->code, cond->codeLength, hash);
32-
return hash;
28+
static void evalFingerprint(const CC *cond, uint8_t *out) {
29+
sha256(cond->code, cond->codeLength, out);
3330
}
3431

3532

@@ -105,7 +102,7 @@ static uint32_t evalSubtypes(const CC *cond) {
105102
*/
106103
int jsonVerifyEval(CC *cond, void *context) {
107104
if (cond->codeLength == 5 && 0 == memcmp(cond->code, "TEST", 4)) {
108-
return cond->code[5];
105+
return cond->code[4];
109106
}
110107
fprintf(stderr, "Cannot verify eval; user function unknown\n");
111108
return 0;

src/cryptoconditions/src/include/secp256k1/src/ecmult_const.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
3636

3737

3838
#endif
39-
39+
#endif

src/cryptoconditions/src/internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct CCType {
3939
char name[100];
4040
Condition_PR asnType;
4141
int (*visitChildren)(CC *cond, CCVisitor visitor);
42-
unsigned char *(*fingerprint)(const CC *cond);
42+
void (*fingerprint)(const CC *cond, uint8_t *fp);
4343
unsigned long (*getCost)(const CC *cond);
4444
uint32_t (*getSubtypes)(const CC *cond);
4545
CC *(*fromJSON)(const cJSON *params, char *err);
@@ -75,7 +75,7 @@ struct CCType *getTypeByAsnEnum(Condition_PR present);
7575
*/
7676
unsigned char *base64_encode(const unsigned char *data, size_t input_length);
7777
unsigned char *base64_decode(const unsigned char *data_, size_t *output_length);
78-
unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp);
78+
void hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp, uint8_t* out);
7979
void dumpStr(unsigned char *str, size_t len);
8080
int checkString(const cJSON *value, char *key, char *err);
8181
int checkDecodeBase64(const cJSON *value, char *key, char *err, unsigned char **data, size_t *size);

src/cryptoconditions/src/prefix.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ static int prefixVisitChildren(CC *cond, CCVisitor visitor) {
3737
}
3838

3939

40-
static unsigned char *prefixFingerprint(const CC *cond) {
40+
static void prefixFingerprint(const CC *cond, uint8_t *out) {
4141
PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t));
42-
//fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix);
43-
asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety
42+
asnCondition(cond->subcondition, &fp->subcondition);
4443
fp->maxMessageLength = cond->maxMessageLength;
4544
OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength);
46-
return hashFingerprintContents(&asn_DEF_PrefixFingerprintContents, fp);
45+
hashFingerprintContents(&asn_DEF_PrefixFingerprintContents, fp, out);
4746
}
4847

4948

src/cryptoconditions/src/preimage.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ static unsigned long preimageCost(const CC *cond) {
4444
}
4545

4646

47-
static unsigned char *preimageFingerprint(const CC *cond) {
48-
unsigned char *hash = calloc(1, 32);
49-
//fprintf(stderr,"preimage %p %p\n",hash,cond->preimage);
50-
sha256(cond->preimage, cond->preimageLength, hash);
51-
return hash;
47+
static void preimageFingerprint(const CC *cond, uint8_t *out) {
48+
sha256(cond->preimage, cond->preimageLength, out);
5249
}
5350

5451

src/cryptoconditions/src/secp256k1.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ void initVerify() {
8888
}
8989

9090

91-
static unsigned char *secp256k1Fingerprint(const CC *cond) {
91+
static void secp256k1Fingerprint(const CC *cond, uint8_t *out) {
9292
Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t));
93-
//fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE);
9493
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE);
95-
return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp);
94+
hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp, out);
9695
}
9796

9897

src/cryptoconditions/src/threshold.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,15 @@ static int cmpConditionBin(const void *a, const void *b) {
9494
}
9595

9696

97-
static unsigned char *thresholdFingerprint(const CC *cond) {
98-
/* Create fingerprint */
97+
static void thresholdFingerprint(const CC *cond, uint8_t *out) {
9998
ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t));
100-
//fprintf(stderr,"thresholdfinger %p\n",fp);
10199
fp->threshold = cond->threshold;
102100
for (int i=0; i<cond->size; i++) {
103101
Condition_t *asnCond = asnConditionNew(cond->subconditions[i]);
104102
asn_set_add(&fp->subconditions2, asnCond);
105103
}
106104
qsort(fp->subconditions2.list.array, cond->size, sizeof(Condition_t*), cmpConditionBin);
107-
return hashFingerprintContents(&asn_DEF_ThresholdFingerprintContents, fp);
105+
hashFingerprintContents(&asn_DEF_ThresholdFingerprintContents, fp, out);
108106
}
109107

110108

src/cryptoconditions/src/utils.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,15 @@ void jsonAddBase64(cJSON *params, char *key, unsigned char *bin, size_t size) {
210210
}
211211

212212

213-
unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp) {
213+
void hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp, uint8_t *out) {
214214
unsigned char buf[BUF_SIZE];
215215
asn_enc_rval_t rc = der_encode_to_buffer(asnType, fp, buf, BUF_SIZE);
216216
ASN_STRUCT_FREE(*asnType, fp);
217217
if (rc.encoded < 1) {
218218
fprintf(stderr, "Encoding fingerprint failed\n");
219219
return 0;
220220
}
221-
unsigned char *hash = calloc(1,32);
222-
sha256(buf, rc.encoded, hash);
223-
return hash;
221+
sha256(buf, rc.encoded, out);
224222
}
225223

226224

src/cryptoconditions/tests/test_failure_modes.py

+21
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,25 @@ def test_malleability_checked():
8282
assert not cc_rfb(b'\xa2\x13\xa0\x0f\xa0\x06\x80\x04abcd\xa0\x05\x80\x03abc\xa1\x00')
8383

8484

85+
def test_large_threshold():
86+
conds = [{
87+
'type': "secp256k1-sha-256",
88+
"publicKey": "02D5D969305535AC29A77079C11D4F0DD40661CF96E04E974A5E8D7E374EE225AA"
89+
}]
90+
91+
for i in range(250):
92+
conds.append({
93+
"type": "eval-sha-256",
94+
"code": "VEVTVAE"
95+
})
96+
97+
r = jsonRPC("encodeCondition", {
98+
"type": "threshold-sha-256",
99+
"subfulfillments": conds,
100+
"threshold": 251
101+
})
102+
assert 'error' not in r, r
103+
104+
105+
85106
so.cc_conditionUri.restype = ctypes.c_char_p

src/deprecation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height.
2525
// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down.
2626
static const int WEEKS_UNTIL_DEPRECATION = 52;
27-
static const int DEPRECATION_HEIGHT = 2200000;
27+
static const int DEPRECATION_HEIGHT = 2900000; //TODO: use [last_season_array_item - 1] + 650.000 for automagic update
2828
static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60);
2929

3030
// Number of blocks before deprecation to warn users

src/fiat/wlc

-2
This file was deleted.

0 commit comments

Comments
 (0)