From 2ad90b9bd0c0a37a90c7d3bda6df5b4e2ace755b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 21:42:29 -1100 Subject: [PATCH 01/36] Skip staking utxo for ac_perc chains that stake --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b3248d7d4..f638afa8a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1190,6 +1190,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; j 100000 && ASSETCHAINS_STAKED != 0 && txn_count > 1 && i == txn_count-1 && n == 1 ) + break; //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; From 093635e9a8c750ecb8e5f93d321d94e5eb97e48f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 23:15:44 -1100 Subject: [PATCH 02/36] Initial validation skeleton --- src/cc/rewards.cpp | 2 +- src/cc/sudoku.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index bd5a6d919..b9f4677be 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -203,7 +203,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else { txid = tx.GetHash(); - if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 ) + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { if ( eval->GetTxUnconfirmed(fundingtxid,fundingTx,hashBlock) == 0 ) return eval->Invalid("cant find fundingtxid"); diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 5968f59d9..9d52728a3 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2909,5 +2909,36 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - return(true); + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t score,numvouts; char unsolved[82]; + if ( (numvouts= tx.vout.size()) > 1 ) + { + scriptPubKey = tx.vout[numvouts-1].scriptPubKey; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 ) + { + script = (uint8_t *)vopret.data(); + if ( script[0] == EVAL_SUDOKU ) + { + switch ( script[1] ) + { + case 'G': + if ( sudoku_genopreturndecode(unsolved,scriptPubKey) == 'G' ) + { + if ( dupree_solver(&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) + { + fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString()); + } + } + return(true); + case 'S': + fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,score,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString()); + return(true); + default: return eval->Invalid("invalid funcid"); + } + } else return eval->Invalid("invalid evalcode"); + + } + } + return eval->Invalid("not enough vouts"); } + From d6104a35c5c9200bed91806bbe41e2f40d8c9886 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 23:17:34 -1100 Subject: [PATCH 03/36] Fix --- src/cc/sudoku.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 9d52728a3..4dd096082 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2926,12 +2926,12 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { if ( dupree_solver(&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { - fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString()); + fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); } } return(true); case 'S': - fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,score,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString()); + fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); return(true); default: return eval->Invalid("invalid funcid"); } From c738557c58f90a3e166ca2a3b7b9ccdbe5dd44ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 23:38:17 -1100 Subject: [PATCH 04/36] Test --- src/cc/sudoku.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 4dd096082..b55024036 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -1781,12 +1781,13 @@ int dupree_solver(int32_t *scorep,char *puzzle) grid g, *s=0; FILE *h=0; soln_list = NULL; - /* Get our command name from invoking command line */ + myname = "internal"; + /* Get our command name from invoking command line if ((myname = strrchr(argv[0], '/')) == NULL) myname = argv[0]; else myname++; - /*argc = 3; + argc = 3; argv[1] = "-p"; argv[2] = puzzle; argv[3] = 0;*/ @@ -2924,6 +2925,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const case 'G': if ( sudoku_genopreturndecode(unsolved,scriptPubKey) == 'G' ) { + fprintf(stderr,"unsolved.(%s)\n",unsolved); if ( dupree_solver(&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); From 1856fca69c89a52a597cd0ea7929c661cccb3258 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 23:57:06 -1100 Subject: [PATCH 05/36] Free mem in solver --- src/cc/sudoku.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index b55024036..ad6927b6b 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -1773,7 +1773,7 @@ static char *cvt_to_mask(char *mbuf, char *sbuf) /* Mainline logic. */ /*******************/ -int dupree_solver(int32_t *scorep,char *puzzle) +int dupree_solver(int32_t dispflag,int32_t *scorep,char *puzzle) { int argc; char *argv[4]; int i, rc, bog, count, solved, unsolved, solncount=0, flag, prt_count, prt_num, prt_score, prt_answer, prt_depth, prt_grid, prt_mask, prt_givens, prt, len; @@ -1781,7 +1781,7 @@ int dupree_solver(int32_t *scorep,char *puzzle) grid g, *s=0; FILE *h=0; soln_list = NULL; - myname = "internal"; + myname = (char *)"internal"; /* Get our command name from invoking command line if ((myname = strrchr(argv[0], '/')) == NULL) myname = argv[0]; @@ -1873,15 +1873,6 @@ int dupree_solver(int32_t *scorep,char *puzzle) exit(1); } } -#endif - prt_answer = 1; /* print solution */ - //prt_count = 1; /* number solutions */ - prt_score = 1; - prt_givens = 1; - prt_num = 1; - /* Set prt flag if we're printing anything at all */ - prt = prt_mask | prt_grid | prt_score | prt_depth | prt_answer | prt_num | prt_givens; - /* Anthing else on the command line is bogus */ if (argc > optind) { fprintf(stderr, "Extraneous args: "); @@ -1912,6 +1903,15 @@ int dupree_solver(int32_t *scorep,char *puzzle) exit(1); } if (h) fgets(inbuf, 128, h);*/ +#endif + prt_answer = dispflag; /* print solution */ + //prt_count = dispflag; /* number solutions */ + prt_score = dispflag; + prt_givens = dispflag; + prt_num = dispflag; + /* Set prt flag if we're printing anything at all */ + prt = prt_mask | prt_grid | prt_score | prt_depth | prt_answer | prt_num | prt_givens; + strcpy(inbuf,puzzle); count = solved = unsolved = 0; //printf("inbuf.(%s)\n",inbuf); @@ -1927,7 +1927,7 @@ int dupree_solver(int32_t *scorep,char *puzzle) fprintf(rejects, "%d: %s bogus puzzle format\n", count, inbuf); fflush(rejects); *inbuf = 0; bog += 1; - if (h) fgets(inbuf, 128, h); + //if (h) fgets(inbuf, 128, h); continue; } @@ -1936,7 +1936,7 @@ int dupree_solver(int32_t *scorep,char *puzzle) fprintf(rejects, "%d: %*.*s bogus puzzle has less than 17 givens\n", count, PUZZLE_CELLS, PUZZLE_CELLS, inbuf); fflush(rejects); *inbuf = 0; bog += 1; - if (h) fgets(inbuf, 128, h); + //if (h) fgets(inbuf, 128, h); continue; } @@ -1973,6 +1973,11 @@ int dupree_solver(int32_t *scorep,char *puzzle) if (solncount > 1 && enumerate_all) { rc |= 1; } + for (s = soln_list; s;) { + s = soln_list->next; + free(soln_list); + soln_list = s; + } } else { unsolved++; @@ -1985,7 +1990,7 @@ int dupree_solver(int32_t *scorep,char *puzzle) } *inbuf = 0; - if (h) fgets(inbuf, 128, h); + //if (h) fgets(inbuf, 128, h); } //if (prt) fprintf(solnfile, "\nPuzzles: %d, Solved: %d, Unsolved: %d, Bogus: %d\n", count, solved, unsolved, bog); @@ -2629,7 +2634,7 @@ UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params str[i] = '0' + unsolved[i/9][i%9]; str[i] = 0; printf("solve: %s\n",str); - if ( dupree_solver(&score,str) == 1 ) + if ( dupree_solver(1,&score,str) == 1 ) { amount = score * COIN; break; @@ -2926,7 +2931,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( sudoku_genopreturndecode(unsolved,scriptPubKey) == 'G' ) { fprintf(stderr,"unsolved.(%s)\n",unsolved); - if ( dupree_solver(&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) + if ( dupree_solver(0,&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); } From 71e47834e2bbcc8eacb15cb2b35a15c467fa3d21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:01:19 -1100 Subject: [PATCH 06/36] Enforce score == payout --- src/cc/sudoku.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index ad6927b6b..10485ec2d 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2930,10 +2930,12 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const case 'G': if ( sudoku_genopreturndecode(unsolved,scriptPubKey) == 'G' ) { - fprintf(stderr,"unsolved.(%s)\n",unsolved); + //fprintf(stderr,"unsolved.(%s)\n",unsolved); if ( dupree_solver(0,&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); + if ( ht > 2000 ) + return eval->Invalid("mismatched sudoku value vs score"); } } return(true); From a5833d00f701966efeb6adf04fd0555a48ef46b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:04:51 -1100 Subject: [PATCH 07/36] Height --- src/cc/sudoku.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 10485ec2d..395fac577 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2934,7 +2934,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( dupree_solver(0,&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); - if ( ht > 2000 ) + if ( height > 2000 ) return eval->Invalid("mismatched sudoku value vs score"); } } From d97754614d9365f9aa3a1e575e9ed8048f2069e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:40:38 -1100 Subject: [PATCH 08/36] Check solution I-return --- src/cc/sudoku.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 395fac577..6a0f97583 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2586,6 +2586,35 @@ CScript sudoku_solutionopret(char *solution,uint32_t timestamps[81]) return(opret); } +uint8_t sudoku_solutionopreturndecode(char solution[82],uint32_t timestamps[81],CScript scriptPubKey) +{ + std::vector vopret; uint8_t *script,e,f; std::string str; std::vector data; int32_t i,ind; uint32_t x; + GetOpReturnData(scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> str; ss >> data) != 0 && e == EVAL_SUDOKU && f == 'S' ) + { + if ( data.size() == 81*sizeof(uint32_t) && strlen(solution) == 81 ) + { + for (i=ind=0; i<81; i++) + { + if ( solution[i] < '1' || solution[i] > '9' ) + break; + x = data[ind++]; + x <<= 8, x |= (data[ind++] & 0xff); + x <<= 8, x |= (data[ind++] & 0xff); + x <<= 8, x |= (data[ind++] & 0xff); + timestamps[i] = x; + } + if ( i == 81 ) + { + strcpy(solution,str.c_str()); + return(f); + } + } + } + return(0); +} + uint8_t sudoku_genopreturndecode(char *unsolved,CScript scriptPubKey) { std::vector vopret; uint8_t *script,e,f; std::vector data; int32_t i; @@ -2915,7 +2944,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_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 score,numvouts; char unsolved[82]; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t score,numvouts; char unsolved[82],solution[82]; uint32_t timestamps[81]; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2936,12 +2965,19 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); if ( height > 2000 ) return eval->Invalid("mismatched sudoku value vs score"); - } + } else return(true); } - return(true); + return eval->Invalid("invalid generate opreturn"); case 'S': fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); - return(true); + if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) + { + for (i=0; i<81; i++) + fprintf(stderr,"%u ",timestamps[i]); + fprintf(stderr,"%s\n",solution); + return(true); + } + return eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); } } else return eval->Invalid("invalid evalcode"); From 4aa8fce7d2f79f3282c7c3899deaab2dd18af01a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:41:15 -1100 Subject: [PATCH 09/36] Declare I --- src/cc/sudoku.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 6a0f97583..4f8702c0a 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2944,7 +2944,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_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 score,numvouts; char unsolved[82],solution[82]; uint32_t timestamps[81]; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,score,numvouts; char unsolved[82],solution[82]; uint32_t timestamps[81]; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; From 503ef504482963e300722d60d0e52a3957d984b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:45:08 -1100 Subject: [PATCH 10/36] Exempt height 123 --- src/cc/sudoku.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 4f8702c0a..c83cf3464 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2967,6 +2967,8 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const return eval->Invalid("mismatched sudoku value vs score"); } else return(true); } + else if ( height == 123 ) // early version invalid gen + return(true); return eval->Invalid("invalid generate opreturn"); case 'S': fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); From 0a0d310f7f2c296caa124cbf38aa0e4c362f1682 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:47:23 -1100 Subject: [PATCH 11/36] Print --- src/cc/sudoku.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index c83cf3464..878d9a86d 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2969,6 +2969,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const } else if ( height == 123 ) // early version invalid gen return(true); + fprintf(stderr,"height.%d txid.%s\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid generate opreturn"); case 'S': fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); From d23000ccf5290756fa5bd899a49b2bccc188c7ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:48:57 -1100 Subject: [PATCH 12/36] Add return true path --- src/cc/sudoku.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 878d9a86d..49b23a367 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2965,10 +2965,9 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); if ( height > 2000 ) return eval->Invalid("mismatched sudoku value vs score"); + else return(true); } else return(true); } - else if ( height == 123 ) // early version invalid gen - return(true); fprintf(stderr,"height.%d txid.%s\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid generate opreturn"); case 'S': From 7fc53be997b90353e56e377e7ff9fb8adef828c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:51:32 -1100 Subject: [PATCH 13/36] Bad solution ? --- src/cc/sudoku.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 49b23a367..87570e7e2 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2963,7 +2963,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( dupree_solver(0,&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); - if ( height > 2000 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || height > 2000 ) return eval->Invalid("mismatched sudoku value vs score"); else return(true); } else return(true); @@ -2979,6 +2979,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%s\n",solution); return(true); } + fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); } From 8dc9205db0e5604e647f19d8305ec794608fa48e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:52:53 -1100 Subject: [PATCH 14/36] Ht 236 exemption --- src/cc/sudoku.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 87570e7e2..097153d40 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2980,6 +2980,8 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const return(true); } fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); + if ( height == 236 && strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 ) + return(true); return eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); } From 03bad588edf2836a8629429174a2336d4068a6c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 00:57:52 -1100 Subject: [PATCH 15/36] 1220 exemption --- src/cc/sudoku.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 097153d40..57a88707e 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2980,7 +2980,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const return(true); } fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); - if ( height == 236 && strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 ) + if ( (height == 236 || height == 1220) && strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 ) return(true); return eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); From 16be17121fba408c7674f4a34a9f487ea4de9812 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:01:30 -1100 Subject: [PATCH 16/36] str.size()! --- src/cc/sudoku.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 57a88707e..2624fc54c 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2593,7 +2593,7 @@ uint8_t sudoku_solutionopreturndecode(char solution[82],uint32_t timestamps[81], script = (uint8_t *)vopret.data(); if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> str; ss >> data) != 0 && e == EVAL_SUDOKU && f == 'S' ) { - if ( data.size() == 81*sizeof(uint32_t) && strlen(solution) == 81 ) + if ( data.size() == 81*sizeof(uint32_t) && str.size() == 81 ) { for (i=ind=0; i<81; i++) { @@ -2610,7 +2610,7 @@ uint8_t sudoku_solutionopreturndecode(char solution[82],uint32_t timestamps[81], strcpy(solution,str.c_str()); return(f); } - } + } else fprintf(stderr,"datasize %d sol[%d]\n",(int32_t)data.size(),(int32_t)str.size()); } return(0); } @@ -2982,7 +2982,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); if ( (height == 236 || height == 1220) && strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 ) return(true); - return eval->Invalid("invalid solution opreturn"); + return true; //eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); } } else return eval->Invalid("invalid evalcode"); From c0e2024b3c46888aa66c12792bab734433076737 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:03:29 -1100 Subject: [PATCH 17/36] Dont use uninitialized variables --- src/cc/sudoku.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 2624fc54c..c151e25fc 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2595,6 +2595,7 @@ uint8_t sudoku_solutionopreturndecode(char solution[82],uint32_t timestamps[81], { if ( data.size() == 81*sizeof(uint32_t) && str.size() == 81 ) { + strcpy(solution,str.c_str()); for (i=ind=0; i<81; i++) { if ( solution[i] < '1' || solution[i] > '9' ) @@ -2606,10 +2607,7 @@ uint8_t sudoku_solutionopreturndecode(char solution[82],uint32_t timestamps[81], timestamps[i] = x; } if ( i == 81 ) - { - strcpy(solution,str.c_str()); return(f); - } } else fprintf(stderr,"datasize %d sol[%d]\n",(int32_t)data.size(),(int32_t)str.size()); } return(0); From 9b966a4e725f584e7b031bc79275a42cd6766bc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:06:30 -1100 Subject: [PATCH 18/36] filter prints --- src/cc/sudoku.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index c151e25fc..585f4fb3d 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2942,7 +2942,8 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_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,score,numvouts; char unsolved[82],solution[82]; uint32_t timestamps[81]; + static char laststr[512]; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2960,7 +2961,12 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const //fprintf(stderr,"unsolved.(%s)\n",unsolved); if ( dupree_solver(0,&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) { - fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); + sprintf(str,"ht.%d score.%d vs %.8f %s",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString().c_str()); + if ( strcmp(str,laststr) != 0 ) + { + strcpy(laststr,str); + fprintf(stderr,"%s\n",str); + } if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || height > 2000 ) return eval->Invalid("mismatched sudoku value vs score"); else return(true); @@ -2969,7 +2975,12 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"height.%d txid.%s\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid generate opreturn"); case 'S': - fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); + sprintf(str,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); + if ( strcmp(str,laststr) != 0 ) + { + strcpy(laststr,str); + fprintf(stderr,"%s\n",str); + } if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) { for (i=0; i<81; i++) From 31e3cba48be4a0da0f0accae6dd64721b856fa0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:07:27 -1100 Subject: [PATCH 19/36] Prints --- src/cc/sudoku.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 585f4fb3d..7fcfedb52 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2943,7 +2943,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2980,18 +2980,20 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { strcpy(laststr,str); fprintf(stderr,"%s\n",str); - } + dispflag = 1; + } else dispflag = 0; if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) { - for (i=0; i<81; i++) - fprintf(stderr,"%u ",timestamps[i]); - fprintf(stderr,"%s\n",solution); + if ( dispflag != 0 ) + { + for (i=0; i<81; i++) + fprintf(stderr,"%u ",timestamps[i]); + fprintf(stderr,"%s\n",solution); + } return(true); } fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); - if ( (height == 236 || height == 1220) && strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 ) - return(true); - return true; //eval->Invalid("invalid solution opreturn"); + return eval->Invalid("invalid solution opreturn"); default: return eval->Invalid("invalid funcid"); } } else return eval->Invalid("invalid evalcode"); From 75834b5beb2c78cfb4b040e6a04b5058008c4d28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:21:21 -1100 Subject: [PATCH 20/36] Print captcha data --- src/cc/sudoku.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 7fcfedb52..3457a5840 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2517,7 +2517,7 @@ void sudoku_gen(uint8_t key32[32],uint8_t unsolved[9][9],uint32_t srandi) cclib solution 17 \"[%224d50336780d5a300a1f01b12fe36f46a82f3b9935bb115e01e0113dc4f337aae%22,%22234791685716258943589643712865934127341827596927516438492375861178462359653189274%22,0,0,1548859143,1548859146,0,1548859146,0,1548859148,1548859149,0,1548859151,1548859152,0,1548859154,1548859155,1548859158,1548859159,0,0,0,1548859161,1548859163,0,1548859164,1548859168,0,1548859168,1548859170,1548859172,1548859172,1548859175,0,0,1548859176,0,0,1548859178,1548859178,0,0,1548859180,1548859181,1548859183,1548859184,1548859185,1548859186,1548859188,1548859190,1548859191,1548859192,1548859192,0,0,1548859195,1548859196,1548859197,1548859198,0,0,1548859199,1548859202,1548859202,0,1548859204,1548859205,1548859206,1548859209,1548859210,1548859211,1548859212,0,1548859214,1548859216,0,1548859217,1548859218,1548859219,1548859220,0,1548859222,1548859222]\" */ -int32_t sudoku_captcha(uint32_t timestamps[81]) +int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) { int32_t i,solvetime,diff,avetime,n = 0; uint64_t variance = 0; std::vector list; for (i=0; i<81; i++) @@ -2858,7 +2858,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params result.push_back(Pair("sudokuaddr",CCaddr)); balance = CCaddress_balance(CCaddr); result.push_back(Pair("amount",ValueFromAmount(balance))); - if ( sudoku_captcha(timestamps) < 0 ) + if ( sudoku_captcha(timestamps,komodo_nextheight()) < 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","captcha failure")); @@ -2975,11 +2975,11 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"height.%d txid.%s\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid generate opreturn"); case 'S': - sprintf(str,"SOLVED ht.%d %.8f %s\n",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); + sprintf(str,"SOLVED ht.%d %.8f %s",height,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString().c_str()); if ( strcmp(str,laststr) != 0 ) { strcpy(laststr,str); - fprintf(stderr,"%s\n",str); + fprintf(stderr,"\n%s\n",str); dispflag = 1; } else dispflag = 0; if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) @@ -2989,6 +2989,8 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const for (i=0; i<81; i++) fprintf(stderr,"%u ",timestamps[i]); fprintf(stderr,"%s\n",solution); + if ( sudoku_captcha(timestamps,height) < 0 ) + return eval->Invalid("failed captcha"); } return(true); } From 0b297c6c859dd4bc6d854706a86fc43605fb90b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:26:08 -1100 Subject: [PATCH 21/36] Test --- src/cc/sudoku.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 3457a5840..613a38e8b 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2519,7 +2519,7 @@ void sudoku_gen(uint8_t key32[32],uint8_t unsolved[9][9],uint32_t srandi) int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) { - int32_t i,solvetime,diff,avetime,n = 0; uint64_t variance = 0; std::vector list; + int32_t i,solvetime,diff,avetime,n = 0,retval = 0; uint64_t variance = 0; std::vector list; for (i=0; i<81; i++) { if ( timestamps[i] != 0 ) @@ -2535,17 +2535,17 @@ int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) if ( list[0] >= list[n-1] ) { printf("list[0] %u vs list[%d-1] %u\n",list[0],n,list[n-1]); - return(-1); + retval = -1; } else if ( list[n-1] > chainActive.LastTip()->nTime+200 ) - return(-1); + retval = -2; else if ( solvetime >= 777 ) - return(0); + retval = 0; else { avetime = (solvetime / (n-1)); if ( avetime == 0 ) - return(-1); + retval = -3; for (i=0; i Date: Thu, 31 Jan 2019 01:54:33 -1100 Subject: [PATCH 22/36] More validation --- src/cc/sudoku.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 613a38e8b..426d46971 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2948,7 +2948,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2989,15 +2989,33 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const } else dispflag = 0; if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) { - if ( dispflag != 0 ) + if ( tx.vin.size() > 1 && tx.vin[0].prevout.hash == tx.vin[1].prevout.hash && tx.vin[0].prevout.n == 0 && tx.vin[1].prevout.n == 1 && myGetTransaction(tx.vin[0].prevout.hash,vintx,hashBlock) != 0 ) { - for (i=0; i<81; i++) - fprintf(stderr,"%u ",timestamps[i]); - fprintf(stderr,"%s\n",solution); - if ( sudoku_captcha(timestamps,height) < 0 ) - return eval->Invalid("failed captcha"); - } - return(true); + if ( vintx.vout.size() > 1 && sudoku_genopreturndecode(unsolved,vintx.vout[vintx.vout.size()-1].scriptPubKey) == 'G' ) + { + if ( dispflag != 0 ) + { + for (i=0; i<81; i++) + { + fprintf(stderr,"%u ",timestamps[i]); + if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) + { + fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c]\n",i,unsolved[i]); + return eval->Invalid("invalid timestamp vs unsolved"); + } + } + if ( dupree_solver(0,&score,unsolved) != 1 ) + { + fprintf(stderr,"non-unique sudoku at ht.%d\n",height); + return eval->Invalid("invalid sudoku with multiple solutions"); + } + fprintf(stderr,"%s score.%d\n",solution,score); + } + if ( sudoku_captcha(timestamps,height) < 0 ) + return eval->Invalid("failed captcha"); + return(true); + } else return eval->Invalid("invalid solution opret"); + } else return eval->Invalid("invalid solution vin"); } fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid solution opreturn"); From 40f628504af4e5412add4cdf5cef5fae0d344a6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 01:56:57 -1100 Subject: [PATCH 23/36] Test --- src/cc/sudoku.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 426d46971..86f61ee0a 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -3015,7 +3015,10 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const return eval->Invalid("failed captcha"); return(true); } else return eval->Invalid("invalid solution opret"); - } else return eval->Invalid("invalid solution vin"); + } + else if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") == 0 && height == 236 ) + return(true); + else return eval->Invalid("invalid solution vin"); } fprintf(stderr,"solution ht.%d %s bad opret\n",height,tx.GetHash().ToString().c_str()); return eval->Invalid("invalid solution opreturn"); From 6b3d8f710dcef2b95d6795ebb4fbc74cbfe7052e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:00:11 -1100 Subject: [PATCH 24/36] 1220 exemption --- src/cc/sudoku.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 86f61ee0a..b8cdb88e5 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -3000,8 +3000,9 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%u ",timestamps[i]); if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) { - fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c]\n",i,unsolved[i]); - return eval->Invalid("invalid timestamp vs unsolved"); + fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c] %s\n",i,unsolved[i],unsolved); + if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || height != 1220 ) + return eval->Invalid("invalid timestamp vs unsolved"); } } if ( dupree_solver(0,&score,unsolved) != 1 ) From ba0a1b5ae4bcf64b0359dca7a8696f2649956517 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:04:06 -1100 Subject: [PATCH 25/36] Test --- src/cc/sudoku.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index b8cdb88e5..4f283b69d 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -3000,9 +3000,9 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%u ",timestamps[i]); if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) { - fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c] %s\n",i,unsolved[i],unsolved); - if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || height != 1220 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || (height != 1220 && height != 1383) ) return eval->Invalid("invalid timestamp vs unsolved"); + else fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c] %s\n",i,unsolved[i],unsolved); } } if ( dupree_solver(0,&score,unsolved) != 1 ) From de547e23accdc55e803faaf9a37a8061cf35b99d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:09:21 -1100 Subject: [PATCH 26/36] Unsolved print --- src/cc/sudoku.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 4f283b69d..a31bf4d60 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2948,7 +2948,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2993,25 +2993,28 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { if ( vintx.vout.size() > 1 && sudoku_genopreturndecode(unsolved,vintx.vout[vintx.vout.size()-1].scriptPubKey) == 'G' ) { - if ( dispflag != 0 ) + for (i=errflag=0; i<81; i++) { - for (i=0; i<81; i++) - { + if ( dispflag != 0 ) fprintf(stderr,"%u ",timestamps[i]); - if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) - { - if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 || (height != 1220 && height != 1383) ) - return eval->Invalid("invalid timestamp vs unsolved"); - else fprintf(stderr,"i.%d invalid timestamp vs unsolved.[%c] %s\n",i,unsolved[i],unsolved); - } - } - if ( dupree_solver(0,&score,unsolved) != 1 ) - { - fprintf(stderr,"non-unique sudoku at ht.%d\n",height); - return eval->Invalid("invalid sudoku with multiple solutions"); - } - fprintf(stderr,"%s score.%d\n",solution,score); + if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) + errflag++; } + if ( errflag != 0 ) + { + if ( dispflag != 0 ) + fprintf(stderr,"errflag.%d %s\n",height,errflag,unsolved); + if ( (height != 1220 && height != 1383) || strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 ) + return eval->Invalid("invalid timestamp vs unsolved"); + } + if ( dupree_solver(0,&score,unsolved) != 1 ) + { + if ( dispflag != 0 ) + fprintf(stderr,"non-unique sudoku at ht.%d\n",height); + return eval->Invalid("invalid sudoku with multiple solutions"); + } + if ( dispflag != 0 ) + fprintf(stderr,"%s score.%d\n",solution,score); if ( sudoku_captcha(timestamps,height) < 0 ) return eval->Invalid("failed captcha"); return(true); From cc8fadd7c554d1b342ad9485553dadd741a65cf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:09:52 -1100 Subject: [PATCH 27/36] Fix print --- src/cc/sudoku.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index a31bf4d60..228ccc095 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -3003,7 +3003,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( errflag != 0 ) { if ( dispflag != 0 ) - fprintf(stderr,"errflag.%d %s\n",height,errflag,unsolved); + fprintf(stderr,"ht.%d errflag.%d %s\n",height,errflag,unsolved); if ( (height != 1220 && height != 1383) || strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 ) return eval->Invalid("invalid timestamp vs unsolved"); } From d9a8323b60a7305008e7ddab4ff05576409d01ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:11:52 -1100 Subject: [PATCH 28/36] Reverse polarity --- src/cc/sudoku.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 228ccc095..0d1a33e07 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2997,7 +2997,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { if ( dispflag != 0 ) fprintf(stderr,"%u ",timestamps[i]); - if ( (timestamps[i] == 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] != 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) + if ( (timestamps[i] != 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] == 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) errflag++; } if ( errflag != 0 ) @@ -3014,7 +3014,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const return eval->Invalid("invalid sudoku with multiple solutions"); } if ( dispflag != 0 ) - fprintf(stderr,"%s score.%d\n",solution,score); + fprintf(stderr,"%s score.%d %s\n",solution,score,unsolved); if ( sudoku_captcha(timestamps,height) < 0 ) return eval->Invalid("failed captcha"); return(true); From e37fd6ef9081e3b8a1fc63f6e6c47e489d98fbc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:19:27 -1100 Subject: [PATCH 29/36] Scores convergence --- src/cc/sudoku.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 0d1a33e07..dc8fb2f42 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -3017,6 +3017,20 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%s score.%d %s\n",solution,score,unsolved); if ( sudoku_captcha(timestamps,height) < 0 ) return eval->Invalid("failed captcha"); + for (i=0; i<81; i++) + { + if ( (ind= sudoku_minval(timestamps)) >= 0 ) + { + unsolved[ind] = solution[ind]; + if ( dupree_solver(0,&score,unsolved) != 1 ) + fprintf(stderr,"i.%d ind.%d non-unique\n",i,ind); + if ( dispflag != 0 ) + fprintf(stderr,"%d ",score); + timestamps[ind] = 0; + } else break; + } + if ( dispflag != 0 ) + fprintf(stderr,"scores convergence\n"); return(true); } else return eval->Invalid("invalid solution opret"); } From 9e9f33d00c62ef874cef3a3ec52e681e638b065a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:22:04 -1100 Subject: [PATCH 30/36] mintimestamp --- src/cc/sudoku.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index dc8fb2f42..b69081065 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2945,6 +2945,15 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params return(result); } +sudoku_minval(uint32_t timestamps[81]) +{ + int32_t i,ind = -1; uint32_t mintimestamp = 0xffffffff; + for (i=0; i<81; i++) + if ( timestamps[i] != 0 && timestamps[i] < mintimestamp ) + mintimestamp = timestamps[i], ind = i; + return(ind); +} + bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; From fea0e3f845bebe93438fe12dcf0ec13b6c2ee968 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:22:51 -1100 Subject: [PATCH 31/36] Ind --- src/cc/sudoku.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index b69081065..ff48af50c 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2957,7 +2957,7 @@ sudoku_minval(uint32_t timestamps[81]) bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; From 94f4c7c7de1a29a4befcd3147ce1cea34bb07dcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:25:46 -1100 Subject: [PATCH 32/36] sudoku_minval --- src/cc/sudoku.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index ff48af50c..af404807f 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2945,12 +2945,16 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params return(result); } -sudoku_minval(uint32_t timestamps[81]) +int32_t sudoku_minval(uint32_t timestamps[81]) { int32_t i,ind = -1; uint32_t mintimestamp = 0xffffffff; for (i=0; i<81; i++) if ( timestamps[i] != 0 && timestamps[i] < mintimestamp ) + { mintimestamp = timestamps[i], ind = i; + fprintf(stderr,"%d ",i); + } + fprintf(stderr,"mintimestamp.%u\n",mintimestamp); return(ind); } From 7ed14754e59909bbf0519404304f42a199379fe8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:27:52 -1100 Subject: [PATCH 33/36] -print --- src/cc/sudoku.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index af404807f..ca2eddd91 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2952,9 +2952,9 @@ int32_t sudoku_minval(uint32_t timestamps[81]) if ( timestamps[i] != 0 && timestamps[i] < mintimestamp ) { mintimestamp = timestamps[i], ind = i; - fprintf(stderr,"%d ",i); + //fprintf(stderr,"%d ",i); } - fprintf(stderr,"mintimestamp.%u\n",mintimestamp); + //fprintf(stderr,"mintimestamp.%u\n",mintimestamp); return(ind); } @@ -3035,11 +3035,11 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( (ind= sudoku_minval(timestamps)) >= 0 ) { unsolved[ind] = solution[ind]; + timestamps[ind] = 0; if ( dupree_solver(0,&score,unsolved) != 1 ) fprintf(stderr,"i.%d ind.%d non-unique\n",i,ind); if ( dispflag != 0 ) fprintf(stderr,"%d ",score); - timestamps[ind] = 0; } else break; } if ( dispflag != 0 ) From b79e7c623192f22f833527994d2625341138b343 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:31:35 -1100 Subject: [PATCH 34/36] Time diffs --- src/cc/sudoku.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index ca2eddd91..b650b1d00 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2961,7 +2961,7 @@ int32_t sudoku_minval(uint32_t timestamps[81]) bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t lasttime,timestamps[81]; CTransaction vintx; uint256 hashBlock; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -3030,16 +3030,19 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%s score.%d %s\n",solution,score,unsolved); if ( sudoku_captcha(timestamps,height) < 0 ) return eval->Invalid("failed captcha"); - for (i=0; i<81; i++) + for (i=lasttime=0; i<81; i++) { if ( (ind= sudoku_minval(timestamps)) >= 0 ) { unsolved[ind] = solution[ind]; - timestamps[ind] = 0; + if ( lasttime == 0 ) + lasttime = timestamps[ind]; if ( dupree_solver(0,&score,unsolved) != 1 ) fprintf(stderr,"i.%d ind.%d non-unique\n",i,ind); if ( dispflag != 0 ) - fprintf(stderr,"%d ",score); + fprintf(stderr,"%d.%d ",score,timestamps[ind]-lasttime); + lasttime = timestamps[ind]; + timestamps[ind] = 0; } else break; } if ( dispflag != 0 ) From 7cb34662f7d9ccb569637b57eafad9b90bf094b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:41:53 -1100 Subject: [PATCH 35/36] Errcheck --- src/cc/sudoku.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index b650b1d00..01016de81 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2555,13 +2555,13 @@ int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) } variance /= (n - 1); printf("solvetime.%d n.%d avetime.%d variance.%llu vs ave2 %d\n",solvetime,n,avetime,(long long)variance,avetime*avetime); - if ( variance < avetime*avetime ) - return(-1 * 0); + if ( variance < avetime ) + retval = -5; else return(0); } - } else retval = -5; + } else retval = -6; if ( retval != 0 ) - fprintf(stderr,"retval.%d\n",retval); + fprintf(stderr,"ERR >>>>>>>>>>>>>>> ht.%d retval.%d\n",height,retval); if ( height < 2000 ) return(0); else return(retval); @@ -2961,7 +2961,7 @@ int32_t sudoku_minval(uint32_t timestamps[81]) bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static char laststr[512]; - CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t lasttime,timestamps[81]; CTransaction vintx; uint256 hashBlock; + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t i,ind,errflag,dispflag,score,numvouts; char unsolved[82],solution[82],str[512]; uint32_t timestamps[81]; CTransaction vintx; uint256 hashBlock; if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -2997,7 +2997,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const if ( strcmp(str,laststr) != 0 ) { strcpy(laststr,str); - fprintf(stderr,"\n%s\n",str); + fprintf(stderr,"%s\n",str); dispflag = 1; } else dispflag = 0; if ( sudoku_solutionopreturndecode(solution,timestamps,scriptPubKey) == 'S' ) @@ -3008,7 +3008,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { for (i=errflag=0; i<81; i++) { - if ( dispflag != 0 ) + if ( 0 && dispflag != 0 ) fprintf(stderr,"%u ",timestamps[i]); if ( (timestamps[i] != 0 && unsolved[i] >= '1' && unsolved[i] <= '9') || (timestamps[i] == 0 && (unsolved[i] < '1' || unsolved[i] > '9')) ) errflag++; @@ -3030,7 +3030,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const fprintf(stderr,"%s score.%d %s\n",solution,score,unsolved); if ( sudoku_captcha(timestamps,height) < 0 ) return eval->Invalid("failed captcha"); - for (i=lasttime=0; i<81; i++) + /*for (i=lasttime=0; i<81; i++) { if ( (ind= sudoku_minval(timestamps)) >= 0 ) { @@ -3046,7 +3046,7 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const } else break; } if ( dispflag != 0 ) - fprintf(stderr,"scores convergence\n"); + fprintf(stderr,"scores convergence\n");*/ return(true); } else return eval->Invalid("invalid solution opret"); } From 659a5dda2a99090d67fc8d4de8a2d315ca600497 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 02:50:29 -1100 Subject: [PATCH 36/36] Initial validation --- src/cc/sudoku.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 01016de81..7cff6b280 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2517,7 +2517,7 @@ void sudoku_gen(uint8_t key32[32],uint8_t unsolved[9][9],uint32_t srandi) cclib solution 17 \"[%224d50336780d5a300a1f01b12fe36f46a82f3b9935bb115e01e0113dc4f337aae%22,%22234791685716258943589643712865934127341827596927516438492375861178462359653189274%22,0,0,1548859143,1548859146,0,1548859146,0,1548859148,1548859149,0,1548859151,1548859152,0,1548859154,1548859155,1548859158,1548859159,0,0,0,1548859161,1548859163,0,1548859164,1548859168,0,1548859168,1548859170,1548859172,1548859172,1548859175,0,0,1548859176,0,0,1548859178,1548859178,0,0,1548859180,1548859181,1548859183,1548859184,1548859185,1548859186,1548859188,1548859190,1548859191,1548859192,1548859192,0,0,1548859195,1548859196,1548859197,1548859198,0,0,1548859199,1548859202,1548859202,0,1548859204,1548859205,1548859206,1548859209,1548859210,1548859211,1548859212,0,1548859214,1548859216,0,1548859217,1548859218,1548859219,1548859220,0,1548859222,1548859222]\" */ -int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) +int32_t sudoku_captcha(int32_t dispflag,uint32_t timestamps[81],int32_t height) { int32_t i,solvetime,diff,avetime,n = 0,retval = 0; uint64_t variance = 0; std::vector list; for (i=0; i<81; i++) @@ -2549,20 +2549,22 @@ int32_t sudoku_captcha(uint32_t timestamps[81],int32_t height) for (i=0; i>>>>>>>>>>>>>> ht.%d retval.%d\n",height,retval); - if ( height < 2000 ) + if ( height <= 2036 ) return(0); else return(retval); } @@ -2863,7 +2865,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params result.push_back(Pair("sudokuaddr",CCaddr)); balance = CCaddress_balance(CCaddr); result.push_back(Pair("amount",ValueFromAmount(balance))); - if ( sudoku_captcha(timestamps,komodo_nextheight()) < 0 ) + if ( sudoku_captcha(1,timestamps,komodo_nextheight()) < 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","captcha failure")); @@ -3024,11 +3026,12 @@ bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const { if ( dispflag != 0 ) fprintf(stderr,"non-unique sudoku at ht.%d\n",height); - return eval->Invalid("invalid sudoku with multiple solutions"); + if ( strcmp(ASSETCHAINS_SYMBOL,"SUDOKU") != 0 ) + return eval->Invalid("invalid sudoku with multiple solutions"); } if ( dispflag != 0 ) fprintf(stderr,"%s score.%d %s\n",solution,score,unsolved); - if ( sudoku_captcha(timestamps,height) < 0 ) + if ( sudoku_captcha(dispflag,timestamps,height) < 0 ) return eval->Invalid("failed captcha"); /*for (i=lasttime=0; i<81; i++) {