From 23df289f70236cdeabca5adee79553cb86b64450 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 19:35:45 -1100 Subject: [PATCH 01/38] CC address support for nspv_listunspent --- src/komodo_nSPV_fullnode.h | 10 +++++++--- src/komodo_nSPV_superlite.h | 4 ++-- src/wallet/rpcdump.cpp | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 494c511e1..f8cc47925 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -137,7 +137,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) } else return(-1); } -int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC) // check mempool { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; @@ -362,12 +362,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; - if ( len < 64 && request[1] == len-2 ) + if ( len < 64 && (request[1] == len-2 || request[1] == len-3) ) { + uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; + if ( request[1] == len-3 ) + isCC = (request[len-1] != 0); + fprintf(stderr,"isCC.%d\n",isCC); memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d23c35363..150d0859c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -385,7 +385,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) return(NSPV_getinfo_json(&NSPV_inforesult)); } -UniValue NSPV_addressutxos(char *coinaddr) +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); @@ -400,7 +400,7 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; - msg[len] = 0; + msg[len++] = (CCflag != 0); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b197b73b0..82e44190c 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,7 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); -UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -1011,17 +1011,22 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() > 1 ) - throw runtime_error("nspv_listunspent address\n"); + int32_t CCflag = 0; + if ( fHelp || params.size() > 2 ) + throw runtime_error("nspv_listunspent address [isCC]\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str())); - else throw runtime_error("nspv_listunspent address\n"); + return(NSPV_addressutxos((char *)NSPV_address.c_str(),0)); + else throw runtime_error("nspv_listunspent address [isCC]\n"); } - if ( params.size() == 1 ) - return(NSPV_addressutxos((char *)params[0].get_str().c_str())); - else throw runtime_error("nspv_listunspent address\n"); + if ( params.size() >= 1 ) + { + if ( params.size() == 2 ) + CCflag = atoi((char *)params[1].get_str().c_str()); + return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag)); + } + else throw runtime_error("nspv_listunspent address [isCC]\n"); } UniValue nspv_spentinfo(const UniValue& params, bool fHelp) From b9cb5e7b4be3ac6573cd90f4a6c185f9bdf17bfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 19:39:49 -1100 Subject: [PATCH 02/38] Full CCflag support --- src/komodo_nSPV.h | 5 +++-- src/komodo_nSPV_fullnode.h | 1 + src/komodo_nSPV_superlite.h | 1 + src/komodo_nSPV_wallet.h | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index cba34c290..77c352659 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -140,7 +140,7 @@ struct NSPV_utxosresp char coinaddr[64]; int64_t total,interest; int32_t nodeheight; - uint16_t numutxos,pad16; + uint16_t numutxos; uint8_t CCflag,pad8; }; int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosresp *ptr) // check mempool @@ -157,7 +157,8 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad8),&ptr->pad8); if ( rwflag != 0 ) { memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index f8cc47925..c28c247cb 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -145,6 +145,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); + ptr->CCflag = isCC; if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 150d0859c..3f11ab74f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -276,6 +276,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("result","success")); result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); result.push_back(Pair("address",ptr->coinaddr)); + result.push_back(Pair("isCC",ptr->CCflag)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); result.push_back(Pair("balance",(double)ptr->total/COIN)); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index f04cef11b..397dbe625 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -218,7 +218,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) - NSPV_addressutxos(srcaddr); + NSPV_addressutxos(srcaddr,0); if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); From 80d02fbb42ff45e6bda718e9dd4d67f19b22ca56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:05:51 -1100 Subject: [PATCH 03/38] Query CC --- src/komodo_nSPV_fullnode.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c28c247cb..cdfb0f57e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -141,7 +141,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; - SetCCunspents(unspentOutputs,coinaddr,false); + SetCCunspents(unspentOutputs,coinaddr,isCC); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); @@ -370,7 +370,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); - fprintf(stderr,"isCC.%d\n",isCC); + if ( isCC != 0 ) + fprintf(stderr,"%s isCC.%d\n",coinaddr,isCC); memset(&U,0,sizeof(U)); if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) { From c9a6b6218a3878d6053c3eee190aeda470e51250 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:16:57 -1100 Subject: [PATCH 04/38] +print --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_wallet.h | 3 ++- src/script/sign.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 77c352659..72a23d23f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -53,6 +53,7 @@ #define NSPV_BROADCASTRESP 0x0d int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); +extern uint256 SIG_TXHASH; int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 397dbe625..a53ec77b2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,8 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); + fprintf(stderr,"SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } // else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); + } else fprintf(stderr,"sigerr SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 685018828..1865d8e35 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -35,6 +35,7 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; +uint256 SIG_TXHASH; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} @@ -52,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } catch (logic_error ex) { return false; } - + TXHASH = hash; if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From 80377ebdc938d49d2f9a4dfd8fe6e70471b73d88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:18:03 -1100 Subject: [PATCH 05/38] SIG_TXHASH --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index a53ec77b2..4ab094562 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,9 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - fprintf(stderr,"SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } else fprintf(stderr,"sigerr SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } From cdfcb27820cc9838a9f881a575204744d9b516bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:20:45 -1100 Subject: [PATCH 06/38] SIG_TXHASH --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 1865d8e35..71fa4cee4 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -53,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } catch (logic_error ex) { return false; } - TXHASH = hash; + SIG_TXHASH = hash; if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From c466bfd18a398d8d22b0146c9bcf02a2ab5663de Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:38:18 -1100 Subject: [PATCH 07/38] New notaries count --- src/komodo_nSPV.h | 23 ++++++++++++++++++++++- src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 72a23d23f..614e7f86f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -431,6 +431,27 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) However, since the vouts being spent by the notaries are highly constrained p2pk vouts, the txhash can be deduced if a specific notary pubkey is indeed the signer */ +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); + +int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) +{ + CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + for (j=0; j<64; j++) + { + pubkeys[j] = buf2pk(elected[j]); + scriptPubKeys[j] = CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + } + for (vini=0; vini= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } else sleep(1); From ccae5863fa178183089e34e1aceda0c637bec7e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:40:22 -1100 Subject: [PATCH 08/38] Flag --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 614e7f86f..67476f105 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -28,7 +28,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_SKIPFULLVALIDATION 1 // changing to 0 issues 26 remote gettransaction, per utxo! need to change to bruteforcer +#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettx, per utxo! need local bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 @@ -439,7 +439,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); - scriptPubKeys[j] = CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); } for (vini=0; vini Date: Mon, 8 Jul 2019 20:45:23 -1100 Subject: [PATCH 09/38] NSPV_utxosresult.CCflag != 0 || --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4ab094562..0a8ca30d2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -218,9 +218,9 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","couldnt getinfo")); return(result); } - if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) NSPV_addressutxos(srcaddr,0); - if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); result.push_back(Pair("address",NSPV_utxosresult.coinaddr)); From 492dc5c2cc5e92048b4fc22b4d8ecd76c631a9f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:49:12 -1100 Subject: [PATCH 10/38] +print --- src/script/sign.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 71fa4cee4..e4ec27688 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -42,11 +42,13 @@ TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keysto bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { CKey key; + fprintf(stderr,"createsig\n"); if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) return false; - + fprintf(stderr,"createsig2\n"); + uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); From 34878d8dbc95b4b95004fd7b45c92ae86bd14537 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:52:35 -1100 Subject: [PATCH 11/38] Reorder code --- src/script/sign.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index e4ec27688..d0ae52b3a 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -41,21 +41,18 @@ TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keysto bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { - CKey key; - fprintf(stderr,"createsig\n"); - if (pprivKey) - key = *pprivKey; - else if (!keystore || !keystore->GetKey(address, key)) - return false; - fprintf(stderr,"createsig2\n"); - - uint256 hash; + CKey key; uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); } catch (logic_error ex) { return false; } SIG_TXHASH = hash; + if (pprivKey) + key = *pprivKey; + else if (!keystore || !keystore->GetKey(address, key)) + return false; + if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From ae0354d651c3ec46f0600ca60c0ff0f0d0f3572a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:16:04 -1100 Subject: [PATCH 12/38] Verify --- src/komodo_nSPV.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67476f105..a141315ec 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; std::vector vchSig; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,11 +443,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini Date: Mon, 8 Jul 2019 21:23:27 -1100 Subject: [PATCH 13/38] Extract vchSig --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a141315ec..3d2628273 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; std::vector vchSig; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig(tx.vin[vini].scriptSig.begin(),mtx.vin[vini].scriptSig.end()); vchSig.pop_back(); for (j=0; j<64; j++) { From 933b352f042091a2b40c81c5df7c51fd243f5148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:27:23 -1100 Subject: [PATCH 14/38] Extract --- src/komodo_nSPV.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3d2628273..b032f2b41 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,8 +443,16 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig(tx.vin[vini].scriptSig.begin(),mtx.vin[vini].scriptSig.end()); - vchSig.pop_back(); + ptr = tx.vin[vini].scriptSig.data(); + std::vector vchSig; + vchSig.resize(tx.vin[vini].scriptSig.size()-2); + for (j=0; j 0 && j < tx.vin[vini].scriptSig.size()-1 ) + vchSig[j-1] = ptr[j]; + fprintf(stderr,"%02x",ptr[j]); + } + fprintf(stderr," sig.%d\n",vini); for (j=0; j<64; j++) { NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j]); From 193e9e14ebc29d9fb65482edfa4b7e640d61c15b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:28:41 -1100 Subject: [PATCH 15/38] ptr() --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b032f2b41..a44098869 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; vchSig.resize(tx.vin[vini].scriptSig.size()-2); for (j=0; j Date: Mon, 8 Jul 2019 21:29:37 -1100 Subject: [PATCH 16/38] Cast --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a44098869..67b224b8f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; vchSig.resize(tx.vin[vini].scriptSig.size()-2); for (j=0; j Date: Mon, 8 Jul 2019 21:38:14 -1100 Subject: [PATCH 17/38] Test --- src/komodo_nSPV.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67b224b8f..03d1f2208 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -445,14 +445,18 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { ptr = (uint8_t *)&tx.vin[vini].scriptSig; std::vector vchSig; - vchSig.resize(tx.vin[vini].scriptSig.size()-2); + siglen = ptr[16]; + vchSig.resize(siglen); for (j=0; j 0 && j < tx.vin[vini].scriptSig.size()-1 ) - vchSig[j-1] = ptr[j]; + if ( j > 17 && j < 17+siglen ) + vchSig[j-17] = ptr[j]; fprintf(stderr,"%02x",ptr[j]); } - fprintf(stderr," sig.%d\n",vini); + fprintf(stderr," sig.%d siglen.%d\n",vini,siglen); + for (j=0; j Date: Mon, 8 Jul 2019 21:52:04 -1100 Subject: [PATCH 18/38] Alternate way --- src/komodo_nSPV.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 03d1f2208..bc73bcc19 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,19 +443,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; - siglen = ptr[16]; - vchSig.resize(siglen); - for (j=0; j 17 && j < 17+siglen ) - vchSig[j-17] = ptr[j]; - fprintf(stderr,"%02x",ptr[j]); - } - fprintf(stderr," sig.%d siglen.%d\n",vini,siglen); + str = (char *)tx.vin[vini].scriptSig.ToString().c_str(); + fprintf(stderr,"scriptSig %s\n",str); + siglen = (int32_t)strlen(str)/2; + decode_hex(sig,siglen,str); + vchSig.resize(siglen-1); + memcpy(&vchSig[0],sig,siglen-1); for (j=0; j Date: Mon, 8 Jul 2019 21:54:30 -1100 Subject: [PATCH 19/38] vchSig --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bc73bcc19..4375acd5f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector vchSig; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); From d40b7709bbc21a73043fd6318158e117fcef16ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:03:27 -1100 Subject: [PATCH 20/38] Printf casts --- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 6 +++--- src/komodo_utils.h | 4 ++-- src/main.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 48962b015..b3f870170 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2051,7 +2051,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) total += txout.nValue; //fprintf(stderr, "MATCHED AmountPaid.%lu notaryid.%i\n",AmountToPay,NotarisationNotaries[n-1]); } - else fprintf(stderr, "NOT MATCHED AmountPaid.%lu AmountToPay.%lu notaryid.%i\n", pblock->vtx[0].vout[n].nValue, AmountToPay, NotarisationNotaries[n-1]); + else fprintf(stderr, "NOT MATCHED AmountPaid.%llu AmountToPay.%llu notaryid.%i\n", (long long)pblock->vtx[0].vout[n].nValue, (long long)AmountToPay, NotarisationNotaries[n-1]); } n++; } @@ -2347,7 +2347,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) numSN = komodo_notaries(notarypubkeys, height, pblock->nTime); if ( pblock->vtx[1].vin.size() < numSN/5 ) { - fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%li\n",height,numSN/5,pblock->vtx[1].vin.size()); + fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%lld\n",height,numSN/5,(long long)pblock->vtx[1].vin.size()); return(-1); } } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1006a9ada..5c60503bf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -669,7 +669,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) int32_t i; if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) { - fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); + fprintf(stderr,"komodo_bannedset: buffer too small %d vs %d\n",(int32_t)(sizeof(banned_txids)/sizeof(*banned_txids)),max); StartShutdown(); } for (i=0; i indcounter %u, prevpos100 %u offset.%ld\n",datalen,validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + fprintf(stderr,"datalen.%ld validated %ld -> indcounter %u, prevpos100 %u offset.%d\n",datalen,validated,indcounter,prevpos100,(int32_t)(indcounter * sizeof(uint32_t))); if ( fpos < datalen ) { fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5a7bb75d1..3e2055204 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2125,7 +2125,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); if ( ASSETCHAINS_FOUNDERS_REWARD != 0 ) { - fprintf(stderr, "set founders reward.%li\n",ASSETCHAINS_FOUNDERS_REWARD); + fprintf(stderr, "set founders reward.%lld\n",(long long)ASSETCHAINS_FOUNDERS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_REWARD),(void *)&ASSETCHAINS_FOUNDERS_REWARD); } } @@ -2348,7 +2348,7 @@ void komodo_args(char *argv0) if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING[0] == 77777 ) { ASSETCHAINS_HALVING[0] *= 5; - fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%lu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,ASSETCHAINS_LASTERA); + fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%llu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,(long long)ASSETCHAINS_LASTERA); } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) dpowconfs = 0; diff --git a/src/main.cpp b/src/main.cpp index 3a29edcf0..339f4e790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -762,7 +762,7 @@ bool komodo_dailysnapshot(int32_t height) // include only top 3999 address. if ( vAddressSnapshot.size() > 3999 ) vAddressSnapshot.resize(3999); lastSnapShotHeight = undo_height; - fprintf(stderr, "vAddressSnapshot.size.%li\n", vAddressSnapshot.size()); + fprintf(stderr, "vAddressSnapshot.size.%d\n", (int32_t)vAddressSnapshot.size()); return true; } @@ -4322,7 +4322,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); StartShutdown(); } - fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); + fprintf(stderr, "snapshot completed in: %d seconds\n", (int32_t)(time(NULL)-start)); } } return true; From ba444af9c4d2af638e1d0821f9938df74e447645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:12:57 -1100 Subject: [PATCH 21/38] Fix --- src/komodo_nSPV.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4375acd5f..3453ad841 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,21 +443,20 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini Date: Mon, 8 Jul 2019 22:14:57 -1100 Subject: [PATCH 22/38] CScript:: --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3453ad841..fb82a5000 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -445,7 +445,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( GetPushedData(pc,vchSig) != 0 ) + if ( CScript::GetPushedData(pc,vchSig) != 0 ) { for (j=0; j Date: Mon, 8 Jul 2019 22:16:44 -1100 Subject: [PATCH 23/38] vData[0] --- src/komodo_nSPV.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fb82a5000..ebeea6f42 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector vchSig; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector>& vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -445,15 +445,15 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( CScript::GetPushedData(pc,vchSig) != 0 ) + if ( CScript::GetPushedData(pc,vData) != 0 ) { - for (j=0; j Date: Mon, 8 Jul 2019 22:17:58 -1100 Subject: [PATCH 24/38] -& --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ebeea6f42..3d39681fd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector>& vData; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); From d023823b90ea47950f282a09f462217f333ef666 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:19:16 -1100 Subject: [PATCH 25/38] tx.vin[vini].scriptSig --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3d39681fd..1374003d4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -445,14 +445,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( CScript::GetPushedData(pc,vData) != 0 ) + if ( tx.vin[vini].scriptSig.GetPushedData(pc,vData) != 0 ) { for (j=0; j Date: Mon, 8 Jul 2019 22:24:17 -1100 Subject: [PATCH 26/38] vData[0] --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1374003d4..af16b94e4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -447,6 +447,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); if ( tx.vin[vini].scriptSig.GetPushedData(pc,vData) != 0 ) { + vData[0].pop_back(); for (j=0; j Date: Mon, 8 Jul 2019 22:27:28 -1100 Subject: [PATCH 27/38] Test --- src/komodo_nSPV.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index af16b94e4..0f8c555d3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; + CPubKey pubkeys[64]; uint8_t sig[512]; char coinaddr[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -453,8 +453,9 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) fprintf(stderr," vData[0]\n"); for (j=0; j<64; j++) { + Getscriptaddress(coinaddr,scriptPubKeys[j]); NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j]); // sets SIG_TXHASH - fprintf(stderr,"%d ",pubkeys[j].Verify(SIG_TXHASH,vData[0])); + fprintf(stderr,"%s.%d ",coinaddr,pubkeys[j].Verify(SIG_TXHASH,vData[0])); } fprintf(stderr," verifies\n"); } From c4f95560b99914da381ccc12caad52d6525fc45b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:31:14 -1100 Subject: [PATCH 28/38] +prints --- src/komodo_nSPV.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 0f8c555d3..df697dc92 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -441,6 +441,9 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); } + fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + for (vini=0; vini Date: Mon, 8 Jul 2019 22:40:28 -1100 Subject: [PATCH 29/38] Test --- src/komodo_nSPV.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index df697dc92..15f3ca911 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -440,6 +440,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j])); } fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); for (vini=0; vini Date: Mon, 8 Jul 2019 22:42:10 -1100 Subject: [PATCH 30/38] .c_str() --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 15f3ca911..aa1d0044b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -440,7 +440,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); - fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j])); + fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); for (vini=0; vini Date: Mon, 8 Jul 2019 23:01:06 -1100 Subject: [PATCH 31/38] NSPV_inforesult.H.nTime --- src/komodo_nSPV.h | 3 ++- src/komodo_nSPV_superlite.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index aa1d0044b..d0e9af6b4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -54,6 +54,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); extern uint256 SIG_TXHASH; +uint32_t NSPV_blocktime(int32_t hdrheight); int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { @@ -518,7 +519,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * if ( opret.size() >= 32*2+4 ) { *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); - komodo_notaries(elected,*ntzheightp,0); + komodo_notaries(elected,*ntzheightp,NSPV_blocktime(*ntzheightp)); if ( verifyntz != 0 && (numsigs= NSPV_newnotariescount(tx,elected)) < 12 ) { fprintf(stderr,"numsigs.%d error\n",numsigs); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index a50b7c44c..5a76cf912 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -386,6 +386,20 @@ UniValue NSPV_getinfo_req(int32_t reqht) return(NSPV_getinfo_json(&NSPV_inforesult)); } +uint32_t NSPV_blocktime(int32_t hdrheight) +{ + if ( hdrheight > 0 ) + { + NSPV_getinfo_req(hdrheight) + if ( NSPV_inforesult.hdrheight == hdrheight ) + { + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); + return(NSPV_inforesult.H.nTime); + } + } + return(0); +} + UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; From fd679b6f0e8c6dda0958a374864b0b920dee6227 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:04:44 -1100 Subject: [PATCH 32/38] Test --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5a76cf912..75fffb761 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -390,7 +390,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) { if ( hdrheight > 0 ) { - NSPV_getinfo_req(hdrheight) + NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); From b31ef7ec9c0094e260e2ced411e0789f8c557be8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:14:50 -1100 Subject: [PATCH 33/38] -print --- src/komodo_nSPV.h | 76 ++++++++++++++++++------------------- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 4 +- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d0e9af6b4..614bd510a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -424,6 +424,43 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); + +int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) +{ + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,retval; uint64_t mask = 0; char *str; std::vector> vData; + for (j=0; j<64; j++) + { + pubkeys[j] = buf2pk(elected[j]); + scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); + } + //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + for (vini=0; vini> vData; - for (j=0; j<64; j++) - { - pubkeys[j] = buf2pk(elected[j]); - scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); - fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); - } - fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); - for (vini=0; vini t%u\n",hdrheight,NSPV_inforesult.H.nTime); + //fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); return(NSPV_inforesult.H.nTime); } } diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 0a8ca30d2..6115132af 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,9 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + // fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + } // else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } From 6ecb8ee9ab7ea8c24034da6b4825ad611752501d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:16:07 -1100 Subject: [PATCH 34/38] Mask --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 614bd510a..9a9e5702a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -458,7 +458,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) //fprintf(stderr," verifies\n"); } } - return(bitweight(numsigs)); + return(bitweight(mask)); } /* From 00115fddeca4e91b71425070cf82998a882ed038 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:23:52 -1100 Subject: [PATCH 35/38] Test --- src/komodo_nSPV.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9a9e5702a..06527e870 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -436,8 +436,8 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); - for (vini=0; vini Date: Mon, 8 Jul 2019 23:26:15 -1100 Subject: [PATCH 36/38] Taxied --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 06527e870..8a66368bd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } - //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); //for (vini=0; vini Date: Mon, 8 Jul 2019 23:29:53 -1100 Subject: [PATCH 37/38] sleep(1); --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8a66368bd..4ac20183b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -520,6 +520,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) { + sleep(1); *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); komodo_notaries(elected,*ntzheightp,NSPV_blocktime(*ntzheightp)); if ( verifyntz != 0 && (numsigs= NSPV_fastnotariescount(tx,elected)) < 12 ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5c29fde7a..75fffb761 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -393,7 +393,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { - //fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); return(NSPV_inforesult.H.nTime); } } From 86e8e39e6fdba454dc5db5cff34dd9e942e10e85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:33:29 -1100 Subject: [PATCH 38/38] Always full validation --- src/komodo_nSPV.h | 2 -- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4ac20183b..333f384f2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -20,7 +20,6 @@ // interest calculations are currently just using what is returned, it should calculate it from scratch -// bruteforce sig -> NN pubkey validator // CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) @@ -28,7 +27,6 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettx, per utxo! need local bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6115132af..5ac4081f5 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -165,7 +165,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(NSPV_SKIPFULLVALIDATION,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security {