From fd2fd9a7e5eb39a7884dee473598c05aef4db074 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sat, 25 Aug 2018 03:59:03 +0700 Subject: [PATCH 01/10] Errors printout define moved to wallet.h --- src/cc/dice.cpp | 23 +++++++++++------------ src/wallet/rpcwallet.cpp | 11 ++++------- src/wallet/wallet.h | 6 +++++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 61dfcbba1..50b9cba78 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -16,30 +16,29 @@ #include "CCdice.h" extern std::string CCerror; -#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); // timeout /* in order to implement a dice game, we need a source of entropy, reasonably fast completion time and a way to manage the utxos. - + 1. CC vout locks "house" funds with hash(entropy) 2. bettor submits bet, with entropy, odds, houseid and sends combined amount into another CC vout. 3. house account sends funds to winner/loser with proof of entropy 4. if timeout, bettor gets refund - + 2. and 3. can be done in mempool - + The house commits to an entropy value by including the hash of the entropy value in the 'E' transaction. - + To bet, one of these 'E' transactions is used as the first input and its hashed entropy is combined with the unhashed entropy attached to the bet 'B' transaction. - + The house node monitors the 'B' transactions and if it sees one of its own, it creates either a winner 'W' or loser 'L' transaction, with proof of hash of entropy. - + In the even the house node doesnt respond before timeoutblocks, then anybody (including bettor) can undo the bet with funds going back to the house and bettor - + In order for people to play dice, someone (anyone) needs to create a funded dice plan and addfunding with enough utxo to allow players to find one. - + createfunding: vins.*: normal inputs vout.0: CC vout for funding @@ -73,7 +72,7 @@ loser: vout.1: tag to owner address for entropy funds vout.2: change to fundingpk vout.n-1: opreturn 'L' sbits fundingtxid hentropy proof - + winner: same as loser, but vout.2 is winnings vout.3: change to fundingpk @@ -81,12 +80,12 @@ winner: timeout: same as winner, just without hentropy or proof - + WARNING: there is an attack vector that precludes betting any large amounts, it goes as follows: 1. do dicebet to get the house entropy revealed 2. calculate bettor entropy that would win against the house entropy 3. reorg the chain and make a big bet using the winning entropy calculated in 2. - + In order to mitigate this, the disclosure of the house entropy needs to be delayed beyond a reasonable reorg depth (notarization). It is recommended for production dice game with significant amounts of money to use such a delayed disclosure method. */ diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ffb75983a..1012a0205 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,7 +38,6 @@ #include -#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); using namespace std; @@ -119,9 +118,9 @@ string AccountFromValue(const UniValue& value) return strAccount; } -char *komodo_chainname() -{ - return(ASSETCHAINS_SYMBOL[0] == 0 ? (char *)"KMD" : ASSETCHAINS_SYMBOL); +char *komodo_chainname() +{ + return(ASSETCHAINS_SYMBOL[0] == 0 ? (char *)"KMD" : ASSETCHAINS_SYMBOL); } UniValue getnewaddress(const UniValue& params, bool fHelp) @@ -4567,7 +4566,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) utxovout = out.i; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; //fprintf(stderr,"check %s/v%d %llu\n",(char *)utxotxid.GetHex().c_str(),utxovout,(long long)utxovalue); - + txNew.vin.resize(1); txNew.vout.resize(1); txfee = utxovalue / 2; @@ -5779,5 +5778,3 @@ UniValue getbalance64(const UniValue& params, bool fHelp) ret.push_back(Pair("notstaking", b)); return ret; } - - diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0c6a90840..70df32bef 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1148,7 +1148,7 @@ public: int minDepth=1, bool ignoreSpent=true, bool ignoreUnspendable=true); - + }; /** A key allocated from the key pool. */ @@ -1204,4 +1204,8 @@ public: READWRITE(vchPubKey); } }; + +/** Error status printout */ +#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); + #endif // BITCOIN_WALLET_WALLET_H From 26bb3613751c3d55d4fd3276d03fbaae2bec14c3 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 02:59:44 +0300 Subject: [PATCH 02/10] CCL chain, one shot --- src/assetchains.json | 10 ++++++++++ src/assetchains.old | 1 + src/dpowassets | 1 + 3 files changed, 12 insertions(+) diff --git a/src/assetchains.json b/src/assetchains.json index 5f0d3464f..b74d953a0 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -132,5 +132,15 @@ "ac_name": "SEC", "ac_supply": "1000000000", "ac_cc": "333" + }, + { + "ac_name": "CCL", + "ac_supply": "200000000", + "ac_end": "1", + "ac_cc": "2", + "addressindex": "1", + "spentindex": "1", + "addnode": "142.93.136.89", + "addnode": "195.201.22.89" } ] diff --git a/src/assetchains.old b/src/assetchains.old index cbf976dd9..a25b6f898 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -38,3 +38,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & +./komodod -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & diff --git a/src/dpowassets b/src/dpowassets index 6506c54d0..88e6f72b8 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -39,3 +39,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" From 4d61e5cd995b2c592ae51936fe0e5979ab2a4e6f Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 04:15:55 +0300 Subject: [PATCH 03/10] CCL --- src/ac/ccl | 2 ++ src/fiat/ccl | 2 ++ 2 files changed, 4 insertions(+) create mode 100755 src/ac/ccl create mode 100755 src/fiat/ccl diff --git a/src/ac/ccl b/src/ac/ccl new file mode 100755 index 000000000..c3d03a0a4 --- /dev/null +++ b/src/ac/ccl @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=CCL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ccl b/src/fiat/ccl new file mode 100755 index 000000000..c3d03a0a4 --- /dev/null +++ b/src/fiat/ccl @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=CCL $1 $2 $3 $4 $5 $6 From 5016068231e99d1c0e982bb966e0d28206b7de64 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 04:17:37 +0300 Subject: [PATCH 04/10] CCL --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index a25b6f898..d7a18811d 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -38,4 +38,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & -./komodod -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & +./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & From f4e9f4670cff7583db002983a301337c85bf4fee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:50:29 -1100 Subject: [PATCH 05/10] -print --- src/komodo.h | 2 +- src/komodo_kv.h | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index dff8b5ab6..28d3a1b9f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -600,7 +600,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { if ( scriptbuf[len] == 'K' ) { - fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); + //fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0); return(-1); } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 2f4eadea4..c533b4976 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -151,7 +151,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { - fprintf(stderr,"(%s) already there\n",(char *)key); + //fprintf(stderr,"(%s) already there\n",(char *)key); //if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) { tstr = (char *)"transfer:"; diff --git a/src/main.cpp b/src/main.cpp index aa6bece16..a96b83f03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1306,7 +1306,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa string reason; if (Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight)) { - fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\n",reason.c_str()); + //fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\n",reason.c_str()); return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason),REJECT_NONSTANDARD, reason); } // Only accept nLockTime-using transactions that can be mined in the next From 282473f1fc81a2000e3e8d9e1d3370707a8368a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:51:19 -1100 Subject: [PATCH 06/10] -print --- src/script/standard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/standard.cpp b/src/script/standard.cpp index b86dfef15..58d2bc701 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -167,7 +167,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector nMaxDatacarrierBytes) { - fprintf(stderr,"size.%d > nMaxDatacarrier.%d\n",(int32_t)vch1.size(),(int32_t)nMaxDatacarrierBytes); + //fprintf(stderr,"size.%d > nMaxDatacarrier.%d\n",(int32_t)vch1.size(),(int32_t)nMaxDatacarrierBytes); break; } } From 62d82abc4c431b9d4f95ee1218c682f9b910389d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:54:33 -1100 Subject: [PATCH 07/10] -print --- src/komodo_kv.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index c533b4976..1b1d92014 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -64,7 +64,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( ptr != 0 ) { duration = komodo_kvduration(ptr->flags); - fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + //fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); @@ -117,7 +117,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) } valueptr = &key[keylen]; fee = komodo_kvfee(flags,opretlen,keylen); - printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); diff --git a/src/main.cpp b/src/main.cpp index a96b83f03..73cafdc1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -736,7 +736,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) if (!::IsStandard(txout.scriptPubKey, whichType)) { reason = "scriptpubkey"; - fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut); + //fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut); return false; } From 19107e362e040c06626d89de2e4f9a2aca254f79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:56:54 -1100 Subject: [PATCH 08/10] -print --- src/komodo_kv.h | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 1b1d92014..4cf482116 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -142,7 +142,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) { - fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13); + //fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13); return; } } diff --git a/src/main.cpp b/src/main.cpp index 73cafdc1c..85de0effa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4187,11 +4187,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } if ( rejects == 0 || rejects == lastrejects ) { - if ( lastrejects != 0 ) + if ( 0 && lastrejects != 0 ) fprintf(stderr,"lastrejects.%d -> all tx in mempool\n",lastrejects); break; } - fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); + //fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0; } From 7f21f769858a2db9c339387d0cd79025d0454817 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 07:29:08 -1100 Subject: [PATCH 09/10] -print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 28d3a1b9f..4b61cafa0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -311,7 +311,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long { if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) { int32_t i; for (i=0; i Date: Sat, 25 Aug 2018 09:01:05 -1100 Subject: [PATCH 10/10] Prevent unlocking fundingtxid --- src/cc/rewards.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d3d374613..33c5f01d4 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -244,7 +244,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t //vout.0: funding CC change or recover normal payout //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid - if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + if ( fundingtxid == txid ) + return eval->Invalid("cant unlock fundingtxid"); + else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); for (i=0; i