From 1c85c52f49c17e7520ff253aaeee70d37a9233d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:04:17 -1100 Subject: [PATCH 1/8] You can ignore ./makerogue: shell: not found --- src/cc/makerogue | 1 + src/cc/rogue_rpc.cpp | 50 ++++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/cc/makerogue b/src/cc/makerogue index 249e646f5..fb7a53cec 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -1,4 +1,5 @@ #!/bin/sh +echo "you can ignore ./makerogue: shell: not found" cd rogue; ./configure # only need this first time make; cd .. diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index a7bbaa489..1ca1bce88 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -325,18 +325,20 @@ uint64_t rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 return(seed); } -int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid) +int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0) { uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey roguepk; uint64_t txfee = 10000; buyin = maxplayers = 0; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { gameheight = komodo_blockheight(hashBlock); - if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) >= txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 ) + if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) == txfee && (unspentv0 == 0 || CCgettxout(playertxid,0,1) == txfee) ) { if ( rogue_newgameopreturndecode(buyin,maxplayers,tx.vout[numvouts-1].scriptPubKey) == 'G' ) { - if ( numvouts > maxplayers+1 ) + if ( maxplayers < 1 || maxplayers > ROGUE_MAXPLAYERS || buyin < 0 ) + return(-6); + if ( numvouts > 2*maxplayers+1 ) { for (i=0; i 0 ) { gametxid = juint256(jitem(params,0)); - if ( (err= rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid)) == 0 ) + if ( (err= rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1)) == 0 ) { if ( n > 1 ) { @@ -803,7 +806,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param mypk = pubkey2pk(Mypubkey()); roguepk = GetUnspendable(cp,0); GetCCaddress1of2(cp,destaddr,roguepk,mypk); - if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid) == 0 ) + if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1) == 0 ) { if ( rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,tx,maxplayers,destaddr,numplayers,symbol,pname) == 0 ) { @@ -811,7 +814,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("playertxid",playertxid.GetHex())); if ( maxplayers == 1 || nextheight <= batonht+ROGUE_MAXKEYSTROKESGAP ) { - mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); + mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); // this validates user mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,batonvalue-txfee,roguepk,mypk)); Myprivkey(mypriv); CCaddr1of2set(cp,roguepk,mypk,mypriv,destaddr); @@ -830,7 +833,7 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector &newdat roguepk = GetUnspendable(cp,0); *numkeysp = 0; seed = 0; - if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) + if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) == 0 ) { if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,rogueaddr,numplayers,symbol,pname) == 0 ) { @@ -965,7 +968,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param { gametxid = juint256(jitem(params,0)); result.push_back(Pair("gametxid",gametxid.GetHex())); - if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) + if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,1)) == 0 ) { if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,myrogueaddr,numplayers,symbol,pname) == 0 ) { @@ -1078,7 +1081,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { txid = juint256(jitem(params,0)); result.push_back(Pair("gametxid",txid.GetHex())); - if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 ) + if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,0) == 0 ) { result.push_back(Pair("result","success")); result.push_back(Pair("gameheight",(int64_t)gameheight)); @@ -1118,7 +1121,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis != txfee || vout != 0 ) // reject any that are not highlander markers continue; - if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 && nextheight <= gameheight+ROGUE_MAXKEYSTROKESGAP ) + if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,1) == 0 && nextheight <= gameheight+ROGUE_MAXKEYSTROKESGAP ) { rogue_playersalive(numplayers,txid,maxplayers); if ( numplayers < maxplayers ) @@ -1182,7 +1185,7 @@ UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { if ( rogue_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' ) { - if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid) == 0 ) + if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0) == 0 ) { if ( CCgettxout(txid,vout,1) < 0 ) b.push_back(gametxid.GetHex()); @@ -1262,7 +1265,7 @@ int32_t rogue_playerdata_validate(uint256 &playertxid,struct CCcontract_info *cp bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,errflag,dispflag,score,numvouts; CTransaction vintx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector playerdata,keystrokes; std::string symbol,pname; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,errs,dispflag,gameheight,score,numvouts; CTransaction vintx,gametx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector playerdata,keystrokes; std::string symbol,pname; if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 && height < 21274 ) return(true); if ( (numvouts= tx.vout.size()) > 1 ) @@ -1291,13 +1294,12 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C switch ( funcid ) { case 'G': - if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' ) + if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) != 0 ) { - //fprintf(stderr,"height.%d couldnt decode newgame opret\n",height); + fprintf(stderr,"height.%d rogue_isvalidgame error.%d\n",height,err); //if ( height > 20000 ) - return eval->Invalid("couldnt decode newgame opret"); + return eval->Invalid("invalid gametxid"); } - // validate newgame tx return(true); break; case 'R': @@ -1307,6 +1309,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C //if ( height > 20000 ) return eval->Invalid("couldnt decode register opret"); } + // baton is created // validation is done below break; case 'K': @@ -1316,7 +1319,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C //if ( height > 20000 ) return eval->Invalid("couldnt decode keystrokes opret"); } - // validate keystrokes are from the correct pk. might need to add vin + // spending the baton proves it is the user if the pk is the signer return(true); break; case 'H': case 'Q': @@ -1326,7 +1329,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C //if ( height > 20000 ) return eval->Invalid("couldnt decode H/Q opret"); } - // validation is done below + // spending the baton proves it is the user if the pk is the signer + // rest of validation is done below break; default: return eval->Invalid("illegal rogue non-decoded funcid"); @@ -1353,7 +1357,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C } else // 'H' { - // verify vin/vout + // verify vin/vout and proper payouts } return(true); break; From fed6024ee745bf526d543ba70f9253239b09a6c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:05:43 -1100 Subject: [PATCH 2/8] err --- src/cc/rogue_rpc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 1ca1bce88..b5e44aad5 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -332,7 +332,7 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { gameheight = komodo_blockheight(hashBlock); - if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) == txfee && (unspentv0 == 0 || CCgettxout(playertxid,0,1) == txfee) ) + if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) == txfee && (unspentv0 == 0 || CCgettxout(txid,0,1) == txfee) ) { if ( rogue_newgameopreturndecode(buyin,maxplayers,tx.vout[numvouts-1].scriptPubKey) == 'G' ) { @@ -1265,7 +1265,7 @@ int32_t rogue_playerdata_validate(uint256 &playertxid,struct CCcontract_info *cp bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,errs,dispflag,gameheight,score,numvouts; CTransaction vintx,gametx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector playerdata,keystrokes; std::string symbol,pname; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,err,dispflag,gameheight,score,numvouts; CTransaction vintx,gametx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector playerdata,keystrokes; std::string symbol,pname; if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 && height < 21274 ) return(true); if ( (numvouts= tx.vout.size()) > 1 ) From 9377ec6542066c435b6660797d38ccd92393175d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:06:36 -1100 Subject: [PATCH 3/8] Ignore --- src/cc/makerogue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/makerogue b/src/cc/makerogue index fb7a53cec..d737f39fa 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -1,9 +1,8 @@ #!/bin/sh -echo "you can ignore ./makerogue: shell: not found" cd rogue; ./configure # only need this first time +echo "you can ignore ./makerogue: shell: not found" make; cd .. gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp -#gcc -std=c++11 -fPIC -shared -o librogue.so cclib.o rogue/rogue.so cp librogue.so ../libcc.so From 0ca1b888c395737651ddf73b4592d4021e3c7c30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:10:55 -1100 Subject: [PATCH 4/8] Test --- src/cc/rogue_rpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index b5e44aad5..510b67727 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1297,7 +1297,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) != 0 ) { fprintf(stderr,"height.%d rogue_isvalidgame error.%d\n",height,err); - //if ( height > 20000 ) + if ( height > 30000 ) return eval->Invalid("invalid gametxid"); } return(true); From 60e6554848eacda156de40263806f6966ca315a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:16:24 -1100 Subject: [PATCH 5/8] Test --- src/cc/rogue_rpc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 510b67727..d4ee66b57 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1294,12 +1294,14 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C switch ( funcid ) { case 'G': + gametxid = tx.GetHash(); if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) != 0 ) { - fprintf(stderr,"height.%d rogue_isvalidgame error.%d\n",height,err); + fprintf(stderr,"height.%d %s rogue_isvalidgame error.%d\n",height,gametxid.GetHex().c_str(),err); if ( height > 30000 ) return eval->Invalid("invalid gametxid"); } + fprintf(stderr,"height.%d %s rogue_isvalidgame\n",height,gametxid.GetHex().c_str()); return(true); break; case 'R': From 79e09db7e6a8a0b1c35fc5a3d75bd54f2ae9497d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:28:25 -1100 Subject: [PATCH 6/8] +print --- src/cc/rogue_rpc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index d4ee66b57..f7ac0162a 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -814,7 +814,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("playertxid",playertxid.GetHex())); if ( maxplayers == 1 || nextheight <= batonht+ROGUE_MAXKEYSTROKESGAP ) { - mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); // this validates user + mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); //this validates user if pk mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,batonvalue-txfee,roguepk,mypk)); Myprivkey(mypriv); CCaddr1of2set(cp,roguepk,mypk,mypriv,destaddr); @@ -1293,7 +1293,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C { switch ( funcid ) { - case 'G': + case 'G': // seems just need to make sure no vout abuse is left to do gametxid = tx.GetHash(); if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) != 0 ) { @@ -1301,7 +1301,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C if ( height > 30000 ) return eval->Invalid("invalid gametxid"); } - fprintf(stderr,"height.%d %s rogue_isvalidgame\n",height,gametxid.GetHex().c_str()); + //fprintf(stderr,"height.%d %s rogue_isvalidgame\n",height,gametxid.GetHex().c_str()); return(true); break; case 'R': @@ -1342,6 +1342,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C switch ( funcid ) { case 'R': // register + // verify vout amounts are as they should be and no vins that shouldnt be return(true); case 'H': // win case 'Q': // bailout From 961a1eb0a2b1967cfdb74fe548f661fd3b5a7713 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Feb 2019 23:28:46 -1100 Subject: [PATCH 7/8] Enforce new game --- src/cc/rogue_rpc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index f7ac0162a..ec1b669dc 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1298,8 +1298,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) != 0 ) { fprintf(stderr,"height.%d %s rogue_isvalidgame error.%d\n",height,gametxid.GetHex().c_str(),err); - if ( height > 30000 ) - return eval->Invalid("invalid gametxid"); + return eval->Invalid("invalid gametxid"); } //fprintf(stderr,"height.%d %s rogue_isvalidgame\n",height,gametxid.GetHex().c_str()); return(true); From f3c28c684a58e4601e439be6200f8365aac0d6fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Feb 2019 00:07:07 -1100 Subject: [PATCH 8/8] -print --- src/cc/rogue_rpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index ec1b669dc..9cef26d83 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1288,7 +1288,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C } if ( e == EVAL_ROGUE ) { - fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]); + //fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]); if ( decoded == 0 ) { switch ( funcid )