From 2995bbcc794c99f39703c1ed220410065c03a878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:28:35 -1100 Subject: [PATCH 01/15] rework selfimport --- src/cc/import.cpp | 76 +++++++++++++++++++++++++++--------------- src/komodo_utils.h | 6 ---- src/rpc/crosschain.cpp | 39 +++++++--------------- 3 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 7902a74b3..d8006cca2 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -31,9 +31,12 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; +int32_t komodo_nextheight(); -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof) // find burnTx with hash from "other" daemon { + MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; + tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn @@ -44,15 +47,45 @@ int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash) // f // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn return(-1); } - else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + else { - // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - return(0); - } - else if ( ASSETCHAINS_SELFIMPORT == "GATEWAY" ) - { - // external coin is the assetchains symbol in the burnTx OP_RETURN + if ( !E_UNMARSHAL(rawtx, ss >> tx) ) return(-1); + scriptPubKey = tx.vout[0].scriptPubKey; + mtx = tx; + mtx.fOverwintered = tmptx.fOverwintered; + mtx.nExpiryHeight = tmptx.nExpiryHeight; + mtx.nVersionGroupId = tmptx.nVersionGroupId; + mtx.nVersion = tmptx.nVersion; + mtx.vout.clear(); + mtx.vout.resize(1); + mtx.vout[0].nValue = burnAmount; + mtx.vout[0].scriptPubKey = scriptPubKey; + if ( tx.GetHash() != txid ) + return(-1); + if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + { + // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 + if ( GetTransaction(tx.vin[0].prevout,vintx,blockHash,false) == 0 ) + return(-1); + if ( tx.vin[0].prevn < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevn].scriptPubKey) != 0 ) + { + pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); + if ( strcmp(pkaddr,destaddr) == 0 ) + { + proof = std::make_pair(txid,newBranch); + return(0); + } + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevn,destaddr,pkaddr); + } + return(-1); + } + else + { + // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN + // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent + return(-1); + } } else return(-1); return(0); @@ -81,20 +114,18 @@ int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,st int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); + fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().ToString().c_str()); return(0); return(-1); } -bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) +bool Eval::ImportCoin(const std::vector params,const CTransaction &importTx,unsigned int nIn) { + TxProof proof; CTransaction burnTx; std::vector payouts; uint64_t txfee = 10000; + uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; if (importTx.vout.size() < 2) return Invalid("too-few-vouts"); - // params - TxProof proof; - CTransaction burnTx; - std::vector payouts; - if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) return Invalid("invalid-params"); @@ -102,15 +133,9 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // It should not be at all malleable if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) return Invalid("non-canonical"); - // burn params - uint32_t targetCcid; - std::string targetSymbol; - uint256 payoutsHash; - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) return Invalid("invalid-burn-tx"); - // check burn amount { uint64_t burnAmount = burnTx.vout.back().nValue; @@ -119,27 +144,24 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp uint64_t totalOut = 0; for (int i=0; i burnAmount) + if (totalOut > burnAmount || totalOut < burnAmount-txfee ) return Invalid("payout-too-high"); } - // Check burntx shows correct outputs hash if (payoutsHash != SerializeHash(payouts)) return Invalid("wrong-payouts"); - if (targetCcid < KOMODO_FIRSTFUNGIBLEID) return Invalid("chain-not-fungible"); - // Check proof confirms existance of burnTx if ( targetCcid != 0xffffffff ) { - if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) + if ( targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol() ) return Invalid("importcoin-wrong-chain"); uint256 target = proof.second.Exec(burnTx.GetHash()); if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - else if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) // various selfchain imports + else if ( ASSETCHAINS_SELFIMPORT == targetSymbol ) // various selfchain imports { if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { @@ -158,7 +180,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp } else { - if ( CheckGATEWAYimport(GetAssetchainsSymbol(),proof,burnTx,payouts) < 0 ) + if ( CheckGATEWAYimport(targetSymbol,proof,burnTx,payouts) < 0 ) return Invalid("GATEWAY-import-failure"); } } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f5d394c7e..a8823e5b3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1798,12 +1798,6 @@ void komodo_args(char *argv0) ASSETCHAINS_SELFIMPORT = ""; exit(0); } - else if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_SELFIMPORT != "GATEWAY" ) - { - fprintf(stderr,"invalid -ac_import type\n"); - ASSETCHAINS_SELFIMPORT = ""; - exit(0); - } if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) { fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index c9a96165a..9ba93f3f4 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -46,9 +46,8 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; -int komodo_nextheight(); uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(TxProof &proof,CTransaction burnTx,uint256 hash); +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) @@ -201,13 +200,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) throw runtime_error("export_amount too small"); } if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - { throw runtime_error("self-import chains cant be fungible"); - /*if ( ASSETCHAINS_SELFIMPORT == targetSymbol || ASSETCHAINS_SELFIMPORT == "GATEWAY" ) - { - ccid = 0xffffffff; - } // else maybe clusters of self-import chains can be supported?*/ - } CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); @@ -284,33 +277,25 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - TxProof proof; CTransaction burnTx,tx; CTxOut burnOut,savevout; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; + CMutableTransaction mtx; + TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); - if (fHelp || params.size() != 2) - throw runtime_error("selfimport txid burnamount\n\n" + if (fHelp || params.size() < 3 || params.size() > 4) + throw runtime_error("selfimport rawtx txid burnamount\n\n" "creates signed selfimport transaction from txid"); - txid = Parseuint256((char *)params[0].get_str().c_str()); - burnAmount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; - // txid is just used to specify the import recv address - // in reality it would be rawtx from the other chain and maybe better to specify address - if ( GetTransaction(txid,tx,blockHash,false) == 0 ) - throw runtime_error("selfimport couldnt find txid"); - savevout = tx.vout[0]; - mtx = tx; - mtx.vout.clear(); - mtx.vout.resize(1); - mtx.vout[0] = savevout; - mtx.vout[0].nValue = burnAmount; + rawtx = ParseHex(params[0].get_str().c_str()); + txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) + burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; + if ( params.size() == 4 ) + rawproof = ParseHex(params[3].get_str().c_str()); + if ( GetSelfimportProof(mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) + throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); - mtx = tx; mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; - if ( GetSelfimportProof(proof,tx,txid) < 0 ) - throw std::runtime_error("Failed validating selfimport"); return HexStr(E_MARSHAL(ss << MakeImportCoinTransaction(proof,burnTx,vouts))); } From 892067414816e146aa9f8776450a701c98389529 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:32:02 -1100 Subject: [PATCH 02/15] Syntax --- src/cc/import.cpp | 18 ++++++++++-------- src/rpc/crosschain.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index d8006cca2..2395791a8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -32,8 +32,10 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; int32_t komodo_nextheight(); +bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); +uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); @@ -53,10 +55,10 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo return(-1); scriptPubKey = tx.vout[0].scriptPubKey; mtx = tx; - mtx.fOverwintered = tmptx.fOverwintered; - mtx.nExpiryHeight = tmptx.nExpiryHeight; - mtx.nVersionGroupId = tmptx.nVersionGroupId; - mtx.nVersion = tmptx.nVersion; + mtx.fOverwintered = tmpmtx.fOverwintered; + mtx.nExpiryHeight = tmpmtx.nExpiryHeight; + mtx.nVersionGroupId = tmpmtx.nVersionGroupId; + mtx.nVersion = tmpmtx.nVersion; mtx.vout.clear(); mtx.vout.resize(1); mtx.vout[0].nValue = burnAmount; @@ -66,9 +68,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( GetTransaction(tx.vin[0].prevout,vintx,blockHash,false) == 0 ) + if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].prevn < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevn].scriptPubKey) != 0 ) + if ( tx.vin[0].n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].n].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -76,7 +78,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevn,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].n,destaddr,pkaddr); } return(-1); } diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 9ba93f3f4..5f40f60fb 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -47,7 +47,7 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 hash,std::vector rawproof); +int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) From fec1d8206984d53a0e82b202b71dd3dd45f43ccd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:35:35 -1100 Subject: [PATCH 03/15] Fixes --- src/cc/import.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 2395791a8..5129354ff 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -34,10 +34,12 @@ extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; int32_t komodo_nextheight(); bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; +CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { - MerkleBranch newBranch; CMutableTransaction &tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; + MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { @@ -70,7 +72,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].n].scriptPubKey) != 0 ) + if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -78,7 +80,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].n,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout,destaddr,pkaddr); } return(-1); } From e3ef4f65a4794714d86c40857f557ee6f3fd44f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:39:24 -1100 Subject: [PATCH 04/15] Include CCinclude --- src/cc/import.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 5129354ff..ecc12c3f8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -18,7 +18,7 @@ #include "importcoin.h" #include "crosschain.h" #include "primitives/transaction.h" - +#include "cc/CCinclude.h" /* * CC Eval method for import coin. @@ -31,11 +31,11 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -int32_t komodo_nextheight(); -bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); +//int32_t komodo_nextheight(); +//bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); -bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); +//CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); +//bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { @@ -70,11 +70,11 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( myGetTransaction(tx.vin[0].prevout,vintx,blockHash) == 0 ) + if ( myGetTransaction(tx.vin[0].prevhash,vintx,blockHash) == 0 ) return(-1); if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) { - pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33.data()); + pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33); if ( strcmp(pkaddr,destaddr) == 0 ) { proof = std::make_pair(txid,newBranch); From 0f05fef7e56ae78bf81cb5f155101b83a6ef32f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:41:17 -1100 Subject: [PATCH 05/15] prevout.n --- src/cc/import.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index ecc12c3f8..2faf4fb07 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -70,9 +70,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 - if ( myGetTransaction(tx.vin[0].prevhash,vintx,blockHash) == 0 ) + if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,blockHash) == 0 ) return(-1); - if ( tx.vin[0].prevout < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout].scriptPubKey) != 0 ) + if ( tx.vin[0].prevout.n < vintx.vout.size() && Getscriptaddress(destaddr,vintx.vout[tx.vin[0].prevout.n].scriptPubKey) != 0 ) { pubkey2addr(pkaddr,ASSETCHAINS_OVERRIDE_PUBKEY33); if ( strcmp(pkaddr,destaddr) == 0 ) @@ -80,7 +80,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout,destaddr,pkaddr); + fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } return(-1); } @@ -118,7 +118,7 @@ int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,st int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); - fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().ToString().c_str()); + fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().c_str()); return(0); return(-1); } From 1839b1d27f084a4906b57c5d4b6c3dc40b1e7ac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:42:54 -1100 Subject: [PATCH 06/15] Fix --- src/cc/import.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 2faf4fb07..38d054fcb 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -44,12 +44,10 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn - return(-1); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn - return(-1); } else { @@ -80,19 +78,16 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo proof = std::make_pair(txid,newBranch); return(0); } - fprintf(stderr,"vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); + fprintf(stderr,"mismatched vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } - return(-1); } else { // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent - return(-1); } } - else return(-1); - return(0); + return(-1); } // use proof from the above functions to validate the import From 4dbb9e832a447cc7ecd6774a356b13c0a7b533da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Dec 2018 23:45:27 -1100 Subject: [PATCH 07/15] Extern --- src/cc/import.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 38d054fcb..3162de1bd 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -31,11 +31,7 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; -//int32_t komodo_nextheight(); -//bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); -uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -//CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); -//bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); +extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { From e0903308239eb7b0624a1f185b1a027dea1c42a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:34:31 -1100 Subject: [PATCH 08/15] remove mutually exclusive constraint on selfimport -ac_beam and -ac_coda cannot be active at the same time Clusters can do import coin normally even with self-import chains. -ac_import=KMD (any bitcoinprotocol coin) will make a side chain (not implemented yet) Theoretically -ac_beam or -ac_coda can work with side chain (not implemented yet other than chain params) --- src/cc/import.cpp | 58 ++++++++++++++++++++++++++---------------- src/crosschain.cpp | 6 ++--- src/importcoin.cpp | 40 ++++++++++++++++++++++------- src/importcoin.h | 2 +- src/komodo_utils.h | 23 +++++++++-------- src/rpc/crosschain.cpp | 21 +++++++++------ 6 files changed, 95 insertions(+), 55 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 3162de1bd..807b12050 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -33,17 +33,23 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector &rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); - if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + if ( source == "BEAM" ) { + if ( ASSETCHAINS_BEAMPORT == 0 ) + return(-1); // confirm via ASSETCHAINS_BEAMPORT that burnTx/hash is a valid BEAM burn + // return(0); } - else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + else if ( source == "CODA" ) { + if ( ASSETCHAINS_CODAPORT == 0 ) + return(-1); // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn + // return(0); } else { @@ -61,7 +67,7 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo mtx.vout[0].scriptPubKey = scriptPubKey; if ( tx.GetHash() != txid ) return(-1); - if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + if ( source == "PUBKEY" ) { // make sure vin0 is signed by ASSETCHAINS_OVERRIDE_PUBKEY33 if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,blockHash) == 0 ) @@ -77,9 +83,9 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo fprintf(stderr,"mismatched vin0[%d] -> %s vs %s\n",tx.vin[0].prevout.n,destaddr,pkaddr); } } - else + else if ( source == ASSETCHAINS_SELFIMPORT ) { - // ASSETCHAINS_SELFIMPORT and external coin is the assetchains symbol in the burnTx OP_RETURN + // source is external coin is the assetchains symbol in the burnTx OP_RETURN // burnAmount, rawtx and rawproof should be enough for gatewaysdeposit equivalent } } @@ -88,25 +94,26 @@ int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProo // use proof from the above functions to validate the import -int32_t CheckBEAMimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckBEAMimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // check with dual-BEAM daemon via ASSETCHAINS_BEAMPORT for validity of burnTx return(-1); } -int32_t CheckCODAimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckCODAimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // check with dual-CODA daemon via ASSETCHAINS_CODAPORT for validity of burnTx return(-1); } -int32_t CheckGATEWAYimport(std::string coin,TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckGATEWAYimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { + // ASSETCHAINS_SELFIMPORT is coin // check for valid burn from external coin blockchain and if valid return(0); return(-1); } -int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector payouts) +int32_t CheckPUBKEYimport(TxProof proof,std::vector rawproof,CTransaction burnTx,std::vector payouts) { // if burnTx has ASSETCHAINS_PUBKEY vin, it is valid return(0); fprintf(stderr,"proof txid.%s\n",proof.first.GetHex().c_str()); @@ -117,19 +124,18 @@ int32_t CheckPUBKEYimport(TxProof proof,CTransaction burnTx,std::vector bool Eval::ImportCoin(const std::vector params,const CTransaction &importTx,unsigned int nIn) { TxProof proof; CTransaction burnTx; std::vector payouts; uint64_t txfee = 10000; - uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; - if (importTx.vout.size() < 2) + uint32_t targetCcid; std::string targetSymbol; uint256 payoutsHash; std::vector rawproof; + if ( importTx.vout.size() < 2 ) return Invalid("too-few-vouts"); // params if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) return Invalid("invalid-params"); - // Control all aspects of this transaction // It should not be at all malleable if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) return Invalid("non-canonical"); // burn params - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash,rawproof)) return Invalid("invalid-burn-tx"); // check burn amount { @@ -156,26 +162,34 @@ bool Eval::ImportCoin(const std::vector params,const CTransaction &impo if (!CheckMoMoM(proof.first, target)) return Invalid("momom-check-fail"); } - else if ( ASSETCHAINS_SELFIMPORT == targetSymbol ) // various selfchain imports + else { - if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) + if ( targetSymbol == "BEAM" ) { - if ( CheckBEAMimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_BEAMPORT == 0 ) + return Invalid("BEAM-import-without-port"); + else if ( CheckBEAMimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("BEAM-import-failure"); } - else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) + else if ( targetSymbol == "CODA" ) { - if ( CheckCODAimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_CODAPORT == 0 ) + return Invalid("CODA-import-without-port"); + else if ( CheckCODAimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("CODA-import-failure"); } - else if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) + else if ( targetSymbol == "PUBKEY" ) { - if ( CheckPUBKEYimport(proof,burnTx,payouts) < 0 ) + if ( ASSETCHAINS_SELFIMPORT != "PUBKEY" ) + return Invalid("PUBKEY-import-when-notPUBKEY"); + else if ( CheckPUBKEYimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("PUBKEY-import-failure"); } else { - if ( CheckGATEWAYimport(targetSymbol,proof,burnTx,payouts) < 0 ) + if ( targetSymbol != ASSETCHAINS_SELFIMPORT ) + return Invalid("invalid-gateway-import-coin"); + else if ( CheckGATEWAYimport(proof,rawproof,burnTx,payouts) < 0 ) return Invalid("GATEWAY-import-failure"); } } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 447f907cc..8b6cb12a4 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -214,16 +214,14 @@ cont: */ void CompleteImportTransaction(CTransaction &importTx) { - TxProof proof; - CTransaction burnTx; - std::vector payouts; + TxProof proof; CTransaction burnTx; std::vector payouts; std::vector rawproof; if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) throw std::runtime_error("Couldn't parse importTx"); std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash; - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof)) throw std::runtime_error("Couldn't parse burnTx"); proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); diff --git a/src/importcoin.cpp b/src/importcoin.cpp index c72aea210..e479757dd 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -38,11 +38,22 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction b } -CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts) +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof) { - std::vector opret = E_MARSHAL(ss << VARINT(targetCCid); - ss << targetSymbol; - ss << SerializeHash(payouts)); + std::vector opret; + if ( targetCCid != 0xffffffff ) + { + opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts)); + } + else + { + opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts); + ss << rawproof); + } return CTxOut(value, CScript() << OP_RETURN << opret); } @@ -60,14 +71,25 @@ bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransactio } -bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash) +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector&rawproof) { - std::vector burnOpret; + std::vector burnOpret; uint32_t ccid = 0; if (burnTx.vout.size() == 0) return false; GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); - return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); - ss >> targetSymbol; - ss >> payoutsHash); + E_UNMARSHAL(burnOpret, ss >> VARINT(ccid)); + if ( ccid != 0xffffffff ) + { + return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); + ss >> targetSymbol; + ss >> payoutsHash); + } + else + { + return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); + ss >> targetSymbol; + ss >> payoutsHash; + ss >> rawproof); + } } diff --git a/src/importcoin.h b/src/importcoin.h index 53611cac9..3053eaf72 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -30,7 +30,7 @@ CTransaction MakeImportCoinTransaction(const TxProof proof, CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts); -bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash); +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector &rawproof); bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, std::vector &payouts); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a8823e5b3..2437b0bf6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1775,36 +1775,33 @@ void komodo_args(char *argv0) ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); - + if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) + { + fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); + exit(0); + } ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" ) { if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 ) { fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } } else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) { fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) { fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); - ASSETCHAINS_SELFIMPORT = ""; exit(0); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 && ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID ) - { - fprintf(stderr,"selfimport chains cant be in a fungible cluster\n"); - exit(0); - } - //ASSETCHAINS_FOUNDERS_PERIOD = GetArg("-ac_period",0); + // else it can be gateway coin + if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; @@ -1857,7 +1854,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - 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 ) + 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 ) { 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; @@ -1927,6 +1924,10 @@ void komodo_args(char *argv0) fprintf(stderr," selfimport\n"); extralen += ASSETCHAINS_SELFIMPORT.size(); } + if ( ASSETCHAINS_BEAMPORT != 0 ) + extraptr[extralen++] = 'b'; + if ( ASSETCHAINS_CODAPORT != 0 ) + extraptr[extralen++] = 'c'; } addn = GetArg("-seednode",""); diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 5f40f60fb..0c4703725 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -47,7 +47,7 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); extern std::string ASSETCHAINS_SELFIMPORT; uint256 Parseuint256(char *hexstr); -int32_t GetSelfimportProof(CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof); UniValue assetchainproof(const UniValue& params, bool fHelp) @@ -199,8 +199,8 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (burnAmount < needed) throw runtime_error("export_amount too small"); } - if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) - throw runtime_error("self-import chains cant be fungible"); + //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) + // throw runtime_error("self-import chains cant be fungible"); CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); @@ -278,18 +278,23 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) UniValue selfimport(const UniValue& params, bool fHelp) { CMutableTransaction mtx; - TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; + std::string source; TxProof proof; CTransaction burnTx,tx; CTxOut burnOut; uint64_t burnAmount; uint256 txid,blockHash; std::vector vouts; std::vector rawtx,rawproof; CScript scriptPubKey; if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) throw runtime_error("selfimport only works on -ac_import chains"); - if (fHelp || params.size() < 3 || params.size() > 4) - throw runtime_error("selfimport rawtx txid burnamount\n\n" + if (fHelp || params.size() < 3 || params.size() > 5 ) + throw runtime_error("selfimport rawtx txid burnamount [rawproof source]\n\n" "creates signed selfimport transaction from txid"); rawtx = ParseHex(params[0].get_str().c_str()); txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; - if ( params.size() == 4 ) + source = ASSETCHAINS_SELFIMPORT; + if ( params.size() >= 4 ) + { rawproof = ParseHex(params[3].get_str().c_str()); - if ( GetSelfimportProof(mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) + if ( params.size() == 5 ) + source = params[4].get_str(); + } + if ( GetSelfimportProof(source,mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); From a5c38d8f9c37dfd87cbf5749bd0de8c9920d19f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:37:43 -1100 Subject: [PATCH 09/15] Fix --- src/importcoin.h | 2 +- src/rpc/crosschain.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/importcoin.h b/src/importcoin.h index 3053eaf72..64019ac8f 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -28,7 +28,7 @@ CAmount GetCoinImportValue(const CTransaction &tx); CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts); -CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts); +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof); bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector &rawproof); bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 0c4703725..d136074d0 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -163,7 +163,7 @@ UniValue calc_MoM(const UniValue& params, bool fHelp) UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { - uint32_t ccid = ASSETCHAINS_CC; + std::vector rawproof; uint32_t ccid = ASSETCHAINS_CC; if (fHelp || params.size() != 3) throw runtime_error( "migrate_converttoexport rawTx dest_symbol export_amount\n" @@ -201,7 +201,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); - CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout); + CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout,rawproof); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); tx.vout.clear(); @@ -297,7 +297,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) if ( GetSelfimportProof(source,mtx,scriptPubKey,proof,burnAmount,rawtx,txid,rawproof) < 0 ) throw std::runtime_error("Failed validating selfimport"); vouts = mtx.vout; - burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts); + burnOut = MakeBurnOutput(burnAmount,0xffffffff,ASSETCHAINS_SELFIMPORT,vouts,rawproof); mtx.vout.clear(); mtx.vout.push_back(burnOut); burnTx = mtx; From 0b4120eefa60aa95a2d3601f3a30c494dd70c571 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:40:20 -1100 Subject: [PATCH 10/15] Fix --- src/cc/import.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 807b12050..107a11e0a 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -33,7 +33,7 @@ extern std::string ASSETCHAINS_SELFIMPORT; extern uint16_t ASSETCHAINS_CODAPORT,ASSETCHAINS_BEAMPORT; extern uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector &rawproof) // find burnTx with hash from "other" daemon +int32_t GetSelfimportProof(std::string source,CMutableTransaction &mtx,CScript &scriptPubKey,TxProof &proof,uint64_t burnAmount,std::vector rawtx,uint256 txid,std::vector rawproof) // find burnTx with hash from "other" daemon { MerkleBranch newBranch; CMutableTransaction tmpmtx; CTransaction tx,vintx; uint256 blockHash; char destaddr[64],pkaddr[64]; tmpmtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); From 81e3a485e2c3377e77a801b4a02d514635283eeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:42:45 -1100 Subject: [PATCH 11/15] Fix test --- src/test-komodo/test_coinimport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 8c1d8b0f8..fda62c30c 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -26,7 +26,7 @@ static uint8_t testNum = 0; class TestCoinImport : public ::testing::Test, public Eval { public: - CMutableTransaction burnTx; + CMutableTransaction burnTx; std::vector rawproof; std::vector payouts; TxProof proof; uint256 MoMoM; @@ -37,7 +37,7 @@ public: void SetImportTx() { burnTx.vout.resize(0); - burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts)); + burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts,rawproof)); importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); MoMoM = burnTx.GetHash(); // TODO: an actual branch } From d63390197d524653555ef5cf3a01792f63a6010f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Jan 2019 23:53:39 -1100 Subject: [PATCH 12/15] Fix comment --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index d136074d0..318acb666 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -283,7 +283,7 @@ UniValue selfimport(const UniValue& params, bool fHelp) throw runtime_error("selfimport only works on -ac_import chains"); if (fHelp || params.size() < 3 || params.size() > 5 ) throw runtime_error("selfimport rawtx txid burnamount [rawproof source]\n\n" - "creates signed selfimport transaction from txid"); + "creates signed selfimport transaction"); rawtx = ParseHex(params[0].get_str().c_str()); txid = Parseuint256((char *)params[1].get_str().c_str()); // allow for txid != hash(rawtx) burnAmount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; From bf3cef4edcf5c27886d0589c73f02f9fb28920a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 02:13:24 -1100 Subject: [PATCH 13/15] Set raw proof to ac_name for cross chain burn --- src/rpc/crosschain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 318acb666..ace11d6a8 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -201,6 +201,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); + rawproof = GetArg("-ac_name",""); CTxOut burnOut = MakeBurnOutput(burnAmount, ccid, targetSymbol, tx.vout,rawproof); UniValue ret(UniValue::VOBJ); ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); From c4f5be1c6dbf19c1217ec38522a4aed494b03f82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 02:16:15 -1100 Subject: [PATCH 14/15] Acname -> raw proof --- src/rpc/crosschain.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index ace11d6a8..55d16288f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -163,7 +163,7 @@ UniValue calc_MoM(const UniValue& params, bool fHelp) UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { - std::vector rawproof; uint32_t ccid = ASSETCHAINS_CC; + std::vector rawproof; uint8_t *ptr; int32_t i; uint32_t ccid = ASSETCHAINS_CC; if (fHelp || params.size() != 3) throw runtime_error( "migrate_converttoexport rawTx dest_symbol export_amount\n" @@ -201,7 +201,10 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) } //if ( ASSETCHAINS_SELFIMPORT.size() > 0 ) // throw runtime_error("self-import chains cant be fungible"); - rawproof = GetArg("-ac_name",""); + rawproof.resize(strlen(ASSETCHAINS_SYMBOL)); + ptr = rawproof.data(); + for (i=0; i Date: Wed, 2 Jan 2019 02:16:52 -1100 Subject: [PATCH 15/15] ASSETCHAINS_SYMBOL --- src/rpc/crosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 55d16288f..a0a3b507f 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -204,7 +204,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) rawproof.resize(strlen(ASSETCHAINS_SYMBOL)); ptr = rawproof.data(); for (i=0; i