From 50b9f4fe83b5c9c088b85a168bee7ef6f51d88f5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 14:01:25 +0500 Subject: [PATCH 01/21] test_ac added --- src/rpc/server.cpp | 2 ++ src/rpc/server.h | 2 ++ src/wallet/rpcwallet.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 24f0c5f98..1eaabdbde 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -537,6 +537,8 @@ static const CRPCCommand vRPCCommands[] = { "util", "reconsiderblock", &reconsiderblock, true }, /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, + { "hidden", "test_ac", &test_ac, true }, + #ifdef ENABLE_WALLET /* Wallet */ { "wallet", "resendwallettransactions", &resendwallettransactions, true}, diff --git a/src/rpc/server.h b/src/rpc/server.h index 0166bca41..53bbd4c21 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -471,4 +471,6 @@ extern UniValue paxprices(const UniValue& params, bool fHelp); extern UniValue paxdeposit(const UniValue& params, bool fHelp); extern UniValue paxwithdraw(const UniValue& params, bool fHelp); +extern UniValue test_ac(const UniValue& params, bool fHelp); + #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8180c9239..8e304c167 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7581,3 +7581,48 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); } + +UniValue test_ac(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 4)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + std::vector pubkey1; + std::vector pubkey2; + + pubkey1 = ParseHex(params[0].get_str().c_str()); + pubkey2 = ParseHex(params[1].get_str().c_str()); + + CPubKey pk1 = pubkey2pk(pubkey1); + CPubKey pk2 = pubkey2pk(pubkey2); + + if(!pk1.IsValid() || !pk2.IsValid()) + throw runtime_error("invalid pubkey\n"); + + int64_t txfee = 10000; + int64_t amount = atoll(params[2].get_str().c_str()) * COIN; + uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); + + if( normalInputs < txfee + amount) + throw runtime_error("not enough normals\n"); + + mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); +} \ No newline at end of file From 9c526cce7d780ff18ec158e277553b162e3cfdff Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 21:04:56 +0500 Subject: [PATCH 02/21] corr heir rpc coins -> satoshi conversion --- src/cc/CCHeir.h | 8 ++--- src/cc/heir.cpp | 72 +++++++++++++++++++++++++++++----------- src/wallet/rpcwallet.cpp | 46 ++++++++++++++++--------- 3 files changed, 87 insertions(+), 39 deletions(-) diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index ecaff9cdb..30334f6e1 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -27,10 +27,10 @@ bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, class CoinHelper; class TokenHelper; -UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); -UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); -UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); -UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount); +UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid); +UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string amount); +UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string amount); UniValue HeirInfo(uint256 fundingtxid); UniValue HeirList(); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ccf9da1bf..4ef143271 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -615,7 +615,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ -template UniValue HeirFund(uint64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) +template UniValue HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -629,7 +629,8 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std if (!heirPubkey.IsValid()) { std::cerr << "HeirFund() heirPubkey is not valid!" << std::endl; - return std::string(""); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid heir pubkey")); } CPubKey myPubkey = pubkey2pk(Mypubkey()); @@ -689,12 +690,12 @@ template UniValue HeirFund(uint64_t txfee, int64_t amount, std } // if no these callers - it could not link -UniValue HeirFundCoinCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ + return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } -UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, funds, heirName, heirPubkey, inactivityTimeSec, tokenid); +UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { + return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -702,7 +703,7 @@ UniValue HeirFundTokenCaller(uint64_t txfee, int64_t funds, std::string heirName * creates tx to add more funds to cryptocondition address for spending by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) +template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -781,13 +782,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, uint64_t txfee, i result.push_back(Pair("error", "can't find normal inputs for tx fee")); } - - return result; } -UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { +UniValue HeirAddCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount) { CPubKey ownerPubkey, heirPubkey; int64_t inactivityTimeSec; @@ -798,10 +797,27 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { uint8_t hasHeirSpendingBegun = 0; if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if (tokenid == zeroid) - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (tokenid == zeroid) { + int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + int64_t amount = atoll(strAmount.c_str()); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirAdd(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } } else { UniValue result(UniValue::VOBJ); @@ -819,7 +835,7 @@ UniValue HeirAddCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { * creates tx to spend funds from cryptocondition address by either funds' owner or heir * @return result object with raw tx or error text */ -template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) +template UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee, int64_t amount, uint256 latesttxid, uint8_t funcId, uint256 tokenid, CPubKey ownerPubkey, CPubKey heirPubkey, int64_t inactivityTimeSec, std::string heirName, uint8_t hasHeirSpendingBegun) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -940,7 +956,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, uint64_t txfe return result; } -UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { +UniValue HeirClaimCaller(uint256 fundingtxid, int64_t txfee, std::string strAmount) { CPubKey ownerPubkey, heirPubkey; int64_t inactivityTimeSec; @@ -951,10 +967,26 @@ UniValue HeirClaimCaller(uint256 fundingtxid, uint64_t txfee, int64_t amount) { uint8_t hasHeirSpendingBegun = 0; if ((latesttxid = FindLatestFundingTx(fundingtxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun)) != zeroid) { - if( tokenid == zeroid ) - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); - else - return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + if (tokenid == zeroid) { + int64_t amount = (int64_t)(atof(strAmount.c_str()) * COIN); + if (amount < 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } + else { + int64_t amount = atoll(strAmount.c_str()); + if (amount <= 0) { + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid amount")); + return result; + } + return _HeirClaim(fundingtxid, txfee, amount, latesttxid, funcId, tokenid, ownerPubkey, heirPubkey, inactivityTimeSec, heirName, hasHeirSpendingBegun); + } } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8e304c167..35325e1e0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7362,7 +7362,7 @@ UniValue heirfund(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 tokenid = zeroid; - uint64_t txfee; + int64_t txfee; int64_t amount; int64_t inactivitytime; std::string hex; @@ -7373,21 +7373,34 @@ UniValue heirfund(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 5 && params.size() != 6) - throw runtime_error("heirfundtokens fee funds heirname heirpubkey inactivitytime [tokenid]\n"); + throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime [tokenid]\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + + if(params.size() == 6) // tokens in satoshis: + amount = atoll(params[1].get_str().c_str()); + else // coins: + amount = atof(params[1].get_str().c_str()) * COIN; + + if( amount <= 0 ) + throw runtime_error("incorrect amount\n"); + name = params[2].get_str(); pubkey = ParseHex(params[3].get_str().c_str()); if( !pubkey2pk(pubkey).IsValid() ) throw runtime_error("incorrect pubkey\n"); - inactivitytime = atof((char*)params[4].get_str().c_str()); + inactivitytime = atoll(params[4].get_str().c_str()); + if (inactivitytime <= 0) + throw runtime_error("incorrect inactivity time param\n"); + if (params.size() == 6) { tokenid = Parseuint256((char*)params[5].get_str().c_str()); if(tokenid == zeroid) @@ -7406,7 +7419,7 @@ UniValue heiradd(const UniValue& params, bool fHelp) { UniValue result; uint256 fundingtxid; - uint64_t txfee; + int64_t txfee; int64_t amount; int64_t inactivitytime; std::string hex; @@ -7417,18 +7430,20 @@ UniValue heiradd(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 3) - throw runtime_error("heiraddtokens fee funds fundingtxid\n"); + throw runtime_error("heiradd txfee funds fundingtxid\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirAddCaller(fundingtxid, txfee, amount); + result = HeirAddCaller(fundingtxid, txfee, params[1].get_str()); return result; } @@ -7437,7 +7452,6 @@ UniValue heirclaim(const UniValue& params, bool fHelp) UniValue result; // result(UniValue::VOBJ); uint256 fundingtxid; int64_t txfee; - int64_t amount; int64_t inactivitytime; std::string hex; std::vector pubkey; @@ -7448,18 +7462,20 @@ UniValue heirclaim(const UniValue& params, bool fHelp) return NullUniValue; if (fHelp || params.size() != 3) - throw runtime_error("heirclaimtokens fee funds fundingtxid\n"); + throw runtime_error("heirclaim txfee funds fundingtxid\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txfee = atoll((char*)params[0].get_str().c_str()); - amount = atoll((char*)params[1].get_str().c_str()); + txfee = atoll(params[0].get_str().c_str()); + if (txfee < 0) + throw runtime_error("incorrect txfee param\n"); + fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); - result = HeirClaimCaller(fundingtxid, txfee, amount); + result = HeirClaimCaller(fundingtxid, txfee, params[1].get_str()); return result; } From 21ad10ac1591779052b89d96bffd6b0db24c1051 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 21 Jan 2019 22:33:50 +0500 Subject: [PATCH 03/21] check of vin's owner pubkeys added --- src/cc/heir.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 4ef143271..3891a34f4 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -400,6 +400,7 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &f return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } + /** * find the latest funding tx: it may be the first F tx or one of A or C tx's * Note: this function is also called from validation code (use non-locking calls) @@ -471,10 +472,24 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke if (tmpFuncId != 0 && fundingtxid == fundingTxidInOpret && (tokenid == zeroid || tokenid == tokenidInOpret)) { // check tokenid also if (blockHeight > maxBlockHeight) { - maxBlockHeight = blockHeight; - latesttxid = txid; - funcId = tmpFuncId; - hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + + // check owner pubkey in vins + bool hasVinOwner = false; + for (auto vin : regtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey == ownerPubkey) { + hasVinOwner = true; + break; + } + } + + // we ignore 'donations' tx (non-owner fundings) for calculating if heir is allowed to spend: + if (hasVinOwner) { + hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; + maxBlockHeight = blockHeight; + latesttxid = txid; + funcId = tmpFuncId; + } //std::cerr << "FindLatestFundingTx() txid=" << latesttxid.GetHex() << " at blockHeight=" << maxBlockHeight // << " opreturn type=" << (char)(funcId ? funcId : ' ') << " hasHeirSpendingBegun=" << (int)hasHeirSpendingBegun << " - set as current lasttxid" << '\n'; @@ -615,7 +630,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info * and also for setting spending plan for the funds' owner and heir * @return fundingtxid handle for subsequent references to this heir funding plan */ -template UniValue HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) +template UniValue _HeirFund(int64_t txfee, int64_t amount, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { UniValue result(UniValue::VOBJ); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -656,6 +671,23 @@ template UniValue HeirFund(int64_t txfee, int64_t amount, std: if (change != 0) { // vout[1] mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + + // check my pubkey in vins + bool notMypubkey = false; + for (auto vin : mtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey != myPubkey) { + notMypubkey = true; + break; + } + } + // do not allow to sign non-owner vin: + if (notMypubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not the owner's key in the wallet")); + return result; + } + // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys; @@ -691,11 +723,11 @@ template UniValue HeirFund(int64_t txfee, int64_t amount, std: // if no these callers - it could not link UniValue HeirFundCoinCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid){ - return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); + return _HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } UniValue HeirFundTokenCaller(int64_t txfee, int64_t satoshis, std::string heirName, CPubKey heirPubkey, int64_t inactivityTimeSec, uint256 tokenid) { - return HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); + return _HeirFund(txfee, satoshis, heirName, heirPubkey, inactivityTimeSec, tokenid); } /** @@ -749,6 +781,22 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in if (change != 0) { // vout[1] mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } + + // check my pubkey in vins + bool notMypubkey = false; + for (auto vin : mtx.vin) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid() && vinPubkey != myPubkey) { + notMypubkey = true; + break; + } + } + // do not allow to sign non-owner vin: + if (notMypubkey) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not the owner's key in the wallet")); + return result; + } // add 1of2 vout validation pubkeys - needed only for tokens: std::vector voutTokenPubkeys; From 56d68d816638321b562f4bfe940fb894929b93aa Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:11:09 +0500 Subject: [PATCH 04/21] corr checking for owner pubkey in vins (is owner's or is other's) --- src/cc/heir.cpp | 86 ++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 3891a34f4..2ebf4b490 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -400,6 +400,22 @@ uint8_t DecodeHeirEitherOpRet(CScript scriptPubKey, uint256 &tokenid, uint256 &f return _DecodeHeirEitherOpRet(scriptPubKey, tokenid, dummyOwnerPubkey, dummyHeirPubkey, dummyInactivityTime, dummyHeirName, fundingTxidInOpret, hasHeirSpendingBegun, noLogging); } +// check if pubkey is in vins +void CheckVinPubkey(std::vector vins, CPubKey pubkey, bool &hasPubkey, bool &hasOtherPubkey) { + + hasPubkey = false; + hasOtherPubkey = false; + + for (auto vin : vins) { + CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); + if (vinPubkey.IsValid()) { + if (vinPubkey == pubkey) + hasPubkey = true; + if (vinPubkey != pubkey) + hasOtherPubkey = true; + } + } +} /** * find the latest funding tx: it may be the first F tx or one of A or C tx's @@ -474,17 +490,13 @@ uint256 _FindLatestFundingTx(uint256 fundingtxid, uint8_t& funcId, uint256 &toke if (blockHeight > maxBlockHeight) { // check owner pubkey in vins - bool hasVinOwner = false; - for (auto vin : regtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey == ownerPubkey) { - hasVinOwner = true; - break; - } - } + bool isOwner = false; + bool isNonOwner = false; - // we ignore 'donations' tx (non-owner fundings) for calculating if heir is allowed to spend: - if (hasVinOwner) { + CheckVinPubkey(regtx.vin, ownerPubkey, isOwner, isNonOwner); + + // we ignore 'donations' tx (with non-owner inputs) for calculating if heir is allowed to spend: + if (isOwner && !isNonOwner) { hasHeirSpendingBegun = hasHeirSpendingBegunInOpret; maxBlockHeight = blockHeight; latesttxid = txid; @@ -672,23 +684,19 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - // check my pubkey in vins - bool notMypubkey = false; - for (auto vin : mtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey != myPubkey) { - notMypubkey = true; - break; - } - } - // do not allow to sign non-owner vin: - if (notMypubkey) { + // check owner pubkey in vins + bool isMypubkey = false; + bool isNotMypubkey = false; + + CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + + // for initial funding do not allow to sign by non-owner key: + if (isNotMypubkey) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "not the owner's key in the wallet")); + result.push_back(Pair("error", "using non-owner inputs not allowed")); return result; } - // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(myPubkey); @@ -782,22 +790,28 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in mtx.vout.push_back(Helper::makeUserVout(change, myPubkey)); } - // check my pubkey in vins - bool notMypubkey = false; - for (auto vin : mtx.vin) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid() && vinPubkey != myPubkey) { - notMypubkey = true; - break; - } - } - // do not allow to sign non-owner vin: - if (notMypubkey) { + // check owner pubkey in vins + bool isMypubkey = false; + bool isNotMypubkey = false; + + CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + + // for additional funding do not allow to sign by both owner and non-owner keys (is this a donation or not?): + if (isMypubkey && isNotMypubkey) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "not the owner's key in the wallet")); + result.push_back(Pair("error", "using both owner and non-owner inputs is not allowed")); return result; } + // warn the user he's making a donation if this is all non-owner keys: + if (isNotMypubkey) { + result.push_back(Pair("result", "warning")); + result.push_back(Pair("warning", "you are about to make a donation to heir fund")); + } + else { + result.push_back(Pair("result", "success")); + } + // add 1of2 vout validation pubkeys - needed only for tokens: std::vector voutTokenPubkeys; voutTokenPubkeys.push_back(ownerPubkey); @@ -808,11 +822,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in Helper::makeAddOpRet(tokenid, voutTokenPubkeys, fundingtxid, hasHeirSpendingBegun))); if (!rawhextx.empty()) { - result.push_back(Pair("result", "success")); result.push_back(Pair("hextx", rawhextx)); } else { std::cerr << "HeirAdd error in FinalizeCCtx" << std::endl; + result.clear(); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "sign error")); } From e6f41e085ed727e9103816ed4b07d3e358973f5a Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:49:34 +0500 Subject: [PATCH 05/21] added real owner inactivity time in heirinfo --- src/cc/heir.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 2ebf4b490..bbc54e232 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1197,6 +1197,14 @@ UniValue HeirInfo(uint256 fundingtxid) result.push_back(Pair("spending allowed for the heir", stream.str().c_str())); stream.str(""); stream.clear(); + + // adding owner current inactivity time: + if (!hasHeirSpendingBegun && durationSec <= inactivityTimeSec) { + stream << durationSec; + result.push_back(Pair("owner inactivity time", stream.str().c_str())); + stream.str(""); + stream.clear(); + } result.push_back(Pair("result", "success")); } From bd2903762880424cb523d0340a1e852e085d1c24 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 13:59:39 +0500 Subject: [PATCH 06/21] string "sec" (seconds) added to heirinfo --- src/cc/heir.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index bbc54e232..ff8d77209 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1184,13 +1184,13 @@ UniValue HeirInfo(uint256 fundingtxid) } stream << inactivityTimeSec; - result.push_back(Pair("inactivity time setting", stream.str().c_str())); + result.push_back(Pair("inactivity time setting, sec", stream.str().c_str())); stream.str(""); stream.clear(); if (!hasHeirSpendingBegun) { // we do not need find duration if the spending already has begun durationSec = CCduration(numblocks, latestFundingTxid); - std::cerr << "HeirInfo() duration=" << durationSec << " inactivityTime=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; + std::cerr << "HeirInfo() duration (sec)=" << durationSec << " inactivityTime (sec)=" << inactivityTimeSec << " numblocks=" << numblocks << '\n'; } stream << std::boolalpha << (hasHeirSpendingBegun || durationSec > inactivityTimeSec); @@ -1201,7 +1201,7 @@ UniValue HeirInfo(uint256 fundingtxid) // adding owner current inactivity time: if (!hasHeirSpendingBegun && durationSec <= inactivityTimeSec) { stream << durationSec; - result.push_back(Pair("owner inactivity time", stream.str().c_str())); + result.push_back(Pair("owner inactivity time, sec", stream.str().c_str())); stream.str(""); stream.clear(); } From a87816f5513a9bb52c7e8b1549ad2022cd144734 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 14:20:33 +0500 Subject: [PATCH 07/21] test rpc serialization Sleep added --- src/cc/heir.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ff8d77209..c0f0c8124 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1116,6 +1116,8 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; + Sleep(10000); + result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 92ab8dd7d8798bd054786070590e485a9f0b8590 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 14:25:17 +0500 Subject: [PATCH 08/21] linux sleep added --- src/cc/heir.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index c0f0c8124..32e4195dc 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,6 +16,8 @@ #include "CCHeir.h" #include "heir_validate.h" +#include + class CoinHelper; class TokenHelper; @@ -1116,7 +1118,7 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; - Sleep(10000); + sleep(10); result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 2d20276606de621c280333882bc171a0a9e7eef5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 15:03:52 +0500 Subject: [PATCH 09/21] better var naming for check vin's pubkey algo --- src/cc/heir.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 32e4195dc..ffa07e2f5 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -687,13 +687,13 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std } // check owner pubkey in vins - bool isMypubkey = false; - bool isNotMypubkey = false; + bool hasMypubkey = false; + bool hasNotMypubkey = false; - CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + CheckVinPubkey(mtx.vin, myPubkey, hasMypubkey, hasNotMypubkey); // for initial funding do not allow to sign by non-owner key: - if (isNotMypubkey) { + if (hasNotMypubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "using non-owner inputs not allowed")); return result; @@ -793,20 +793,20 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in } // check owner pubkey in vins - bool isMypubkey = false; - bool isNotMypubkey = false; + bool hasMypubkey = false; + bool hasNotMypubkey = false; - CheckVinPubkey(mtx.vin, myPubkey, isMypubkey, isNotMypubkey); + CheckVinPubkey(mtx.vin, myPubkey, hasMypubkey, hasNotMypubkey); // for additional funding do not allow to sign by both owner and non-owner keys (is this a donation or not?): - if (isMypubkey && isNotMypubkey) { + if (hasMypubkey && hasNotMypubkey) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "using both owner and non-owner inputs is not allowed")); return result; } // warn the user he's making a donation if this is all non-owner keys: - if (isNotMypubkey) { + if (hasNotMypubkey) { result.push_back(Pair("result", "warning")); result.push_back(Pair("warning", "you are about to make a donation to heir fund")); } @@ -1118,7 +1118,7 @@ UniValue HeirInfo(uint256 fundingtxid) std::ostringstream stream; std::string msg; - sleep(10); + //sleep(10); result.push_back(Pair("fundingtxid", fundingtxid.GetHex())); result.push_back(Pair("name", heirName.c_str())); From 98c5280e6b95b37f2a704a6d5433533366dad263 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 18:31:03 +0500 Subject: [PATCH 10/21] corr marker to cc unspendable for F, added validation to prevent its spending added marker to prevent archiving for A --- src/cc/heir.cpp | 33 +++++++++++++---------- src/cc/heir_validate.h | 60 +++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ffa07e2f5..883b11da2 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,8 +16,6 @@ #include "CCHeir.h" #include "heir_validate.h" -#include - class CoinHelper; class TokenHelper; @@ -653,6 +651,8 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std cp = CCinit(&C, Helper::getMyEval()); if (txfee == 0) txfee = 10000; + + int64_t markerfee = 10000; //std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl; @@ -664,17 +664,18 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std CPubKey myPubkey = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) { int64_t inputs, change; - if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners - //mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk - mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); + if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { + + mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey)); // add a marker for finding all plans in HeirList() // TODO: change marker either to cc or normal txidaddr unspendable CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker? + // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone + MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code // calc and add change vout: if (inputs > amount) @@ -782,7 +783,11 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in // add cryptocondition to spend this funded amount for either pk mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey)); - + + char markeraddr[64]; + CPubKey markerPubkey = CCtxidaddr(markeraddr, fundingtxid); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts + if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user @@ -1232,10 +1237,10 @@ UniValue HeirInfo(uint256 fundingtxid) template void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; - char coinaddr[64]; - CPubKey ccPubKeyEmpty; - GetCCaddress(cp, coinaddr, ccPubKeyEmpty); - SetCCunspents(unspentOutputs, cp->normaladdr); + char markeraddr[64]; + + GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); + SetCCunspents(unspentOutputs, markeraddr); //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; @@ -1283,10 +1288,10 @@ UniValue HeirList() struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit! cpHeir = CCinit(&heirC, EVAL_HEIR); - cpTokens = CCinit(&tokenC, EVAL_TOKENS); + //cpTokens = CCinit(&tokenC, EVAL_TOKENS); _HeirList(cpHeir, result); - _HeirList(cpTokens, result); + //_HeirList(cpTokens, result); not used anymore return result; } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index c4bb7ea60..7dd09a427 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -125,8 +125,8 @@ class CValidatorBase public: CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0; - virtual bool validateVout(CTxOut vout, std::string& message) const = 0; + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0; + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0; protected: CCcontract_info * m_cp; @@ -258,10 +258,10 @@ private: if (v->isVinValidator()) // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); else // if it is vout validator pass the previous tx vout: - result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], refMessage); + result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); if (!result) { return result; } @@ -359,7 +359,7 @@ private: if (!v->isVinValidator()) { // if this is a 'in' validation plan then pass the previous tx vout: - bool result = v->validateVout(pTx->vout[iv], refMessage); + bool result = v->validateVout(pTx->vout[iv], iv, refMessage); if (!result) return result; } @@ -402,7 +402,7 @@ public: m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl; CPubKey ownerPubkey, heirPubkey; @@ -438,7 +438,7 @@ public: std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return false; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; } private: CScript m_fundingOpretScript; @@ -456,7 +456,7 @@ public: : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl; @@ -498,7 +498,7 @@ public: message = std::string("invalid pubkey"); return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -516,7 +516,7 @@ public: : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl; @@ -554,7 +554,7 @@ public: // this is not heir: return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -572,7 +572,7 @@ public: : m_fundingOpretScript(opret), CValidatorBase(cp) {} virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { //std::cerr << "COpRetValidator::validateVout() entered" << std::endl; @@ -607,12 +607,42 @@ public: //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } private: CScript m_fundingOpretScript; }; + +/* +** marker spending prevention validator, +** returns false if for tx with funcid=F vout.1 is being tried to spend +*/ +template class CMarkerValidator : CValidatorBase +{ +public: + CMarkerValidator(CCcontract_info* cp) + : CValidatorBase(cp) { } + + virtual bool isVinValidator() const { return false; } // this is vout validator + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { + + uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; + uint8_t dummyIsHeirSpendingBegan; + + uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + + if( funcId == 'F' && vout_n == 1 ) + return false; + + return true; + } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + +private: + CScript m_fundingOpretScript; +}; + /** * empty validator always returns true */ @@ -623,8 +653,8 @@ public: : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } - virtual bool validateVout(CTxOut vout, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; } + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } }; From 426aa32dd50e7010eb1465032317b4b146dc5f3b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 19:25:25 +0500 Subject: [PATCH 11/21] corr F tx marker protection validation code --- src/cc/heir.cpp | 1 + src/cc/heir_validate.h | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 883b11da2..69bf1a757 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -56,6 +56,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont // only for tokens: CMyPubkeyVoutValidator ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret COpRetValidator opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx + CMarkerValidator markerValidator(cp); // initial tx marker spending protection CNullValidator nullValidator(cp); switch (funcId) { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 7dd09a427..14e608bc2 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -125,7 +125,7 @@ class CValidatorBase public: CValidatorBase(CCcontract_info* cp) : m_cp(cp) {} virtual bool isVinValidator() const = 0; - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0; + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0; protected: @@ -258,7 +258,7 @@ private: if (v->isVinValidator()) // validate this vin and previous vout: - result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); + result = v->validateVin(pTx->vin[iv], pPrevTx->vout, pTx->vin[iv].prevout.n, refMessage); else // if it is vout validator pass the previous tx vout: result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage); @@ -438,7 +438,7 @@ public: std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl; return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return false; } private: CScript m_fundingOpretScript; @@ -498,7 +498,7 @@ public: message = std::string("invalid pubkey"); return false; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -554,7 +554,7 @@ public: // this is not heir: return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; @@ -607,17 +607,17 @@ public: //std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl; return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } private: CScript m_fundingOpretScript; }; -/* -** marker spending prevention validator, -** returns false if for tx with funcid=F vout.1 is being tried to spend -*/ +/** + * marker spending prevention validator, + * returns false if for tx with funcid=F vout.1 is being tried to spend + */ template class CMarkerValidator : CValidatorBase { public: @@ -625,22 +625,22 @@ public: : CValidatorBase(cp) { } virtual bool isVinValidator() const { return false; } // this is vout validator - virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { + virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (prevVout.size() > 0) { - if( funcId == 'F' && vout_n == 1 ) - return false; - - return true; + // get funcId for prev tx: + uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + if (funcId == 'F' && prevN == 1) // do not allow to spend 'F' marker's vout + return false; + } + + return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } - -private: - CScript m_fundingOpretScript; }; /** @@ -654,7 +654,7 @@ public: virtual bool isVinValidator() const { return false; } virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } - virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; } + virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { return true; } }; From 6c26e91376209daf8ff0b92ce57b3e658585186b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 19:48:24 +0500 Subject: [PATCH 12/21] corr cpHeir init in _heirFund for marker enabled logging --- src/cc/heir.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 69bf1a757..a5533c0c1 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -674,7 +674,9 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std // add a marker for finding all plans in HeirList() // TODO: change marker either to cc or normal txidaddr unspendable - CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0); + struct CCcontract_info *cpHeir, heirC; + cpHeir = CCinit(&heirC, EVAL_HEIR); + CPubKey heirUnspendablePubKey = GetUnspendable(cpHeir, 0); // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code @@ -1235,7 +1237,7 @@ UniValue HeirInfo(uint256 fundingtxid) * @return list of heir plan handles (fundingtxid) */ -template void _HeirList(struct CCcontract_info *cp, UniValue &result) +void _HeirList(struct CCcontract_info *cp, UniValue &result) { std::vector> unspentOutputs; char markeraddr[64]; @@ -1243,7 +1245,7 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); SetCCunspents(unspentOutputs, markeraddr); - //std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; // TODO: move marker to special cc addr to prevent checking all tokens for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -1252,7 +1254,7 @@ template void _HeirList(struct CCcontract_info *cp, UniValue &r uint256 tokenid; int32_t vout = (int32_t)it->first.index; - //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; if (GetTransaction(txid, fundingtx, hashBlock, false)) { @@ -1291,7 +1293,7 @@ UniValue HeirList() cpHeir = CCinit(&heirC, EVAL_HEIR); //cpTokens = CCinit(&tokenC, EVAL_TOKENS); - _HeirList(cpHeir, result); + _HeirList(cpHeir, result); //_HeirList(cpTokens, result); not used anymore return result; From 28d090c05ea324444184a1e03b3f29151894782e Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:02:20 +0500 Subject: [PATCH 13/21] corr adding marker vout for F --- src/cc/heir.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index a5533c0c1..993c7bb5b 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -678,7 +678,7 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std cpHeir = CCinit(&heirC, EVAL_HEIR); CPubKey heirUnspendablePubKey = GetUnspendable(cpHeir, 0); // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone - MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, markerfee, heirUnspendablePubKey)); // this marker spending is disabled in the validation code // calc and add change vout: if (inputs > amount) @@ -762,6 +762,8 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in if (txfee == 0) txfee = 10000; + int64_t markerfee = 10000; + CPubKey myPubkey = pubkey2pk(Mypubkey()); // check if it is the owner @@ -771,7 +773,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in return result; } - if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners + if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) { // some for marker int64_t inputs, change; @@ -789,7 +791,7 @@ template UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in char markeraddr[64]; CPubKey markerPubkey = CCtxidaddr(markeraddr, fundingtxid); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts + mtx.vout.push_back(CTxOut(markerfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts if (inputs > amount) change = (inputs - amount); // -txfee <-- txfee pays user From 3865cae643c701742cdb57c667bbd02248f8c85c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:21:45 +0500 Subject: [PATCH 14/21] added test to try to spend heir marker F --- src/rpc/server.cpp | 1 + src/rpc/server.h | 2 ++ src/wallet/rpcwallet.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1eaabdbde..82a400e71 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -538,6 +538,7 @@ static const CRPCCommand vRPCCommands[] = /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, { "hidden", "test_ac", &test_ac, true }, + { "hidden", "test_heirmarker", &test_heirmarker, true }, #ifdef ENABLE_WALLET /* Wallet */ diff --git a/src/rpc/server.h b/src/rpc/server.h index 53bbd4c21..3edc85ebf 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -471,6 +471,8 @@ extern UniValue paxprices(const UniValue& params, bool fHelp); extern UniValue paxdeposit(const UniValue& params, bool fHelp); extern UniValue paxwithdraw(const UniValue& params, bool fHelp); +// test rpc: extern UniValue test_ac(const UniValue& params, bool fHelp); +extern UniValue test_heirmarker(const UniValue& params, bool fHelp); #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 35325e1e0..76ca2cf8d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7641,4 +7641,31 @@ UniValue test_ac(const UniValue& params, bool fHelp) cp = CCinit(&C, EVAL_HEIR); return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); +} + +UniValue test_heirmarker(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 4)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements() < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + mtx.vin.push_back(CTxIn(fundingtxid, 1)); + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); } \ No newline at end of file From 098ba877fb3a0d90cc83082bf20802d7aec7b402 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 20:37:41 +0500 Subject: [PATCH 15/21] corr test code for spending marker F --- src/cc/heir_validate.h | 5 +++-- src/wallet/rpcwallet.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 14e608bc2..fd414461e 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -635,10 +635,11 @@ public: // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - if (funcId == 'F' && prevN == 1) // do not allow to spend 'F' marker's vout + if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout + message = std::string("spending marker not allowed"); return false; + } } - return true; } }; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 76ca2cf8d..c1cf25b41 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7648,16 +7648,20 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) // make fake token tx: struct CCcontract_info *cp, C; - if (fHelp || (params.size() != 4)) + if (fHelp || (params.size() != 1)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements() < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); CPubKey myPubkey = pubkey2pk(Mypubkey()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); + if (normalInputs < 10000) + throw runtime_error("not enough normals\n"); + mtx.vin.push_back(CTxIn(fundingtxid, 1)); mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); From 8a15610e445b1bc9db91bff96ae1807cf30eae3d Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:03:08 +0500 Subject: [PATCH 16/21] corr marker validator --- src/cc/heir.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 993c7bb5b..3070ed9ef 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -60,10 +60,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont CNullValidator nullValidator(cp); switch (funcId) { - case 'F': // fund tokens + case 'F': // fund tokens (only for tokens) // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &ownerCCaddrValidator); // check cc owner addr // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding @@ -71,10 +71,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont // no checking for opret yet break; - case 'A': // add tokens + case 'A': // add tokens (only for tokens) // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &ownerCCaddrValidator); // check cc owner addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &ownerCCaddrValidator); // check cc owner addr // vout validation plan: voutPlan.pushValidators(0, &cc1of2ValidatorThis); // check 1of2 addr funding @@ -82,10 +82,10 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont voutPlan.pushValidators(numvouts - 1, &opRetValidator); // opreturn check, NOTE: only for C or A: break; - case 'C': + case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &cc1of2ValidatorThis); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend From 61f1d8771deeafd0fcc3855b153052910de4bbae Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:07:44 +0500 Subject: [PATCH 17/21] removed 1of2 validator for test marker spending --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 3070ed9ef..ce0445975 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -85,7 +85,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator/*, &cc1of2ValidatorThis*/); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend From fb69b514b2d61d127635d8b021061a5a60373cb0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:36:57 +0500 Subject: [PATCH 18/21] added logging to marker validator --- src/cc/heir_validate.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index fd414461e..0e4a04868 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -631,15 +631,21 @@ public: uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; + std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; + if (prevVout.size() > 0) { // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); + + std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; + if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout message = std::string("spending marker not allowed"); return false; } } + std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; return true; } }; From da00a3d0217f4c7ea6c1dc5b35ac5a1dc111b008 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:47:31 +0500 Subject: [PATCH 19/21] isVinValidator flag corrected = true --- src/cc/heir_validate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 0e4a04868..6e4049896 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -624,7 +624,7 @@ public: CMarkerValidator(CCcontract_info* cp) : CValidatorBase(cp) { } - virtual bool isVinValidator() const { return false; } // this is vout validator + virtual bool isVinValidator() const { return true; } // this is vin validator virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; } virtual bool validateVin(CTxIn vin, std::vector prevVout, int32_t prevN, std::string& message) const { From de8af6cc93d198ce2db3c18ca26efad349e8f0a5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 21:54:47 +0500 Subject: [PATCH 20/21] debug logging disabled --- src/cc/heir.cpp | 4 ++-- src/cc/heir_validate.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index ce0445975..93a59f95f 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1247,7 +1247,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); SetCCunspents(unspentOutputs, markeraddr); - std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; + //std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; // TODO: move marker to special cc addr to prevent checking all tokens for (std::vector>::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { @@ -1256,7 +1256,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) uint256 tokenid; int32_t vout = (int32_t)it->first.index; - std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; + //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; if (GetTransaction(txid, fundingtx, hashBlock, false)) { diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 6e4049896..df58e3bf1 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -631,21 +631,20 @@ public: uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid; uint8_t dummyIsHeirSpendingBegan; - std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; - + //std::cerr << "CMarkerValidator::validateVin() prevVout.size()=" << prevVout.size() << " prevN=" << prevN << std::endl; if (prevVout.size() > 0) { // get funcId for prev tx: uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true); - std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; + //std::cerr << "CMarkerValidator::validateVin() funcId=" << (funcId?funcId:' ') << std::endl; if (funcId == 'F' && prevN == 1) { // do not allow to spend 'F' marker's vout message = std::string("spending marker not allowed"); return false; } } - std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; + //std::cerr << "CMarkerValidator::validateVin() exits with true" << std::endl; return true; } }; From 6481576883e63756c37142f886868b8a1b67009a Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 22 Jan 2019 22:02:43 +0500 Subject: [PATCH 21/21] restored 1of2 validator for C (was off to test markerValidator) --- src/cc/heir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 93a59f95f..71ec9b040 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -85,7 +85,7 @@ template bool RunValidationPlans(uint8_t funcId, struct CCcont case 'C': // spend coins or tokens // vin validation plan: vinPlan.pushValidators((CInputIdentifierBase*)&normalInputIdentifier, &nullValidator); // txfee vin - vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator/*, &cc1of2ValidatorThis*/); // cc1of2 funding addr + vinPlan.pushValidators((CInputIdentifierBase*)&ccInputIdentifier, &markerValidator, &cc1of2ValidatorThis); // cc1of2 funding addr // vout validation plan: voutPlan.pushValidators(0, &heirSpendValidator); // check if heir is allowed to spend