diff --git a/.gitignore b/.gitignore index d139071e0..a4396df73 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ src/cc/rogue/rogue src/cc/rogue/rogue.so src/cc/rogue/test.zip +src/cc/dapps/a.out src/checkfile src/foo.zip @@ -145,8 +146,6 @@ src/rogue.530623577502174316.pack src/rogue.530623577502174316.player -src/cc/rogue/config.h - src/cc/rogue/config.h src/ROGUE.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a7354b240..2a06081f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,7 @@ build:ubuntu: - mkdir ${PACKAGE_DIR_LINUX} - cp src/komodod src/komodo-cli + zcutil/fetch-params.sh ${PACKAGE_DIR_LINUX} - chmod +x ${PACKAGE_DIR_LINUX}/komodod - chmod +x ${PACKAGE_DIR_LINUX}/komodo-cli @@ -71,10 +72,8 @@ build:windows: - cp src/komodod.exe src/komodo-cli.exe src/komodo-tx.exe - src/cc/rogue/rogue.exe + zcutil/wget64.exe zcutil/fetch-params.bat - src/cc/rogue/x86_64-w64-mingw32/bin/libcurl-4.dll - src/cc/rogue/x86_64-w64-mingw32/bin/libncursesw6.dll ${PACKAGE_DIR_WINDOWS} - zip -r ${PACKAGE_DIR_WINDOWS}.zip ${PACKAGE_DIR_WINDOWS} - md5sum ${AGAMA_ARTIFACTS_WINDOWS} > ${AGAMA_ARTIFACTS_WINDOWS_CHECKSUM} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..b7ff449d6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,62 @@ + +# Komodo Core (komodod) Software Contribution Guidelines + +Thank you for reaching out and trying to make Komodo an even better software application and blockchain platform. These contribution guidelines shall help you figuring out where you can be helpful and how to easily get started. + +## Table of Contents + +0. [Types of contributions we're looking for](#types-of-contributions-were-looking-for) +0. [Ground rules & expectations](#ground-rules--expectations) +0. [How to contribute](#how-to-contribute) +0. [Style guide](#style-guide) +0. [Setting up your environment](#setting-up-your-environment) +0. [Contribution review process](#contribution-review-process) +0. [Community](#community) + +## Types of contributions we're looking for +There are many ways you can directly contribute to Komodo: + +* Debug and test the Komodo Core code +* Find and fix bugs +* Improve suboptimal code +* Extend our software +* Perform a secure code review of Komodo Core and other Komodo-related software + +Interested in making a contribution? Read on! + +## Ground rules & expectations + +Before we get started, here are a few things we expect from you (and that you should expect from others): + +* Be kind and thoughtful in your conversations around this project. We all come from different backgrounds and projects, which means we likely have different perspectives on "how open source is done." Try to listen to others rather than convince them that your way is correct. +* Open Source Guides are released with a [Contributor Code of Conduct](./code_of_conduct.md). By participating in this project, you agree to abide by its terms. +* If you open a pull request, please ensure that your contribution passes all tests. If there are test failures, you will need to address them before we can merge your contribution. +* When adding content, please consider if it is widely valuable. Please don't add references or links to things you or your employer have created as others will do so if they appreciate it. + +## How to contribute + +If you'd like to contribute, start by searching through the [issues](https://github.com/komodoplatform/komodo/issues) and [pull requests](https://github.com/komodoplatform/komodo/pulls) to see whether someone else has raised a similar idea or question. + +If you don't see your idea listed, and you think it can contribute to Komodo, do one of the following: +* **If your contribution is minor,** such as a fixing a typo, open a pull request. +* **If your contribution is major,** such as a new feature or bugfix, start by opening an issue first. That way, other contributors can weigh in on the discussion before you do any work. + +## Style guide +Write clear, clean and consistent code. Follow well-known and established style guidelines like [Google's C++ Style Guide](https://google.github.io/styleguide/cppguide.html) or [Bjarne Stroustrup's C++ Style FAQ](http://www.stroustrup.com/bs_faq2.html). + +## Setting up your environment + +The Komodo Core (komodod) is mainly written in C++ with specific modules written in C. Follow the [Getting Started](https://github.com/komodoplatform/komodo#getting-started) instructions to build komodod from sources. For more informations about the Komodo Platform and a full API documentation please visit the official [Komodo developer documentation](https://docs.komodoplatform.com/). + +## Contribution review process + +Our team and community will review your contribution and start a transparent testing and quality assurance process. As soon as your contribution has undergone sucessful review and QA signoff it gets merged into the Komodo sourcecode. + +## Community + +Discussions about Komodo's development take place on our [discord server](https://discord.gg/yhfzqsg). Anybody is welcome to join these conversations. There is also a [newsletter](http://komodoplatform.com) with regular updates. + +Wherever possible, do not take these conversations to private channels, including contacting the maintainers directly. Keeping communication public means everybody can benefit and learn from the conversation. + + +This contribution guideline is adapted from the Open Source Guides. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..6bcbe7706 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,30 @@ +## Reporting a Vulnerability + +Please use the below [contact data](https://komodoplatform.com/.well-known/security.txt.asc) to report vulnerabilities. We kindly ask you to not publish or exploit any found vulnerabilities. + +``` +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +Contact: security@komodoplatform.com +Contact: ca333@komodoplatform.com +Contact: noashh@komodoplatform.com +Encryption: http://pgp.key-server.io:11371/0x379287998EE6CF47 +-----BEGIN PGP SIGNATURE----- + +iQJNBAEBCAA3FiEEVez5U2AlPa805zvqN5KHmY7mz0cFAlz6EuMZHGNhMzMzQGtv +bW9kb3BsYXRmb3JtLmNvbQAKCRA3koeZjubPR8cIEACP+JjyXDIzjgIewMMi/02b +tsYswPyQ+9bAoEJnis3r94d1FP1rqXmt4oNz6VwFTqQLEa5opW+gvvaxBTFJSPb0 +UzbS+1PjfAOox5cnT3Dnv9kcy4ECslnW/G+mH+85BUgz1HuqYc8A3kNQJL7KqLoi +YeD0Hd09KtlG+B4PWdnqLw/uvfbavSKdMn6WSIU6adNZWX0ewSubWPXvrWea5cI2 +yKDdMcDqB8Sc9J4JR2L9zW8NqPQuaxfLQbkCt2tg9QjlClrAqQgb8OZQJgY9f1T/ +kBlVXoA4ZUZeifvjSKxQ/3TdRFP+jbV9xsb6sr14zTx+Wcoqtgsh3l9F4+T3V2m8 +/c/iS4mFlK31pJtwYyrJAq9hpggqymdCVi0Pa3yLZsEj3orBPaPWbmq2v7xeF3J8 +y8vqAkt3M3T6251aZAKEcaN5RXYJW70CTseadwp0tmrAL2nIVmziNCMOF+Bufyxi +HddkasTcNX8VYfPCLWqBwrocx8d3n3E7dBGeS2x2iwuRVQ85pH5d+imxaMftcbqm +YrNuiqcI/0XDGk9pS6f1gpu5Eh5Q2QXGmOoRlfosfkAEfgFxfaMvmcu5Ay1s0gSR +MsTn0PrQyMYC3t3KpyP47C8ui9x7FtJFltR/QT4yzBF1QyDmINnK86ldQqSui402 +2+gQFt7YFvLIBUiy1fh1Jw== +=UITq +-----END PGP SIGNATURE----- +``` diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index d01e8b5a3..7be744aeb 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -1,9 +1,9 @@ -OSX_MIN_VERSION=10.8 -OSX_SDK_VERSION=10.11 +OSX_MIN_VERSION=10.12 +OSX_SDK_VERSION=10.12 OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk LD64_VERSION=253.9 -darwin_CC=gcc-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CC=gcc-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CXX=g++-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3681cf2f3..1d8cf669e 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -59,6 +59,8 @@ one other technical note is that komodod has the insight-explorer extensions bui #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define CCDISABLEALL memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)) +#define CCENABLE(x) ASSETCHAINS_CCDISABLES[((uint8_t)x)] = 0 #ifndef _BITS256 #define _BITS256 diff --git a/src/cc/Makefile_custom b/src/cc/Makefile_custom new file mode 100755 index 000000000..79219ec96 --- /dev/null +++ b/src/cc/Makefile_custom @@ -0,0 +1,38 @@ +SHELL = /bin/sh +CC = gcc +CC_DARWIN = g++-8 +CC_WIN = x86_64-w64-mingw32-gcc-posix +CFLAGS_DARWIN = -DBUILD_CUSTOMCC -std=c++11 -arch x86_64 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib +CFLAGS = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -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 +CFLAGS_WIN = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/x86_64-w64-mingw32/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program +$(info $(OS)) +OS := $(shell uname -s) +$(info $(OS)) +TARGET = customcc.so +TARGET_DARWIN = customcc.dylib +TARGET_WIN = customcc.dll +SOURCES = cclib.cpp +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ + +all: $(TARGET) + +$(TARGET): $(SOURCES) + $(info Building cclib to src/) +ifeq ($(OS),Darwin) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) -c $(SOURCES) + cp $(TARGET_DARWIN) ../libcc.dylib +else ifeq ($(HOST),x86_64-w64-mingw32) + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) -c $(SOURCES) + cp $(TARGET_WIN) ../libcc.dll +#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host +else + $(info LINUX) + $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES) + cp $(TARGET) ../libcc.so +endif + +clean: + rm -rf $(TARGET) diff --git a/src/cc/Makefile_rogue b/src/cc/Makefile_rogue index baf8767aa..3b2f65e00 100644 --- a/src/cc/Makefile_rogue +++ b/src/cc/Makefile_rogue @@ -1,6 +1,6 @@ SHELL = /bin/sh CC = gcc -CC_DARWIN = g++-6 +CC_DARWIN = g++-8 CC_WIN = x86_64-w64-mingw32-gcc-posix CFLAGS_DARWIN = -DBUILD_ROGUE -std=c++11 -arch x86_64 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib CFLAGS = -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 @@ -14,7 +14,7 @@ TARGET = librogue.so TARGET_DARWIN = librogue.dylib TARGET_WIN = librogue.dll SOURCES = cclib.cpp -#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ all: $(TARGET) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 33d776650..ea8085822 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -315,6 +315,8 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char { long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; sprintf(fname,"/tmp/zmigrate.%s",method); + //if ( (acname == 0 || acname[0] == 0) && strcmp(refcoin,"KMD") != 0 ) + // acname = refcoin; if ( acname[0] != 0 ) { if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) @@ -938,7 +940,505 @@ int32_t have_pending_opid(char *coinstr,int32_t clearresults) return(pending); } +int64_t utxo_value(char *refcoin,char *srcaddr,bits256 txid,int32_t v) +{ + cJSON *txjson,*vouts,*vout,*sobj,*array; int32_t numvouts,numaddrs; int64_t val,value = 0; char *addr,str[65]; + srcaddr[0] = 0; + if ( (txjson= get_rawtransaction(refcoin,"",txid)) != 0 ) + { + if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && v < numvouts ) + { + vout = jitem(vouts,v); + if ( (val= jdouble(vout,"value")*SATOSHIDEN) != 0 && (sobj= jobj(vout,"scriptPubKey")) != 0 ) + { + if ( (array= jarray(&numaddrs,sobj,"addresses")) != 0 && numaddrs == 1 && (addr= jstri(array,0)) != 0 && strlen(addr) < 64 ) + { + strcpy(srcaddr,addr); + value = val; + } else printf("couldnt get unique address for %s/%d\n",bits256_str(str,txid),v); + } else printf("error getting value for %s/v%d\n",bits256_str(str,txid),v); + } + } + return(value); +} + +int32_t verify_vin(char *refcoin,bits256 txid,int32_t v,char *cmpaddr) +{ + cJSON *txjson,*vins,*vin; int32_t numvins; char vinaddr[64],str[65]; + vinaddr[0] = 0; + if ( (txjson= get_rawtransaction(refcoin,"",txid)) != 0 ) + { + if ( (vins= jarray(&numvins,txjson,"vin")) != 0 && v < numvins ) + { + vin = jitem(vins,v); + if ( utxo_value(refcoin,vinaddr,jbits256(vin,"txid"),jint(vin,"vout")) > 0 && strcmp(vinaddr,cmpaddr) == 0 ) + return(0); + printf("mismatched vinaddr.(%s) vs %s\n",vinaddr,cmpaddr); + } + } + return(-1); +} + +int32_t txid_in_vins(char *refcoin,bits256 txid,bits256 cmptxid) +{ + cJSON *txjson,*vins,*vin; int32_t numvins,v,vinvout; bits256 vintxid; char str[65]; + if ( (txjson= get_rawtransaction(refcoin,"",txid)) != 0 ) + { + if ( (vins= jarray(&numvins,txjson,"vin")) != 0 ) + { + for (v=0; vrefundvalue < 0 ) + return(-1); + sprintf(url,"https://kmd.explorer.dexstats.info/insight-api-komodo/addr/%s",item->destaddr); + if ( (retstr= send_curl(url,"/tmp/itemvalid")) != 0 ) + { + if ( (curljson= cJSON_Parse(retstr)) != 0 ) + { + if ( (txids= jarray(&numtxids,curljson,"transactions")) != 0 ) + { + for (i=0; itxid) == 0 ) + { + printf("found item->txid %s inside %s\n",bits256_str(str,item->txid),bits256_str(str2,txid)); + item->approved = 1; + break; + } + } + } + free_json(curljson); + } + //printf("%s\n",retstr); + free(retstr); + } + if ( item->approved != 0 ) + return(1); + *waitingp = item->refundvalue; + return(-1); +} + +void scan_claims(int32_t issueflag,char *refcoin,int32_t batchid) +{ + char str[65]; int32_t i,num,numstolen=0,numcandidates=0,numinvalids=0,numrefunded=0,numwaiting=0; struct claimitem *item; int64_t batchmin,batchmax,waiting,refunded,possiblerefund=0,possiblestolen = 0,invalidsum=0,totalrefunded=0,waitingsum=0; + if ( batchid == 0 ) + { + batchmin = 0; + batchmax = 7 * SATOSHIDEN; + } + else if ( batchid == 1 ) + { + batchmin = 7 * SATOSHIDEN; + batchmax = 777 * SATOSHIDEN; + } + else if ( batchid == 2 ) + { + batchmin = 1;//777 * SATOSHIDEN; + batchmax = 77777 * SATOSHIDEN; + } + else if ( batchid == 3 ) + { + batchmin = 77777 * SATOSHIDEN; + batchmax = 1000000 * SATOSHIDEN; + } + for (i=0; irefundvalue < batchmin || item->refundvalue >= batchmax ) + continue; + if ( itemvalid(refcoin,&refunded,&waiting,item) < 0 ) + { + if ( refunded != 0 ) + { + numrefunded++; + totalrefunded += refunded; + } + else if ( waiting != 0 ) + { + numwaiting++; + waitingsum += waiting; + } + else + { + invalidsum += item->refundvalue; + numinvalids++; + } + continue; + } + if ( item->total > item->refundvalue*1.1 + 10*SATOSHIDEN ) + { + printf("possible.%d stolen %s %.8f vs refund %.8f -> %.8f\n",batchid,item->oldaddr,dstr(item->total),dstr(item->refundvalue),dstr(item->total)-dstr(item->refundvalue)); + numstolen++; + possiblestolen += (item->total - item->refundvalue); + item->approved = 0; + } + else + { + printf("candidate.%d %s %.8f vs refund %.8f -> %s\n",batchid,item->oldaddr,dstr(item->total),dstr(item->refundvalue),item->destaddr); + numcandidates++; + possiblerefund += item->refundvalue; + } + } + printf("batchid.%d TOTAL exposure %d %.8f, possible refund %d %.8f, invalids %d %.8f, numrefunded %d %.8f, waiting %d %.8f\n",batchid,numstolen,dstr(possiblestolen),numcandidates,dstr(possiblerefund),numinvalids,dstr(invalidsum),numrefunded,dstr(totalrefunded),numwaiting,dstr(waitingsum)); + for (i=num=0; iapproved != 0 ) + { + printf("%d.%d: approved.%d %s %.8f vs refund %.8f -> %s\n",i,num,batchid,item->oldaddr,dstr(item->total),dstr(item->refundvalue),item->destaddr); + num++; + if ( issueflag != 0 ) + { + static FILE *fp; char cmd[1024]; + if ( fp == 0 ) + fp = fopen("refund.log","wb"); + genrefund(cmd,refcoin,item->txid,item->destaddr,item->refundvalue); + if ( fp != 0 ) + { + fprintf(fp,"%s,%s,%s,%s,%s,%.8f,%s\n",item->username,refcoin,bits256_str(str,item->txid),item->oldaddr,item->destaddr,dstr(item->refundvalue),cmd); + fflush(fp); + } + memset(&SECONDVIN,0,sizeof(SECONDVIN)); + SECONDVOUT = 1; +//printf(">>>>>>>>>>>>>>>>>> getchar after (%s)\n",cmd); +//getchar(); + } + } + } +} + +int32_t update_claimvalue(int32_t *disputedp,char *addr,int64_t amount,bits256 txid) +{ + int32_t i; struct claimitem *item; + *disputedp = 0; + for (i=0; irefundvalue = amount; + if ( bits256_nonz(item->txid) != 0 ) + printf("disputed.%d %s claimed %.8f vs %.8f\n",item->disputed,addr,dstr(item->total),dstr(amount)); + item->txid = txid; + if ( item->disputed != 0 ) + *disputedp = 1; + return(i); + } + } + return(-1); +} + +int64_t update_claimstats(char *username,char *oldaddr,char *destaddr,int64_t amount) +{ + int32_t i; struct claimitem *item; + for (i=0; idestaddr) != 0 )//|| strcmp(username,item->username) != 0 ) + { + item->disputed++; + printf("disputed.%d claim.%-4d: (%36s -> %36s %s) vs. (%36s -> %36s %s) \n",item->disputed,i,oldaddr,destaddr,username,item->oldaddr,item->destaddr,item->username); + } + item->numutxos++; + item->total += amount; + return(amount); + } + } + item = &CLAIMS[NUM_CLAIMS++]; + item->total = amount; + item->numutxos = 1; + strncpy(item->oldaddr,oldaddr,sizeof(item->oldaddr)); + strncpy(item->destaddr,destaddr,sizeof(item->destaddr)); + strncpy(item->username,username,sizeof(item->username)); + printf("new claim.%-4d: %36s %16.8f -> %36s %s\n",NUM_CLAIMS,oldaddr,dstr(amount),destaddr,username); + return(amount); +} + +int32_t update_addrstats(char *srcaddr,int64_t amount) +{ + int32_t i; struct addritem *item; + for (i=0; itotal = amount; + item->numutxos = 1; + strcpy(item->addr,srcaddr); + printf("%d new address %s\n",NUM_ADDRESSES,srcaddr); + return(-1); +} + +int64_t sum_of_vins(char *refcoin,int32_t *totalvinsp,int32_t *uniqaddrsp,bits256 txid) +{ + cJSON *txjson,*vins,*vin; char str[65],srcaddr[64]; int32_t i,numarray; int64_t amount,total = 0; + if ( (txjson= get_rawtransaction(refcoin,"",txid)) != 0 ) + { + if ( (vins= jarray(&numarray,txjson,"vin")) != 0) + { + for (i=0; i 0 ) + { + //printf("%d.(%s)\n",numlines,buf); + str = buf; + n = i = 0; + memset(fields,0,sizeof(fields)); + while ( *str != 0 ) + { + if ( *str == ',' || *str == '\n' || *str == '\r' ) + { + fields[n][i] = 0; + i = 0; + if ( n > 1 ) + { + //printf("(%16s) ",fields[n]); + } + n++; + if ( *str == '\n' || *str == '\r' ) + break; + } + if ( *str == ',' || *str == ' ' ) + str++; + else fields[n][i++] = *str++; + } + //printf("%s\n",fields[0]); + total += update_claimstats(fields[1],fields[3],fields[6],atof(fields[4])*SATOSHIDEN + 0.0000000049); + numlines++; + } + fclose(fp); + } + printf("total claims %.8f\n",dstr(total)); +} + int32_t main(int32_t argc,char **argv) +{ + char *coinstr,*acstr,*addr,buf[64],srcaddr[64],str[65]; cJSON *retjson,*item; int32_t i,n,disputed,numdisputed,numsmall=0,numpayouts=0,numclaims=0,num=0,totalvins=0,uniqaddrs=0; int64_t amount,total = 0,total2 = 0,payout,maxpayout,smallpayout=0,totalpayout = 0,totaldisputed = 0,totaldisputed2 = 0,fundingamount = 0; + if ( argc != 2 ) + { + printf("argc needs to be 2: coin\n"); + return(-1); + } + if ( strcmp(argv[1],"KMD") == 0 ) + { + REFCOIN_CLI = "./komodo-cli"; + coinstr = clonestr("KMD"); + acstr = ""; + } + else if ( strcmp(argv[1],"CHIPS") == 0 ) + { + REFCOIN_CLI = "./chips-cli"; + coinstr = clonestr("CHIPS"); + acstr = ""; + } + else + { + sprintf(buf,"./komodo-cli -ac_name=%s",argv[1]); + REFCOIN_CLI = clonestr(buf); + coinstr = clonestr(argv[1]); + acstr = coinstr; + } + if ( 1 )//strcmp(coinstr,"KMD") == 0 ) + { + sprintf(buf,"%s-Claims.csv",coinstr); + reconcile_claims(buf); + for (i=0; i 0 ) + { + for (i=0; i fundingamount ) + { + fundingamount = amount; + SECONDVIN = jbits256(item,"txid"); + SECONDVOUT = jint(item,"vout"); + printf("set SECONDVIN to %s/v%d %.8f\n",bits256_str(str,SECONDVIN),SECONDVOUT,dstr(amount)); + } + continue; + } + if ( strcmp(coinstr,"KMD") == 0 && verify_vin(coinstr,jbits256(item,"txid"),0,"R9JCEd6xnCxNUSpLrHEWvzPSh7CNXm7z75") < 0 ) + { + printf("WARNING: imposter dust detected! %s\n",bits256_str(str,jbits256(item,"txid"))); + continue; + } + else if ( strcmp(coinstr,"KMD") != 0 && verify_vin(coinstr,jbits256(item,"txid"),0,"R9MUnxXijovvSeT9sFuUX23TiFtVvZEGjT") < 0 ) + { + printf("WARNING: imposter dust detected! %s\n",bits256_str(str,jbits256(item,"txid"))); + continue; + } + amount = (utxo_value(coinstr,srcaddr,jbits256(item,"txid"),0) - 20000) * SATOSHIDEN; + //printf("%d: %s claimvalue %.8f\n",num,srcaddr,dstr(amount)); + num++; + total2 += amount; + if ( update_claimvalue(&disputed,srcaddr,amount,jbits256(item,"txid")) >= 0 ) + { + if ( disputed != 0 ) + { + totaldisputed2 += amount; + numdisputed++; + } + else + { + numclaims++; + total += amount; + } + } + } + } + } + free_json(retjson); + printf("remaining refunds.%d %.8f, numclaims.%d %.8f, numdisputed.%d %.8f\n",num,dstr(total2),numclaims,dstr(total),numdisputed,dstr(totaldisputed2)); + } + //scan_claims(0,coinstr,0); + //scan_claims(0,coinstr,1); + scan_claims(0,coinstr,2); + //scan_claims(0,coinstr,3); + } + else if ( (retjson= get_listunspent(coinstr,acstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(retjson)) > 0 ) + { + for (i=0; i= SATOSHIDEN ) + { + payout = ADDRESSES[i].total / SATOSHIDEN; + if ( payout > maxpayout ) + maxpayout = payout; + totalpayout += payout; + numpayouts++; + //if ( payout >= 7 ) + //{ + // numsmall++; + //smallpayout += payout; + genpayout(coinstr,ADDRESSES[i].addr,payout); + //} + //printf("%-4d: %-64s numutxos.%-4lld %llu\n",i,ADDRESSES[i].addr,ADDRESSES[i].numutxos,(long long)payout); + } + } + printf("num.%d total %.8f vs vintotal %.8f, totalvins.%d uniqaddrs.%d:%d totalpayout %llu maxpayout %llu numpayouts.%d numsmall.%d %llu\n",num,dstr(total),dstr(total2),totalvins,uniqaddrs,NUM_ADDRESSES,(long long)totalpayout,(long long)maxpayout,numpayouts,numsmall,(long long)smallpayout); + } +} + +int32_t zmigratemain(int32_t argc,char **argv) { char buf[1024],*zsaddr,*coinstr; if ( argc != 3 ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index a23a7b16c..c580753cf 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -78,8 +78,13 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) uint8_t ecode = cond->code[0]; if ( ASSETCHAINS_CCDISABLES[ecode] != 0 ) { - fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); - return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + // check if a height activation has been set. + if ( mapHeightEvalActivate[ecode] == 0 || this->GetCurrentHeight() == 0 || mapHeightEvalActivate[ecode] > this->GetCurrentHeight() ) + { + fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); + fprintf(stderr, "ac_ccactivateht: evalcode.%i activates at height.%i vs current height.%i\n", ecode, mapHeightEvalActivate[ecode], this->GetCurrentHeight()); + return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + } } std::vector vparams(cond->code+1, cond->code+cond->codeLength); if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) diff --git a/src/cc/makecclib b/src/cc/makecclib index 5241ea675..e4816c55c 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,8 +7,6 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -#exit 0 - echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/cc/makecustom b/src/cc/makecustom index 154be4f31..7f1c789c9 100755 --- a/src/cc/makecustom +++ b/src/cc/makecustom @@ -1,6 +1,7 @@ #!/bin/sh -gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp -cp customcc.so ../libcc.so -cd .. -make -cd cc +if make -f Makefile_custom "$@"; then + echo CUSTOMCC BUILD SUCCESSFUL +else + echo CUSTOMCC BUILD FAILED + exit 1 +fi diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index f019ae271..193f66a1a 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -642,11 +642,7 @@ int32_t GetLatestTimestamp(int32_t height) blockHash = chainActive[height]->GetBlockHash(); pindex = mapBlockIndex[blockHash]; - if ( komodo_blockload(block,pindex) == 0 ) - { - return(block.nTime); - } - return(0); + return(pindex->nTime); } bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) @@ -1208,4 +1204,3 @@ UniValue OraclesList() } return(result); } - diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cf15f0b19..7be46f613 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -179,7 +179,70 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }, { - {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" } + {"madmax_NA", "0237e0d3268cebfa235958808db1efc20cc43b31100813b1f3e15cc5aa647ad2c3" }, // 0 + {"alright_AR", "020566fe2fb3874258b2d3cf1809a5d650e0edc7ba746fa5eec72750c5188c9cc9" }, + {"strob_NA", "0206f7a2e972d9dfef1c424c731503a0a27de1ba7a15a91a362dc7ec0d0fb47685" }, + {"dwy_EU", "021c7cf1f10c4dc39d13451123707ab780a741feedab6ac449766affe37515a29e" }, + {"phm87_SH", "021773a38db1bc3ede7f28142f901a161c7b7737875edbb40082a201c55dcf0add" }, + {"chainmakers_NA", "02285d813c30c0bf7eefdab1ff0a8ad08a07a0d26d8b95b3943ce814ac8e24d885" }, + {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, + {"blackjok3r_SH", "021eac26dbad256cbb6f74d41b10763183ee07fb609dbd03480dd50634170547cc" }, + {"chainmakers_EU", "03fdf5a3fce8db7dee89724e706059c32e5aa3f233a6b6cc256fea337f05e3dbf7" }, + {"titomane_AR", "023e3aa9834c46971ff3e7cb86a200ec9c8074a9566a3ea85d400d5739662ee989" }, + {"fullmoon_SH", "023b7252968ea8a955cd63b9e57dee45a74f2d7ba23b4e0595572138ad1fb42d21" }, // 10 + {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, + {"chmex_EU", "0281304ebbcc39e4f09fda85f4232dd8dacd668e20e5fc11fba6b985186c90086e" }, + {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309" }, + {"ca333_DEV", "02856843af2d9457b5b1c907068bef6077ea0904cc8bd4df1ced013f64bf267958" }, + {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18" }, + {"pungocloud_SH", "024dfc76fa1f19b892be9d06e985d0c411e60dbbeb36bd100af9892a39555018f6" }, + {"voskcoin_EU", "034190b1c062a04124ad15b0fa56dfdf34aa06c164c7163b6aec0d654e5f118afb" }, + {"decker_DEV", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707" }, + {"cryptoeconomy_EU", "0290ab4937e85246e048552df3e9a66cba2c1602db76e03763e16c671e750145d1" }, + {"etszombi_EU", "0293ea48d8841af7a419a24d9da11c34b39127ef041f847651bae6ab14dcd1f6b4" }, // 20 + {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, + {"pirate_AR", "03e29c90354815a750db8ea9cb3c1b9550911bb205f83d0355a061ac47c4cf2fde" }, + {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, + {"zatjum_SH", "02d6b0c89cacd58a0af038139a9a90c9e02cd1e33803a1f15fceabea1f7e9c263a" }, + {"madmax_AR", "03c5941fe49d673c094bc8e9bb1a95766b4670c88be76d576e915daf2c30a454d3" }, + {"lukechilds_NA", "03f1051e62c2d280212481c62fe52aab0a5b23c95de5b8e9ad5f80d8af4277a64b" }, + {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8" }, + {"tonyl_AR", "02cc8bc862f2b65ad4f99d5f68d3011c138bf517acdc8d4261166b0be8f64189e1" }, + {"infotech_DEV", "0345ad4ab5254782479f6322c369cec77a7535d2f2162d103d666917d5e4f30c4c" }, + {"fullmoon_NA", "032c716701fe3a6a3f90a97b9d874a9d6eedb066419209eed7060b0cc6b710c60b" }, // 30 + {"etszombi_AR", "02e55e104aa94f70cde68165d7df3e162d4410c76afd4643b161dea044aa6d06ce" }, + {"node-9_EU", "0372e5b51e86e2392bb15039bac0c8f975b852b45028a5e43b324c294e9f12e411" }, + {"phba2061_EU", "03f6bd15dba7e986f0c976ea19d8a9093cb7c989d499f1708a0386c5c5659e6c4e" }, + {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, + {"and1-89_EU", "02736cbf8d7b50835afd50a319f162dd4beffe65f2b1dc6b90e64b32c8e7849ddd" }, + {"komodopioneers_SH", "032a238a5747777da7e819cfa3c859f3677a2daf14e4dce50916fc65d00ad9c52a" }, + {"komodopioneers_EU", "036d02425916444fff8cc7203fcbfc155c956dda5ceb647505836bef59885b6866" }, + {"d0ct0r_NA", "0303725d8525b6f969122faf04152653eb4bf34e10de92182263321769c334bf58" }, + {"kolo_DEV", "02849e12199dcc27ba09c3902686d2ad0adcbfcee9d67520e9abbdda045ba83227" }, + {"peer2cloud_AR", "02acc001fe1fe8fd68685ba26c0bc245924cb592e10cec71e9917df98b0e9d7c37" }, // 40 + {"webworker01_SH", "031e50ba6de3c16f99d414bb89866e578d963a54bde7916c810608966fb5700776" }, + {"webworker01_NA", "032735e9cad1bb00eaababfa6d27864fa4c1db0300c85e01e52176be2ca6a243ce" }, + {"pbca26_NA", "03a97606153d52338bcffd1bf19bb69ef8ce5a7cbdc2dbc3ff4f89d91ea6bbb4dc" }, + {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, + {"pirate_NA", "0255e32d8a56671dee8aa7f717debb00efa7f0086ee802de0692f2d67ee3ee06ee" }, + {"lukechilds_AR", "025c6a73ff6d750b9ddf6755b390948cffdd00f344a639472d398dd5c6b4735d23" }, + {"dragonhound_NA", "0224a9d951d3a06d8e941cc7362b788bb1237bb0d56cc313e797eb027f37c2d375" }, + {"fullmoon_AR", "03da64dd7cd0db4c123c2f79d548a96095a5a103e5b9d956e9832865818ffa7872" }, + {"chainzilla_SH", "0360804b8817fd25ded6e9c0b50e3b0782ac666545b5416644198e18bc3903d9f9" }, + {"titomane_EU", "03772ac0aad6b0e9feec5e591bff5de6775d6132e888633e73d3ba896bdd8e0afb" }, // 50 + {"jeezy_EU", "037f182facbad35684a6e960699f5da4ba89e99f0d0d62a87e8400dd086c8e5dd7" }, + {"titomane_SH", "03850fdddf2413b51790daf51dd30823addb37313c8854b508ea6228205047ef9b" }, + {"alien_AR", "03911a60395801082194b6834244fa78a3c30ff3e888667498e157b4aa80b0a65f" }, + {"pirate_EU", "03fff24efd5648870a23badf46e26510e96d9e79ce281b27cfe963993039dd1351" }, + {"thegaltmines_NA", "02db1a16c7043f45d6033ccfbd0a51c2d789b32db428902f98b9e155cf0d7910ed" }, + {"computergenie_NA", "03a78ae070a5e9e935112cf7ea8293f18950f1011694ea0260799e8762c8a6f0a4" }, + {"nutellalicka_SH", "02f7d90d0510c598ce45915e6372a9cd0ba72664cb65ce231f25d526fc3c5479fc" }, + {"chainstrike_SH", "03b806be3bf7a1f2f6290ec5c1ea7d3ea57774dcfcf2129a82b2569e585100e1cb" }, + {"dwy_SH", "036536d2d52d85f630b68b050f29ea1d7f90f3b42c10f8c5cdf3dbe1359af80aff" }, + {"alien_EU", "03bb749e337b9074465fa28e757b5aa92cb1f0fea1a39589bca91a602834d443cd" }, // 60 + {"gt_AR", "0348430538a4944d3162bb4749d8c5ed51299c2434f3ee69c11a1f7815b3f46135" }, + {"patchkez_SH", "03f45e9beb5c4cd46525db8195eb05c1db84ae7ef3603566b3d775770eba3b96ee" }, + {"decker_AR", "03ffdf1a116300a78729608d9930742cd349f11a9d64fcc336b8f18592dd9c91bc" }, // 63 } }; @@ -240,7 +303,9 @@ extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; +extern std::map mapHeightEvalActivate; void komodo_netevent(std::vector payload); +int32_t getacseason(uint32_t timestamp); #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 @@ -269,6 +334,7 @@ uint32_t komodo_heightstamp(int32_t height); int64_t komodo_pricemult(int32_t ind); int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); +int32_t komodo_currentheight(); #endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7cfe870b4..9a80e5e24 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -627,7 +627,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to const char *banned_txids[] = { - "78cb4e21245c26b015b888b14c4f5096e18137d2741a6de9734d62b07014dfca", //233559 + "78cb4e21245c26b015b888b14c4f5096e18137d2741a6de9734d62b07014dfca", // vout1 only 233559 "00697be658e05561febdee1aafe368b821ca33fbb89b7027365e3d77b5dfede5", //234172 "e909465788b32047c472d73e882d79a92b0d550f90be008f76e1edaee6d742ea", //234187 "f56c6873748a327d0b92b8108f8ec8505a2843a541b1926022883678fb24f9dc", //234188 @@ -645,8 +645,24 @@ const char *banned_txids[] = // all vouts banned "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 + //"43416a0c4da6b1a5c1d375bdbe8f7dc8d44d8f60df593d3376aa8221ec66357e", // vout0 only + //"1eb295ed54c47f35cbccd7e7e40d03041f1853581da6d41102a9d8813782b6cb", + //"db121e4012222adfc841824984a2a90b7e5b018dd71307822537d58160195e43", + //"28f95b8148ac4ae6e09c7380e34422fab41d568a411e53dc94823e36a3d6f386", + //"01d8c839463bda2f2f6400ede4611357913684927a767422a8560ead1b22557c", + //"6e4980a9e1bd669f4df04732dc6f11b7773b6de88d1abcf89a6b9007d72ef9ac", + //"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2", }; +int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts) +{ + if ( k < indallvouts ) + return(vout == 1); + else if ( k == indallvouts || k == indallvouts+1 ) + return(1); + else return(vout == 0); +} + int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) { int32_t i; @@ -691,7 +707,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { for (k=0; k= indallvouts) ) + if ( block.vtx[i].vin[j].prevout.hash == array[k] && komodo_checkvout(block.vtx[i].vin[j].prevout.n,k,indallvouts) != 0 ) //(block.vtx[i].vin[j].prevout.n == 1 || k >= indallvouts) ) { printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j); return(-1); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 099cddd4b..d8e292431 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -29,6 +29,7 @@ uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); +int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts); pthread_mutex_t komodo_mutex,staked_mutex; @@ -114,6 +115,8 @@ int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; CScript KOMODO_EARLYTXID_SCRIPTPUB; int32_t ASSETCHAINS_EARLYTXIDCONTRACT; +std::map mapHeightEvalActivate; + struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e2c7dfb4c..028bc4dc2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -65,7 +65,6 @@ const char *Notaries_genesis[][2] = int32_t getkmdseason(int32_t height) { - int8_t season = 0; if ( height <= KMD_SEASON_HEIGHTS[0] ) return(1); for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) @@ -76,9 +75,8 @@ int32_t getkmdseason(int32_t height) return(0); }; -int32_t getacseason(int32_t timestamp) +int32_t getacseason(uint32_t timestamp) { - int8_t season = 0; if ( timestamp <= KMD_SEASON_TIMESTAMPS[0] ) return(1); for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 11cbea808..ecf5237e6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -14,6 +14,7 @@ ******************************************************************************/ #include "komodo_defs.h" #include "key_io.h" +#include "cc/CCinclude.h" #include #ifdef _WIN32 @@ -1665,7 +1666,6 @@ uint64_t komodo_ac_block_subsidy(int nHeight) extern int64_t MAX_MONEY; void komodo_cbopretupdate(int32_t forceflag); -int32_t getacseason(int32_t timestamp); void SplitStr(const std::string& strVal, std::vector &outVals); int8_t equihash_params_possible(uint64_t n, uint64_t k) @@ -1692,7 +1692,7 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) void komodo_args(char *argv0) { - std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; + std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); memset(ccenables,0,sizeof(ccenables)); @@ -1757,6 +1757,27 @@ void komodo_args(char *argv0) ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); KOMODO_SNAPSHOT_INTERVAL = GetArg("-ac_snapshot",0); Split(GetArg("-ac_nk",""), ASSETCHAINS_NK, 0); + + // -ac_ccactivateht=evalcode,height,evalcode,height,evalcode,height.... + Split(GetArg("-ac_ccactivateht",""), ccEnablesHeight, 0); + // fill map with all eval codes and activation height of 0. + for ( int i = 0; i < 256; i++ ) + mapHeightEvalActivate[i] = 0; + for ( int i = 0; i < 512; i++ ) + { + int32_t ecode = ccEnablesHeight[i]; + int32_t ht = ccEnablesHeight[i+1]; + if ( ecode > 256 ) + fprintf(stderr, "ac_ccactivateht: invalid evalcode.%i must be between 0 and 256.\n", ecode); + else if ( ht > 0 ) + { + // update global map. + mapHeightEvalActivate[ecode] = ht; + fprintf(stderr, "ac_ccactivateht: ecode.%i activates at height.%i\n", ecode, mapHeightEvalActivate[ecode]); + } + i++; + } + if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); @@ -2297,6 +2318,68 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_private for a non-PIRATE chain is not supported. The only reason to have an -ac_private chain is for total privacy and that is best achieved with the largest anon set. PIRATE has that and it is recommended to just use PIRATE\n"); StartShutdown(); } + // Set cc enables for all existing ac_cc chains here. + if ( strcmp("AXO",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + if ( strcmp("CCL",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + CCENABLE(EVAL_TOKENS); + CCENABLE(EVAL_HEIR); + } + if ( strcmp("COQUI",ASSETCHAINS_SYMBOL) == 0 ) + { + CCDISABLEALL; + CCENABLE(EVAL_DICE); + CCENABLE(EVAL_CHANNELS); + CCENABLE(EVAL_ORACLES); + CCENABLE(EVAL_ASSETS); + CCENABLE(EVAL_TOKENS); + } + if ( strcmp("DION",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + + if ( strcmp("EQL",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + if ( strcmp("ILN",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + if ( strcmp("OUR",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + if ( strcmp("ZEXO",ASSETCHAINS_SYMBOL) == 0 ) + { + // No CCs used on this chain yet. + CCDISABLEALL; + } + if ( strcmp("SEC",ASSETCHAINS_SYMBOL) == 0 ) + { + CCDISABLEALL; + CCENABLE(EVAL_ASSETS); + CCENABLE(EVAL_TOKENS); + CCENABLE(EVAL_ORACLES); + } + if ( strcmp("KMDICE",ASSETCHAINS_SYMBOL) == 0 ) + { + CCDISABLEALL; + CCENABLE(EVAL_FAUCET); + CCENABLE(EVAL_DICE); + CCENABLE(EVAL_ORACLES); + } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) diff --git a/src/main.cpp b/src/main.cpp index a8ae8b60c..30783e2ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1341,16 +1341,19 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); n = tx.vin.size(); - for (j=0; j= indallvouts) ) + for (k=0; kGetHeight(),j); - return(false); + if ( tx.vin[j].prevout.hash == array[k] && komodo_checkvout(tx.vin[j].prevout.n,k,indallvouts) != 0 ) //(tx.vin[j].prevout.n == 1 || k >= indallvouts) ) + { + static uint32_t counter; + if ( counter++ < 100 ) + printf("MEMPOOL: banned tx.%d being used at ht.%d vout.%d\n",k,(int32_t)chainActive.Tip()->GetHeight(),j); + return(false); + } } } } @@ -1373,8 +1376,6 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState } } -extern int32_t getacseason(int32_t timestamp); - int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime) // from ac_private chains only { int32_t season = getacseason(tiptime); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 76d35ff61..9c55c807b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -51,6 +51,7 @@ using namespace std; extern int32_t KOMODO_INSYNC; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); +int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp); #include "komodo_defs.h" #include "komodo_structs.h" @@ -133,6 +134,9 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) result.push_back(Pair("error", "null blockhash")); return(result); } + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + result.push_back(Pair("last_notarized_height", notarized_height)); result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain @@ -284,6 +288,9 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + result.push_back(Pair("last_notarized_height", notarized_height)); result.push_back(Pair("hash", block.GetHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain @@ -1846,7 +1853,6 @@ UniValue getchaintips(const UniValue& params, bool fHelp) /* Construct the output array. */ UniValue res(UniValue::VARR); const CBlockIndex *forked; - BOOST_FOREACH(const CBlockIndex* block, setTips) BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index c95d7b891..53a744497 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -60,7 +60,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he * or over the difficulty averaging window if 'lookup' is nonpositive. * If 'height' is nonnegative, compute the estimate at the time when a given block was found. */ -int64_t GetNetworkHashPS(int lookup, int height) { +int64_t GetNetworkHashPS(int lookup, int height) +{ CBlockIndex *pb = chainActive.LastTip(); if (height >= 0 && height < chainActive.Height()) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index eca4abb36..95c2cc343 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -78,7 +78,7 @@ int8_t StakedNotaryID(std::string ¬aryname, char *Raddress); uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); -#define KOMODO_VERSION "0.3.3b" +#define KOMODO_VERSION "0.4.0a" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; diff --git a/src/wallet/db.h b/src/wallet/db.h index e1ae52909..8ad246de4 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -33,9 +33,17 @@ #include -// If CCLIB fails to compile with this, use the one below. -#include -//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +#ifdef BUILD_ROGUE + #ifdef __APPLE__ + #include "../depends/x86_64-apple-darwin18.6.0/include/db_cxx.h" + #elif defined(_WIN32) + #include "../depends/x86_64-w64-mingw32/include/db_cxx.h" + #else + #include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" + #endif +#else + #include +#endif extern unsigned int nWalletDBUpdated; diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 1fe9db11a..676239d0b 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -1680,6 +1680,63 @@ TEST(WalletTests, WriteWitnessCache) { wallet.SetBestChain(walletdb, loc); } +TEST(WalletTests, SetBestChainIgnoresTxsWithoutShieldedData) { + SelectParams(CBaseChainParams::REGTEST); + + TestWallet wallet; + MockWalletDB walletdb; + CBlockLocator loc; + + // Set up transparent address + CKey tsk = DecodeSecret(tSecretRegtest); + wallet.AddKey(tsk); + auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID()); + + // Set up a Sprout address + auto sk = libzcash::SproutSpendingKey::random(); + wallet.AddSproutSpendingKey(sk); + + // Generate a transparent transaction that is ours + CMutableTransaction t; + t.vout.resize(1); + t.vout[0].nValue = 90*CENT; + t.vout[0].scriptPubKey = scriptPubKey; + CWalletTx wtxTransparent {nullptr, t}; + wallet.AddToWallet(wtxTransparent, true, NULL); + + // Generate a Sprout transaction that is ours + auto wtxSprout = GetValidReceive(sk, 10, true); + auto noteMap = wallet.FindMySproutNotes(wtxSprout); + wtxSprout.SetSproutNoteData(noteMap); + wallet.AddToWallet(wtxSprout, true, NULL); + + // Generate a Sprout transaction that only involves our transparent address + auto sk2 = libzcash::SproutSpendingKey::random(); + auto wtxInput = GetValidReceive(sk2, 10, true); + auto note = GetNote(sk2, wtxInput, 0, 0); + auto wtxTmp = GetValidSpend(sk2, note, 5); + CMutableTransaction mtx {wtxTmp}; + mtx.vout[0].scriptPubKey = scriptPubKey; + CWalletTx wtxSproutTransparent {NULL, mtx}; + wallet.AddToWallet(wtxSproutTransparent, true, NULL); + + EXPECT_CALL(walletdb, TxnBegin()) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteTx(wtxTransparent.GetHash(), wtxTransparent)) + .Times(0); + EXPECT_CALL(walletdb, WriteTx(wtxSprout.GetHash(), wtxSprout)) + .Times(1).WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteTx(wtxSproutTransparent.GetHash(), wtxSproutTransparent)) + .Times(0); + EXPECT_CALL(walletdb, WriteWitnessCacheSize(0)) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteBestBlock(loc)) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, TxnCommit()) + .WillOnce(Return(true)); + wallet.SetBestChain(walletdb, loc); +} + TEST(WalletTests, UpdateSproutNullifierNoteMap) { TestWallet wallet; uint256 r {GetRandHash()}; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa5876e23..bf861662f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5342,8 +5342,13 @@ int32_t ensure_CCrequirements(uint8_t evalcode) CCerror = ""; if ( ASSETCHAINS_CCDISABLES[evalcode] != 0 || (evalcode == EVAL_MARMARA && ASSETCHAINS_MARMARA == 0) ) { - fprintf(stderr,"evalcode %d disabled\n",evalcode); - return(-1); + // check if a height activation has been set. + fprintf(stderr, "evalcode.%i activates at height. %i current height.%i\n", evalcode, mapHeightEvalActivate[evalcode], komodo_currentheight()); + if ( mapHeightEvalActivate[evalcode] == 0 || komodo_currentheight() == 0 || mapHeightEvalActivate[evalcode] > komodo_currentheight() ) + { + fprintf(stderr,"evalcode %d disabled\n",evalcode); + return(-1); + } } if ( NOTARY_PUBKEY33[0] == 0 ) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index b00365a77..296e2fa57 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -807,10 +807,17 @@ protected: } try { for (std::pair& wtxItem : mapWallet) { - if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) { - LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n"); - walletdb.TxnAbort(); - return; + auto wtx = wtxItem.second; + // We skip transactions for which mapSproutNoteData and mapSaplingNoteData + // are empty. This covers transactions that have no Sprout or Sapling data + // (i.e. are purely transparent), as well as shielding and unshielding + // transactions in which we only have transparent addresses involved. + if (!(wtx.mapSproutNoteData.empty() && wtx.mapSaplingNoteData.empty())) { + if (!walletdb.WriteTx(wtxItem.first, wtx)) { + LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n"); + walletdb.TxnAbort(); + return; + } } } if (!walletdb.WriteWitnessCacheSize(nWitnessCacheSize)) { diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index e81eba03d..d2d90a85f 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -488,7 +488,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, auto verifier = libzcash::ProofVerifier::Strict(); // ac_public chains set at height like KMD and ZEX, will force a rescan if we dont ignore this error: bad-txns-acpublic-chain // there cannot be any ztx in the wallet on ac_public chains that started from block 1, so this wont affect those. - if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain") ) + // PIRATE fails this check for notary nodes, need exception. Triggers full rescan without it. + if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain" && state.GetRejectReason() != "bad-txns-acprivacy-chain") ) { //fprintf(stderr, "tx failed: %s rejectreason.%s\n", wtx.GetHash().GetHex().c_str(), state.GetRejectReason().c_str()); // vin-empty on staking chains is error relating to a failed staking tx, that for some unknown reason did not fully erase. save them here to erase and re-add later on. diff --git a/toolchain-info.sh b/toolchain-info.sh index 0bb39c19b..6a0fc7e75 100755 --- a/toolchain-info.sh +++ b/toolchain-info.sh @@ -1,6 +1,6 @@ #!/bin/bash -tools=("gcc-6" "g++-6" "otool" "nm") +tools=("gcc-8" "g++-8" "otool" "nm") echo "Platform: `uname -a`" echo "-------------------------------------" diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 5f1817e9e..3c0522a90 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -1,6 +1,6 @@ #!/bin/bash -export CC=gcc-6 -export CXX=g++-6 +export CC=gcc-8 +export CXX=g++-8 export LIBTOOL=libtool export AR=ar export RANLIB=ranlib @@ -47,12 +47,12 @@ make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 WD=$PWD cd src/cc echo $PWD -./makerogue +./makecustom cd $WD ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ +CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ ./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" make "$@" V=1 NO_GTEST=1 STATIC=1 diff --git a/zcutil/build-win.sh b/zcutil/build-win.sh index 8cf1751af..e8c0465d9 100755 --- a/zcutil/build-win.sh +++ b/zcutil/build-win.sh @@ -14,7 +14,7 @@ cd ../ WD=$PWD cd src/cc echo $PWD -./makerogue +./makecustom cd $WD ./autogen.sh diff --git a/zcutil/build.sh b/zcutil/build.sh index dc4d027b1..96e0b7c2c 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -106,7 +106,7 @@ CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" WD=$PWD cd src/cc echo $PWD -./makecclib +./makecustom cd $WD "$MAKE" "$@" V=1