diff --git a/src/hush_utils.h b/src/hush_utils.h index a80e191e5..f81ae46aa 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 The Hush developers +// Copyright (c) 2016-2020 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** @@ -949,9 +949,7 @@ int32_t dragon_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian case 4: *(uint32_t *)endianedp = (uint32_t)x; break; case 8: *(uint64_t *)endianedp = (uint64_t)x; break; } - } - else - { + } else { x = 0; switch ( len ) { @@ -1464,11 +1462,14 @@ uint16_t komodo_userpass(char *userpass,char *symbol) return(port); } +#define HUSH_MAGIC 0xc0decafe + +// CAN YOU FEEL THE HUSH MAGIC??? uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t extralen) { uint8_t buf[512]; uint32_t crc0=0; int32_t len = 0; bits256 hash; - if ( strcmp(symbol,"KMD") == 0 ) - return(0x8de4eef9); + if ( strcmp(symbol,"HUSH3") == 0 ) + return(HUSH_MAGIC); len = dragon_rwnum(1,&buf[len],sizeof(supply),(void *)&supply); strcpy((char *)&buf[len],symbol); len += strlen(symbol); @@ -1485,34 +1486,35 @@ uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_ uint16_t komodo_assetport(uint32_t magic,int32_t extralen) { - if ( magic == 0x8de4eef9 ) - return(7770); + if(fDebug) + fprintf(stderr,"%s: extralen=%d\n",__func__,extralen); else if ( extralen == 0 ) return(8000 + (magic % 7777)); else return(16000 + (magic % 49500)); } +// DUKE: extralen is sometimes wrong which causes wrong diffbits? +// This function is only called on startup, blocktime changing code does not modify magic +// Hush 3.5.x and Hush 3.6.x have same history and p2p ports, but different magic uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,uint8_t *extraptr,int32_t extralen) { - if ( symbol == 0 || symbol[0] == 0 || strcmp("KMD",symbol) == 0 ) + if(fDebug) + fprintf(stderr,"%s: extralen=%d\n",__func__,extralen); + /* + if ( strcmp("HUSH3",symbol) == 0 ) { - *magicp = 0x8de4eef9; - return(7770); + //TODO: magic of hush 3.5.x + *magicp = 0x8de4beef; + return(18030); } + */ *magicp = komodo_assetmagic(symbol,supply,extraptr,extralen); + if(fDebug) + fprintf(stderr,"%s: extralen=%d, magic=%d, supply=%l\n",__func__,extralen, &magic, supply); + return(komodo_assetport(*magicp,extralen)); } -/*void komodo_ports(uint16_t ports[MAX_CURRENCIES]) -{ - int32_t i; uint32_t magic; - for (i=0; i (uint64_t)90*1000*1000000 ) { - fprintf(stderr,"-ac_supply must be less than 90 billion\n"); + fprintf(stderr,"-ac_supply must be less than 90 billion, derpz\n"); StartShutdown(); } - fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); + if(fDebug) + fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); - ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); + ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); - ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); - ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); - ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); - ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); - ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); - ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0); - //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); - if ( ASSETCHAINS_CBOPRET != 0 ) - { + ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); + ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); + ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); + ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0); + if(fDebug) + fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); + if ( ASSETCHAINS_CBOPRET != 0 ) { SplitStr(GetArg("-ac_prices",""), ASSETCHAINS_PRICES); if ( ASSETCHAINS_PRICES.size() > 0 ) ASSETCHAINS_CBOPRET |= 4; @@ -2088,14 +2091,12 @@ void hush_args(char *argv0) StartShutdown(); } - + // HUSH will always be The First Pure Sapling Coin, no Sprout JoinSplits in our history! ;) ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { ASSETCHAINS_OVERWINTER = GetArg("-ac_overwinter", -1); - } - else - { + } else { ASSETCHAINS_OVERWINTER = GetArg("-ac_overwinter", ASSETCHAINS_SAPLING); } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) @@ -2121,9 +2122,7 @@ void hush_args(char *argv0) { ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); - } - else - { + } else { printf("ASSETCHAINS_FOUNDERS_REWARD set to %ld\n", ASSETCHAINS_FOUNDERS_REWARD); } /*else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) @@ -2132,9 +2131,7 @@ void hush_args(char *argv0) printf("-ac_perc must be set with -ac_pubkey\n"); }*/ } - } - else - { + } else { if ( ASSETCHAINS_COMMISSION != 0 ) { ASSETCHAINS_COMMISSION = 0; @@ -2147,23 +2144,26 @@ void hush_args(char *argv0) } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || HUSH_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) { - fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); + if(fDebug) + fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; // if we have one era, this should create the same data structure as it used to, same if we increase _MAX_ERAS for ( int i = 0; i <= ASSETCHAINS_LASTERA; i++ ) { - printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu notarypay.%llu\n", i, + if (fDebug) { + printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu notarypay.%llu\n", i, (long long)ASSETCHAINS_ENDSUBSIDY[i], (long long)ASSETCHAINS_REWARD[i], (long long)ASSETCHAINS_HALVING[i], (long long)ASSETCHAINS_DECAY[i], (long long)ASSETCHAINS_NOTARY_PAY[i]); + } - // TODO: Verify that we don't overrun extrabuf here, which is a 256 byte buffer + // TODO: Verify that we don't overrun extrabuf here, which is a 32KB byte buffer extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY[i]),(void *)&ASSETCHAINS_ENDSUBSIDY[i]); extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD[i]),(void *)&ASSETCHAINS_REWARD[i]); extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING[i]),(void *)&ASSETCHAINS_HALVING[i]); @@ -2205,6 +2205,7 @@ void hush_args(char *argv0) extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(tmp),(void *)&tmp); if ( ASSETCHAINS_FOUNDERS > 1 ) extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); + // NOTE: Hush does not use this, we use -ac_script to implement our FR -- Duke if ( ASSETCHAINS_FOUNDERS_REWARD != 0 ) { fprintf(stderr, "set founders reward.%lld\n",(long long)ASSETCHAINS_FOUNDERS_REWARD); @@ -2232,9 +2233,10 @@ void hush_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; -fprintf(stderr,"extralen.%d before disable bits\n",extralen); - if ( nonz > 0 ) - { + + fprintf(stderr,"extralen.%d before disable bits\n",extralen); + + if ( nonz > 0 ) { memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); extralen += sizeof(disablebits); } @@ -2247,8 +2249,12 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } fprintf(stderr," <- CCLIB name\n"); } - if ( ASSETCHAINS_BLOCKTIME != 60 ) + // is this not being run correctly? + if ( ASSETCHAINS_BLOCKTIME != 60 ) { extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_BLOCKTIME),(void *)&ASSETCHAINS_BLOCKTIME); + fprintf(stderr,"%s: ASSETCHAINS_BLOCKTIME=%d, extralen=%d\n", __func__, ASSETCHAINS_BLOCKTIME, extralen); + } + if ( Mineropret.size() != 0 ) { for (i=0; i= 0 && baseid < 32 ) { //komodo_maxallowed(baseid); - printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); + if(fDebug) + printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); } if ( ASSETCHAINS_CC >= HUSH_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; if ( KOMODO_BIT63SET(MAX_MONEY) != 0 ) MAX_MONEY = KOMODO_MAXNVALUE; - fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); + if(fDebug) + fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(SMART_CHAIN_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) != 0 ) { ASSETCHAINS_P2PPORT = GetArg("-port",0); + if(fDebug) fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; @@ -2343,8 +2352,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); extern int COINBASE_MATURITY; if ( strcmp(SMART_CHAIN_SYMBOL,"KMD") == 0 ) { - fprintf(stderr,"cant have assetchain named KMD\n"); - StartShutdown(); + fprintf(stderr,"Oh hellz yezzz\n"); } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,SMART_CHAIN_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; @@ -2371,6 +2379,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); magicstr[8] = 0; #ifndef FROM_CLI sprintf(fname,"%s_7776",SMART_CHAIN_SYMBOL); + // TODO: why are we doing this again? Most users do not need this if ( (fp= fopen(fname,"wb")) != 0 ) { int8_t notarypay = 0; @@ -2394,9 +2403,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); fprintf(stderr,"smart utxo CC contract %d will activate at height.%d\n",(int32_t)ccEnablesHeight[0],(int32_t)ccEnablesHeight[1]); } } - } - else - { + } else { char fname[512],username[512],password[4096]; int32_t iter; FILE *fp; ASSETCHAINS_P2PPORT = 7770; ASSETCHAINS_RPCPORT = 7771; @@ -2439,75 +2446,20 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",SMART_CHAIN_SYMBOL,BITCOIND_RPCPORT); - // Set cc enables for all existing ac_cc chains here. - if ( strcmp("AXO",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("CCL",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - CCENABLE(EVAL_TOKENS); - CCENABLE(EVAL_HEIR); - } - if ( strcmp("COQUI",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_DICE); - CCENABLE(EVAL_CHANNELS); - CCENABLE(EVAL_ORACLES); - CCENABLE(EVAL_ASSETS); - CCENABLE(EVAL_TOKENS); - } - if ( strcmp("DION",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - - if ( strcmp("EQL",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("ILN",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("OUR",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("ZEXO",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("SEC",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_ASSETS); - CCENABLE(EVAL_TOKENS); - CCENABLE(EVAL_ORACLES); - } - if ( strcmp("KMDICE",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_FAUCET); - CCENABLE(EVAL_DICE); - CCENABLE(EVAL_ORACLES); + // Set custom cc rulse for chains here + if ( strcmp("HUSH3",SMART_CHAIN_SYMBOL) == 0 ) { + // Disable all CC's + if(GetArg("-ac_disable_cc",false)) { + CCDISABLEALL; + } } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); HUSH_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); - if ( SMART_CHAIN_SYMBOL[0] == 0 || strcmp(SMART_CHAIN_SYMBOL,"SUPERNET") == 0 || strcmp(SMART_CHAIN_SYMBOL,"DEX") == 0 || strcmp(SMART_CHAIN_SYMBOL,"COQUI") == 0 || strcmp(SMART_CHAIN_SYMBOL,"PIRATE") == 0 || strcmp(SMART_CHAIN_SYMBOL,"KMDICE") == 0 ) + if ( strcmp(SMART_CHAIN_SYMBOL,"CA333LIES") == 0 ) HUSH_EXTRASATOSHI = 1; } -void komodo_nameset(char *symbol,char *dest,char *source) +void hush_nameset(char *symbol,char *dest,char *source) { if ( source[0] == 0 ) { strcpy(symbol,(char *)"HUSH3"); @@ -2521,7 +2473,7 @@ void komodo_nameset(char *symbol,char *dest,char *source) struct hush_state *hush_stateptrget(char *base) { int32_t baseid; - if ( base == 0 || base[0] == 0 || strcmp(base,(char *)"KMD") == 0 ) + if ( base == 0 || base[0] == 0 || strcmp(base,(char *)"KYCSELLOUTS") == 0 ) return(&KOMODO_STATES[33]); else if ( (baseid= komodo_baseid(base)) >= 0 ) return(&KOMODO_STATES[baseid+1]); @@ -2531,7 +2483,7 @@ struct hush_state *hush_stateptrget(char *base) struct hush_state *hush_stateptr(char *symbol,char *dest) { int32_t baseid; - komodo_nameset(symbol,dest,SMART_CHAIN_SYMBOL); + hush_nameset(symbol,dest,SMART_CHAIN_SYMBOL); return(hush_stateptrget(symbol)); }