From ce99447bb48643e19dee8fdd0a523377485718ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 11:54:11 -1100 Subject: [PATCH] Threshold check in all CC addinputs --- src/cc/CCassetstx.cpp | 6 ++++-- src/cc/MofN.cpp | 1 + src/cc/auction.cpp | 1 + src/cc/dice.cpp | 19 ++++++------------- src/cc/faucet.cpp | 5 ++++- src/cc/fsm.cpp | 1 + src/cc/gateways.cpp | 5 ++++- src/cc/lotto.cpp | 1 + src/cc/payments.cpp | 1 + src/cc/pegs.cpp | 1 + src/cc/prices.cpp | 1 + src/cc/rewards.cpp | 5 +++-- src/cc/triggers.cpp | 1 + 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 5c933bd77..4bc1adc42 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,15 +17,17 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7b5f106d0..d0d8db0bb 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -120,6 +120,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 26d33545f..1f1164a0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -88,7 +88,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it Actually a much better solution to this is possible, which allows to retain the realtime response aspect of dice CC, which is critical to its usage. - +What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy */ @@ -138,6 +138,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); + // check to make sure it got accepted + for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } - } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } return(false); @@ -202,6 +204,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr->bettxid = bettxid; ptr->sbits = sbits; ptr->iswin = iswin; + // check for duplicates here!!! if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); @@ -658,16 +661,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } -// jl777: need to make it bestfit -/* fix: bidTx.0281db86a2b45bf73a0e674ec40ca4866fc54298c677d42c5dd8c71254d127f1 -entropyTx.671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c v0 -entropyTx vin0 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 v0 -76a9141f64ce357cb254464c2d5a9c06ca8d0c0ca9be9488ac script vs 210354ad90c26923962bbdfc7fd4956cb52db73682b58df9ee3ffc4751e61c8d465dac (B) entropy vin.0 fundingPubKey mismatch 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 -CC Eval EVAL_DICE Invalid: vin1 of entropy tx not fundingPubKey for bet spending tx 671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c*/ - -/*make tx.L -CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae96b78bd46965066fed7f7fa5838faed9588e62bcd4a406f478eecd5*/ - uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 676cb152c..3bf8a3476 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -142,14 +142,17 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 41601b437..9f9accbb5 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -122,6 +122,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b6fcb2136..a9fc6a4cd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -332,15 +332,18 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; fprintf(stderr,"check %s for gateway inputs\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6cd751b8d..f3cd40ba2 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -115,6 +115,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d9074bd49..21e371b4a 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -122,6 +122,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6ee0364e2..3d69ceec1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -129,6 +129,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { + // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,destaddr); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a70071af9..e7a3750f3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -325,15 +325,16 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r // 'L' vs 'F' and 'A' int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 1000000 ) + if ( it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk);