Merge pull request 'Sync duke to dev' (#434) from duke into dev

Reviewed-on: https://git.hush.is/hush/hush3/pulls/434
This commit is contained in:
duke
2024-10-03 17:23:48 +02:00
22 changed files with 81 additions and 474 deletions

View File

@@ -222,24 +222,6 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat
CChainParams::checkpointData = checkpointData;
}
/*
To change the max block size, all that needs to be updated is the #define _MAX_BLOCK_SIZE in utils.h
However, doing that without any other changes will allow forking non-updated nodes by creating a larger block. So, make sure to height activate the new blocksize properly.
Assuming it is 8MB, then:
#define _OLD_MAX_BLOCK_SIZE (4096 * 1024)
#define _MAX_BLOCK_SIZE (2 * 4096 * 1024)
change the body of if:
{
if ( height < saplinght+1000000 ) // activates 8MB blocks 1 million blocks after saplinght
return(_OLD_MAX_BLOCK_SIZE);
else return(_MAX_BLOCK_SIZE);
}
*/
// Unused Testnet, for completeness. We make testcoins instead.
class CTestNetParams : public CChainParams {
public:
@@ -490,16 +472,27 @@ void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivation
regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight);
}
/*
To change the max block size, all that needs to be updated is the #define _MAX_BLOCK_SIZE in utils.h
However, doing that without any other changes will allow forking non-updated nodes by creating a larger block. So, make sure to height activate the new blocksize properly.
Assuming it is 8MB, then:
#define _OLD_MAX_BLOCK_SIZE (4096 * 1024)
#define _MAX_BLOCK_SIZE (2 * 4096 * 1024)
change the body of MAX_BLOCK_SIZE() function to
{
if ( height < saplinght+1000000 ) // activates 8MB blocks 1 million blocks after saplinght
return(_OLD_MAX_BLOCK_SIZE);
else return(_MAX_BLOCK_SIZE);
}
*/
int32_t MAX_BLOCK_SIZE(int32_t height)
{
// this codebase requires sapling activation at height=1
int32_t saplinght = 1; // pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight;
//fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight);
//if ( height <= 0 || (saplinght > 0 && height >= saplinght) )
//{
return(_MAX_BLOCK_SIZE);
//}
//else return(2000000);
}
// Change the Hush blocktime at run-time(!)

View File

@@ -557,8 +557,6 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
CAmount value,nResult = 0;
if ( interestp != 0 )
*interestp = 0;
//if ( tx.IsCoinImport() )
// return GetCoinImportValue(tx);
if ( tx.IsCoinBase() != 0 )
return 0;
for (unsigned int i = 0; i < tx.vin.size(); i++)
@@ -616,7 +614,7 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
// use the maximum priority for all (partially or fully) shielded transactions.
// (Note that coinbase transactions cannot contain Sapling shielded Spends or Outputs.)
if (tx.vShieldedSpend.size() > 0 || tx.vShieldedOutput.size() > 0 || tx.IsCoinImport() ) { // || tx.IsPegsImport()) {
if (tx.vShieldedSpend.size() > 0 || tx.vShieldedOutput.size() > 0 ) {
return MAX_PRIORITY;
}

View File

@@ -233,64 +233,6 @@ public:
DefaultCCChecker() { }
virtual bool checkCC(uint256 txid, const std::vector<CTxOut> &vouts, int32_t nvout, uint8_t evalcode, std::string funcids, uint256 filtertxid)
{
CScript opret, dummy;
std::vector< vscript_t > vParams;
vscript_t vopret;
if (nvout < vouts.size())
{
// first check if it is cc vout
if (vouts[nvout].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams))
{
// try to find cc opret
if (vParams.size() > 0)
{
COptCCParams p(vParams[0]); // parse vout data
if (p.vData.size() > 0)
{
vopret = p.vData[0]; // get opret data
}
}
// if no cc opret check last vout opret
if (vopret.size() == 0)
{
GetOpReturnData(vouts.back().scriptPubKey, vopret);
}
if (vopret.size() > 2)
{
uint8_t opretEvalcode, opretFuncid;
uint256 opretTxid;
bool isEof = true;
bool isCreateTx = false;
// parse opret first 3 fields:
bool parseOk = E_UNMARSHAL(vopret,
ss >> opretEvalcode;
ss >> opretFuncid;
if (funcids.size() > 0 && opretFuncid == funcids[0]) // this means that we check txid only for second+ funcid in array (considering that the first funcid is the creation txid itself like tokens)
{
isCreateTx = true;
}
else
{
ss >> opretTxid;
isCreateTx = false;
}
isEof = ss.eof(); );
opretTxid = revuint256(opretTxid);
std::cerr << __func__ << " " << "opretEvalcode=" << opretEvalcode << " opretFuncid=" << (char)opretFuncid << " isCreateTx=" << isCreateTx << " opretTxid=" << opretTxid.GetHex() << std::endl;
if( parseOk /*parseOk=true if eof reached*/|| !isEof /*more data means okay*/)
{
if (evalcode == opretEvalcode && std::find(funcids.begin(), funcids.end(), (char)opretFuncid) != funcids.end() &&
(isCreateTx && filtertxid == txid || !isCreateTx && filtertxid == opretTxid))
{
return true;
}
}
}
}
}
return false;
}
};

View File

@@ -322,31 +322,14 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a
}
else if ( bitcoin_base58decode(rmd160,destaddr) != 25 )
{
if ( (len= is_hexstr(destaddr,0)) > 0 )
{
len >>= 1;
data.resize(len);
decode_hex(&data[0],len,destaddr);
if ( data[len-1] == OP_CHECKCRYPTOCONDITION )
{
data.resize(--len);
scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION;
}
else
{
if ( (len= is_hexstr(destaddr,0)) > 0 ) {
result.push_back(Pair("result","error"));
result.push_back(Pair("error","only CC hex allowed for now"));
return(result); }
}
else
{
return(result);
} else {
result.push_back(Pair("result","error"));
result.push_back(Pair("error","invalid destaddr/CCvout hex"));
return(result);
}
}
else
{
} else {
data.resize(20);
memcpy(&data[0],&rmd160[1],20);
scriptPubKey = (CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG);

View File

@@ -817,7 +817,7 @@ bool hush_dailysnapshot(int32_t height)
{
uint256 blockhash; CTransaction txin;
//if (tx.IsPegsImport() && j==0) continue;
if ( !tx.IsCoinImport() && !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) )
if ( !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) )
{
int vout = tx.vin[j].prevout.n;
if ( ExtractDestination(txin.vout[vout].scriptPubKey, vDest) )
@@ -994,11 +994,10 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight)
}
nDataOut++;
//fprintf(stderr,"is OP_RETURN\n");
}
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
} else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
reason = "bare-multisig";
return false;
} else if (whichType != TX_CRYPTOCONDITION && txout.IsDust(::minRelayTxFee)) {
} else if (txout.IsDust(::minRelayTxFee)) {
reason = "dust";
return false;
}
@@ -1103,8 +1102,8 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs,
if (tx.IsCoinBase())
return true; // Coinbases don't use vin normally
if (tx.IsCoinImport())
return tx.vin[0].scriptSig.IsCoinImport();
//if (tx.IsCoinImport())
// return tx.vin[0].scriptSig.IsCoinImport();
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
@@ -1180,7 +1179,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx)
unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs)
{
if (tx.IsCoinBase() || tx.IsCoinImport())
if (tx.IsCoinBase())
return 0;
unsigned int nSigOps = 0;
@@ -1223,16 +1222,6 @@ bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockInde
{
const bool overwinterActive = nHeight >=1 ? true : false; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
const bool saplingActive = nHeight >=1 ? true : false; //NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
const bool isSprout = false; //!overwinterActive;
/*
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
if (isSprout && tx.fOverwintered) {
int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight;
return state.DoS((ht < 0 || nHeight < ht) ? 0 : dosLevel,error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),REJECT_INVALID, "tx-overwinter-not-active");
//return state.DoS(isInitBlockDownload() ? 0 : dosLevel,error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),REJECT_INVALID, "tx-overwinter-not-active");
}
*/
if (saplingActive) {
// Reject transactions with valid version but missing overwintered flag
@@ -1899,7 +1888,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Keep track of transactions that spend a coinbase, which we re-scan
// during reorgs to ensure COINBASE_MATURITY is still met.
bool fSpendsCoinbase = false;
if (!tx.IsCoinImport()) { // && !tx.IsPegsImport()) {
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
const CCoins *coins = view.AccessCoins(txin.prevout.hash);
if (coins->IsCoinBase()) {
@@ -1907,7 +1895,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
break;
}
}
}
// Grab the branch ID we expect this transaction to commit to. We don't
// yet know if it does, but if the entry gets added to the mempool, then
// it has passed ContextualCheckInputs and therefore this is correct.
@@ -1937,7 +1924,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Continuously rate-limit free (really, very-low-fee) transactions
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
// be annoying or make others' transactions take longer to confirm.
if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize) && !tx.IsCoinImport() )
if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize) )
{
static CCriticalSection csFreeLimiter;
static double dFreeCount;
@@ -1960,6 +1947,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
dFreeCount += nSize;
}
fRejectAbsurdFee = false;
if ( fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19)
// Disable checks for absurd fees when adding to the mempool. Instead, this check is done
// when a user attempts to make a transaction with an absurd fee and only rejects absurd
// fees when OP_RETURN data is NOT being used. This means users making normal financial
@@ -1968,9 +1958,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// It would be nice to detect the use of OP_RETURN right here but it seems to only be known
// inside of IsStandard() inside of IsStandardTx() and we want to avoid doing expensive checks
// multiple times.
fRejectAbsurdFee = false;
if (fRejectAbsurdFee && !tx.IsCoinImport() && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19)
{
string errmsg = strprintf("absurdly high fees %s, %d > %d",
hash.ToString(),
@@ -2018,8 +2005,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
LOCK(pool.cs);
// Store transaction in memory
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
if (!tx.IsCoinImport())
{
// Add memory address index
if (fAddressIndex) {
pool.addAddressIndex(entry, view);
@@ -2031,7 +2017,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
}
}
}
return true;
}
@@ -2909,10 +2894,6 @@ int8_t GetAddressType(const CScript &scriptPubKey, CTxDestination &vDest, txnout
{
keyType = 2;
}
else if (txType == TX_CRYPTOCONDITION )
{
keyType = 3;
}
}
return keyType;
}

View File

@@ -200,19 +200,20 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
//fprintf(stderr,"%s: added dummy coinbase\n", __func__);
// Largest block you're willing to create:
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1));
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(1)); // MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1));
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)-1000), nBlockMaxSize));
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(1)-1000), nBlockMaxSize));
//nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)-1000), nBlockMaxSize));
// How much of the block should be dedicated to high-priority transactions,
// included regardless of the fees they pay
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
const unsigned int nBlockPrioritySize = std::min( nBlockMaxSize, (unsigned int) GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE) );
// nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
// Minimum block size you want to create; block will be filled with free transactions
// until there are no more or the block reaches this size:
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
const unsigned int nBlockMinSize = std::min(nBlockMaxSize, (unsigned int) GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE));
// nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
//fprintf(stderr,"%s: nBlockMaxSize=%u, nBlockPrioritySize=%u, nBlockMinSize=%u\n", __func__, nBlockMaxSize, nBlockPrioritySize, nBlockMinSize);
@@ -735,7 +736,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
pblock->hashFinalSaplingRoot = sapling_tree.root();
// all PoS chains need this data in the block at all times
if ( ASSETCHAINS_LWMAPOS || ASSETCHAINS_STAKED == 0 || HUSH_MININGTHREADS > 0 )
if ( ASSETCHAINS_LWMAPOS || HUSH_MININGTHREADS > 0 )
{
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
@@ -743,7 +744,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (IS_HUSH_NOTARY == 0 || My_notaryid < 0) )
if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && (IS_HUSH_NOTARY == 0 || My_notaryid < 0) )
{
CValidationState state;
//fprintf(stderr,"%s: check validity\n", __func__);
@@ -761,11 +762,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
//fprintf(stderr,"valid\n");
}
}
if ( !isStake )
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
// fprintf(stderr,"%s: done\n", __func__);
return pblocktemplate.release();
}
@@ -785,7 +785,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
hashPrevBlock = pblock->hashPrevBlock;
}
++nExtraNonce;
unsigned int nHeight = pindexPrev->GetHeight()+1; // Height first in coinbase required for block.version=2
const unsigned int nHeight = pindexPrev->GetHeight()+1; // Height first in coinbase required for block.version=2
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
@@ -1151,7 +1151,7 @@ void static RandomXMiner()
} else {
rxdebug("%s: calculating keyHeight with randomxInterval=%d\n", randomxInterval);
// At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing
int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval;
const int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval;
uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash();
randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey);
@@ -1163,10 +1163,10 @@ void static RandomXMiner()
rxdebug("%s: initializing dataset with %d threads\n", initThreadCount);
std::vector<std::thread> threads;
uint32_t startItem = 0;
auto perThread = datasetItemCount / initThreadCount;
auto remainder = datasetItemCount % initThreadCount;
const auto perThread = datasetItemCount / initThreadCount;
const auto remainder = datasetItemCount % initThreadCount;
for (int i = 0; i < initThreadCount; ++i) {
auto count = perThread + (i == initThreadCount - 1 ? remainder : 0);
const auto count = perThread + (i == initThreadCount - 1 ? remainder : 0);
threads.push_back(std::thread(&randomx_init_dataset, randomxDataset, randomxCache, startItem, count));
startItem += count;
}
@@ -1205,7 +1205,7 @@ void static RandomXMiner()
return;
}
static uint32_t counter;
if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 )
if ( counter++ < 10 )
fprintf(stderr,"RandomXMiner: created illegal blockB, retry with counter=%u\n", counter);
sleep(1);
continue;
@@ -1399,10 +1399,8 @@ void static RandomXMiner()
rxdebug("%s: going to destroy rx VM\n");
randomx_destroy_vm(myVM);
rxdebug("%s: destroyed VM\n");
}
} catch (const boost::thread_interrupted&) {
miningTimer.stop();
c.disconnect();

View File

@@ -693,7 +693,7 @@ public:
bool IsMint() const
{
return IsCoinImport() || IsCoinBase();
return IsCoinBase(); // || IsCoinImport();
}
bool IsCoinBase() const
@@ -705,7 +705,8 @@ public:
bool IsCoinImport() const
{
return (vin.size() == 1 && vin[0].prevout.n == 10e8);
return false;
//return (vin.size() == 1 && vin[0].prevout.n == 10e8);
}
bool IsPegsImport() const

View File

@@ -242,7 +242,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
vector<unsigned char> hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23);
delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString()));
}
else if (out.scriptPubKey.IsPayToPublicKey() || out.scriptPubKey.IsPayToCryptoCondition()) {
else if (out.scriptPubKey.IsPayToPublicKey()) {
CTxDestination address;
if (ExtractDestination(out.scriptPubKey, address))
{

View File

@@ -146,31 +146,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
UniValue in(UniValue::VOBJ);
if (tx.IsCoinBase()) {
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
}
/* else if (tx.IsCoinImport() && txin.prevout.n==10e8) {
in.push_back(Pair("is_import", "1"));
ImportProof proof; CTransaction burnTx; std::vector<CTxOut> payouts; CTxDestination importaddress;
if (UnmarshalImportTx(tx, proof, burnTx, payouts))
{
if (burnTx.vout.size() == 0)
continue;
in.push_back(Pair("txid", burnTx.GetHash().ToString()));
in.push_back(Pair("value", ValueFromAmount(burnTx.vout.back().nValue)));
in.push_back(Pair("valueSat", burnTx.vout.back().nValue));
// extract op_return to get burn source chain.
std::vector<uint8_t> burnOpret; std::string targetSymbol; uint32_t targetCCid; uint256 payoutsHash; std::vector<uint8_t>rawproof;
if (UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash, rawproof))
{
if (rawproof.size() > 0)
{
std::string sourceSymbol;
E_UNMARSHAL(rawproof, ss >> sourceSymbol);
in.push_back(Pair("address", "IMP-" + sourceSymbol + "-" + burnTx.GetHash().ToString()));
}
}
}
} */
else {
} else {
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (int64_t)txin.prevout.n));
{

View File

@@ -957,37 +957,6 @@ bool EvalScript(
}
break;
/*
case OP_CHECKCRYPTOCONDITION:
case OP_CHECKCRYPTOCONDITIONVERIFY:
{
if (!IsCryptoConditionsEnabled()) {
goto INTERPRETER_DEFAULT;
}
if (stack.size() < 2)
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
//fprintf(stderr,"check cryptocondition\n");
int fResult = checker.CheckCryptoCondition(stacktop(-1), stacktop(-2), script, consensusBranchId);
if (fResult == -1) {
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
}
popstack(stack);
popstack(stack);
stack.push_back(fResult == 1 ? vchTrue : vchFalse);
if (opcode == OP_CHECKCRYPTOCONDITIONVERIFY)
{
if (fResult == 1)
popstack(stack);
else
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_VERIFY);
}
}
break;
*/
INTERPRETER_DEFAULT:
default:
@@ -1356,15 +1325,6 @@ bool TransactionSignatureChecker::CheckSig(
}
int TransactionSignatureChecker::CheckCryptoCondition(
const std::vector<unsigned char>& condBin,
const std::vector<unsigned char>& ffillBin,
const CScript& scriptCode,
uint32_t consensusBranchId) const
{
return 0;
}
bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) const
{
// There are two times of nLockTime: lock-by-blockheight
@@ -1407,38 +1367,6 @@ bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) con
return true;
}
/*
* Allow larger opcode in case of crypto condition scriptSig
*/
bool EvalCryptoConditionSig(
vector<vector<unsigned char> >& stack,
const CScript& scriptSig,
ScriptError* serror)
{
CScript::const_iterator pc = scriptSig.begin();
opcodetype opcode;
valtype vchPushValue;
set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
if (!scriptSig.GetOp(pc, opcode, vchPushValue))
return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
if (opcode == 0 || opcode > OP_PUSHDATA4)
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
if (pc != scriptSig.end())
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
if (vchPushValue.size() > MAX_SCRIPT_CRYPTOCONDITION_FULFILLMENT_SIZE)
return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
stack.push_back(vchPushValue);
return true;
}
bool VerifyScript(
const CScript& scriptSig,
const CScript& scriptPubKey,
@@ -1454,12 +1382,7 @@ bool VerifyScript(
}
vector<vector<unsigned char> > stack, stackCopy;
if (IsCryptoConditionsEnabled() && scriptPubKey.IsPayToCryptoCondition()) {
if (!EvalCryptoConditionSig(stack, scriptSig, serror))
// serror is set
return false;
}
else if (!EvalScript(stack, scriptSig, flags, checker, consensusBranchId, serror))
if (!EvalScript(stack, scriptSig, flags, checker, consensusBranchId, serror))
// serror is set
return false;
if (flags & SCRIPT_VERIFY_P2SH)

View File

@@ -147,15 +147,6 @@ public:
return false;
}
virtual int CheckCryptoCondition(
const std::vector<unsigned char>& condBin,
const std::vector<unsigned char>& ffillBin,
const CScript& scriptCode,
uint32_t consensusBranchId) const
{
return false;
}
virtual ~BaseSignatureChecker() {}
};
@@ -174,11 +165,6 @@ public:
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {}
bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, uint32_t consensusBranchId) const;
bool CheckLockTime(const CScriptNum& nLockTime) const;
int CheckCryptoCondition(
const std::vector<unsigned char>& condBin,
const std::vector<unsigned char>& ffillBin,
const CScript& scriptCode,
uint32_t consensusBranchId) const;
};
class MutableTransactionSignatureChecker : public TransactionSignatureChecker

View File

@@ -156,9 +156,6 @@ const char* GetOpName(opcodetype opcode)
case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY";
case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG";
case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY";
case OP_CHECKCRYPTOCONDITION : return "OP_CHECKCRYPTOCONDITION";
case OP_CHECKCRYPTOCONDITIONVERIFY
: return "OP_CHECKCRYPTOCONDITIONVERIFY";
// expansion
case OP_NOP1 : return "OP_NOP1";
@@ -382,12 +379,6 @@ bool CScript::MayAcceptCryptoCondition() const
bool CScript::IsCoinImport() const
{
const_iterator pc = this->begin();
vector<unsigned char> data;
opcodetype opcode;
if (this->GetOp(pc, opcode, data))
if (opcode > OP_0 && opcode <= OP_PUSHDATA4)
return data.begin()[0] == EVAL_IMPORTCOIN;
return false;
}

View File

@@ -40,9 +40,6 @@
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
// Max size of pushdata in a CC sig in bytes
static const unsigned int MAX_SCRIPT_CRYPTOCONDITION_FULFILLMENT_SIZE = 2048;
// Maximum script length in bytes
static const int MAX_SCRIPT_SIZE = 10000;
@@ -178,8 +175,6 @@ enum opcodetype
OP_CHECKSIGVERIFY = 0xad,
OP_CHECKMULTISIG = 0xae,
OP_CHECKMULTISIGVERIFY = 0xaf,
OP_CHECKCRYPTOCONDITION = 0xcc,
OP_CHECKCRYPTOCONDITIONVERIFY = 0xcd,
// expansion
OP_NOP1 = 0xb0,
@@ -200,7 +195,6 @@ enum opcodetype
OP_PUBKEYS = 0xfb,
OP_PUBKEYHASH = 0xfd,
OP_PUBKEY = 0xfe,
OP_CRYPTOCONDITION = 0xfc,
OP_INVALIDOPCODE = 0xff,
};

View File

@@ -83,8 +83,6 @@ const char* ScriptErrorString(const ScriptError serror)
return "NOPx reserved for soft-fork upgrades";
case SCRIPT_ERR_PUBKEYTYPE:
return "Public key is neither compressed or uncompressed";
case SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT:
return "Crypto-Condition payload is invalid";
case SCRIPT_ERR_UNKNOWN_ERROR:
case SCRIPT_ERR_ERROR_COUNT:
default: break;

View File

@@ -70,9 +70,6 @@ typedef enum ScriptError_t
SCRIPT_ERR_ERROR_COUNT,
/* crypto-condition script errors */
SCRIPT_ERR_CRYPTOCONDITION_VERIFY,
SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT
} ScriptError;
#define SCRIPT_ERR_LAST SCRIPT_ERR_ERROR_COUNT

View File

@@ -128,29 +128,6 @@ static bool SignN(const vector<valtype>& multisigdata, const BaseSignatureCreato
return nSigned==nRequired;
}
std::vector<CCcontract_info> &GetCryptoConditions()
{
static bool initialized = false;
static std::vector<CCcontract_info> vCC = std::vector<CCcontract_info>();
CCcontract_info C;
if (!initialized)
{
// this should initialize any desired auto-signed crypto-conditions
}
return vCC;
}
bool GetCCByUnspendableAddress(struct CCcontract_info *cp, char *addrstr)
{
return false;
}
bool CCinitLite(struct CCcontract_info *cp, uint8_t evalcode)
{
return false;
}
bool _Getscriptaddress(char *destaddr, const CScript &scriptPubKey)
{
CTxDestination address;
@@ -239,9 +216,6 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
}
return false;
case TX_CRYPTOCONDITION:
return SignStepCC(creator, scriptPubKey, vSolutions, ret, consensusBranchId);
case TX_MULTISIG:
ret.push_back(valtype()); // workaround CHECKMULTISIG bug
return (SignN(vSolutions, creator, scriptPubKey, ret, consensusBranchId));
@@ -429,11 +403,6 @@ static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignature
return sigs2;
case TX_PUBKEY:
case TX_PUBKEYHASH:
case TX_CRYPTOCONDITION:
// Signatures are bigger than placeholders or empty scripts:
if (sigs1.script.empty() || sigs1.script[0].empty())
return sigs2;
return sigs1;
case TX_SCRIPTHASH:
if (sigs1.script.empty() || sigs1.script.back().empty())
return sigs2;

View File

@@ -143,7 +143,6 @@ const char* GetTxnOutputType(txnouttype t)
case TX_SCRIPTHASH: return "scripthash";
case TX_MULTISIG: return "multisig";
case TX_NULL_DATA: return "nulldata";
case TX_CRYPTOCONDITION: return "cryptocondition";
default: return "invalid";
}
return NULL;
@@ -183,40 +182,6 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
return true;
}
if (IsCryptoConditionsEnabled()) {
// Shortcut for pay-to-crypto-condition
CScript ccSubScript = CScript();
std::vector<std::vector<unsigned char>> vParams;
if (scriptPubKey.IsPayToCryptoCondition(&ccSubScript, vParams))
{
if (scriptPubKey.MayAcceptCryptoCondition())
{
typeRet = TX_CRYPTOCONDITION;
vector<unsigned char> hashBytes; uint160 x; int32_t i; uint8_t hash20[20],*ptr;;
x = Hash160(ccSubScript);
memcpy(hash20,&x,20);
hashBytes.resize(20);
ptr = hashBytes.data();
for (i=0; i<20; i++)
ptr[i] = hash20[i];
vSolutionsRet.push_back(hashBytes);
if (vParams.size())
{
COptCCParams cp = COptCCParams(vParams[0]);
if (cp.IsValid())
{
for (auto k : cp.vKeys)
{
vSolutionsRet.push_back(std::vector<unsigned char>(k.begin(), k.end()));
}
}
}
return true;
}
return false;
}
}
// Scan templates
const CScript& script1 = scriptPubKey;
BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates)
@@ -328,8 +293,6 @@ int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned c
return vSolutions[0][0] + 1;
case TX_SCRIPTHASH:
return 1; // doesn't include args needed by the script
case TX_CRYPTOCONDITION:
return 1;
}
return -1;
}
@@ -404,21 +367,6 @@ bool ExtractDestination(const CScript& _scriptPubKey, CTxDestination& addressRet
addressRet = CScriptID(uint160(vSolutions[0]));
return true;
}
else if (IsCryptoConditionsEnabled() != 0 && whichType == TX_CRYPTOCONDITION)
{
if (vSolutions.size() > 1)
{
CPubKey pk = CPubKey((vSolutions[1]));
addressRet = pk;
return pk.IsValid();
}
else
{
addressRet = CKeyID(uint160(vSolutions[0]));
}
return true;
}
// Multisig txns have more than one address...
return false;
}
@@ -464,30 +412,7 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto
if (addressRet.empty())
return false;
}
// Removed to get CC address printed in getrawtransaction and decoderawtransaction
// else if (IsCryptoConditionsEnabled() != 0 && typeRet == TX_CRYPTOCONDITION)
// {
// nRequiredRet = vSolutions.front()[0];
// for (unsigned int i = 1; i < vSolutions.size()-1; i++)
// {
// CTxDestination address;
// if (vSolutions[i].size() == 20)
// {
// address = CKeyID(uint160(vSolutions[i]));
// }
// else
// {
// address = CPubKey(vSolutions[i]);
// }
// addressRet.push_back(address);
// }
// if (addressRet.empty())
// return false;
// }
else
{
} else {
nRequiredRet = 1;
CTxDestination address;
if (!ExtractDestination(scriptPubKey, address))

View File

@@ -75,7 +75,6 @@ enum txnouttype
TX_PUBKEYHASH,
TX_SCRIPTHASH,
TX_MULTISIG,
TX_CRYPTOCONDITION,
TX_NULL_DATA,
};

View File

@@ -456,7 +456,7 @@ uint32_t hush_segid32(char *coinaddr);
bool CBlockTreeDB::Snapshot2(std::map <std::string, CAmount> &addressAmounts, UniValue *ret)
{
int64_t total = 0; int64_t totalAddresses = 0; std::string address;
int64_t utxos = 0; int64_t ignoredAddresses = 0, cryptoConditionsUTXOs = 0, cryptoConditionsTotals = 0;
int64_t utxos = 0; int64_t ignoredAddresses = 0;
DECLARE_IGNORELIST
boost::scoped_ptr<CDBIterator> iter(NewIterator());
//std::map <std::string, CAmount> addressAmounts;
@@ -479,13 +479,7 @@ bool CBlockTreeDB::Snapshot2(std::map <std::string, CAmount> &addressAmounts, Un
if ( nValue == 0 )
continue;
getAddressFromIndex(indexKey.type, indexKey.hashBytes, address);
if ( indexKey.type == 3 )
{
cryptoConditionsUTXOs++;
cryptoConditionsTotals += nValue;
total += nValue;
continue;
}
std::map <std::string, int>::iterator ignored = ignoredMap.find(address);
if (ignored != ignoredMap.end())
{
@@ -540,12 +534,6 @@ bool CBlockTreeDB::Snapshot2(std::map <std::string, CAmount> &addressAmounts, Un
ret->push_back(make_pair("total_addresses", totalAddresses ));
// Total number of ignored addresses in this snaphot
ret->push_back(make_pair("ignored_addresses", ignoredAddresses));
// Total number of crypto condition utxos we skipped
ret->push_back(make_pair("skipped_cc_utxos", cryptoConditionsUTXOs));
// Total value of skipped crypto condition utxos
ret->push_back(make_pair("cc_utxo_value", (double) cryptoConditionsTotals / COIN));
// total of all the address's, does not count coins in CC vouts.
ret->push_back(make_pair("total_includeCCvouts", (double) (total+cryptoConditionsTotals)/ COIN ));
// The snapshot finished at this block height
ret->push_back(make_pair("ending_height", chainActive.Height()));
}

View File

@@ -120,13 +120,12 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
const CTransaction& tx = mapTx.find(hash)->GetTx();
mapRecentlyAddedTx[tx.GetHash()] = &tx;
nRecentlyAddedSequence += 1;
if (!tx.IsCoinImport()) {
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
//if (tx.IsPegsImport() && i==0) continue;
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
}
}
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
mapSaplingNullifiers[spendDescription.nullifier] = &tx;
}
@@ -157,14 +156,6 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
CTxDestination vDest;
if (Solver(prevout.scriptPubKey, txType, vSols) || ExtractDestination(prevout.scriptPubKey, vDest))
{
if (vDest.which())
{
uint160 hashBytes;
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType, prevout.scriptPubKey.IsPayToCryptoCondition()))
{
vSols.push_back(vector<unsigned char>(hashBytes.begin(), hashBytes.end()));
}
}
if (txType == TX_SCRIPTHASH)
{
keyType = 2;
@@ -191,11 +182,6 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
// if we failed to solve, and got a vDest, assume P2PKH or P2PK address returned
if (vDest.which())
{
uint160 hashBytes;
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType, out.scriptPubKey.IsPayToCryptoCondition()))
{
vSols.push_back(vector<unsigned char>(hashBytes.begin(), hashBytes.end()));
}
}
else if (txType == TX_SCRIPTHASH)
{

View File

@@ -1977,17 +1977,6 @@ isminetype CWallet::IsMine(const CTransaction& tx, uint32_t voutNum)
case TX_NULL_DATA:
break;
case TX_CRYPTOCONDITION:
// for now, default is that the first value returned will be the script, subsequent values will be
// pubkeys. if we have the first pub key in our wallet, we consider this spendable
if (vSolutions.size() > 1)
{
keyID = CPubKey(vSolutions[1]).GetID();
if (this->HaveKey(keyID))
return ISMINE_SPENDABLE;
}
break;
case TX_PUBKEY:
keyID = CPubKey(vSolutions[0]).GetID();
if (this->HaveKey(keyID))

View File

@@ -78,16 +78,6 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& _scriptPubKey)
case TX_NONSTANDARD:
case TX_NULL_DATA:
break;
case TX_CRYPTOCONDITION:
// for now, default is that the first value returned will be the script, subsequent values will be
// pubkeys. if we have the first pub key in our wallet, we consider this spendable
if (vSolutions.size() > 1)
{
keyID = CPubKey(vSolutions[1]).GetID();
if (keystore.HaveKey(keyID))
return ISMINE_SPENDABLE;
}
break;
case TX_PUBKEY:
keyID = CPubKey(vSolutions[0]).GetID();
if (keystore.HaveKey(keyID))