Complete nothing at stake solution, waiting for confirm of masks

This commit is contained in:
miketout
2018-10-06 21:28:51 -07:00
parent a1fd99cf34
commit 191f3bbddd
16 changed files with 227 additions and 139 deletions

View File

@@ -232,7 +232,7 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode)
strcpy(cp->normaladdr,AssetsNormaladdr);
strcpy(cp->CChexstr,AssetsCChexstr);
memcpy(cp->CCpriv,AssetsCCpriv,32);
cp->validate = AssetsValidate;
cp->validate = CoinbaseGuardValidate;
cp->ismyvin = IsAssetsInput;
break;

View File

@@ -196,7 +196,7 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey)
strcpy(destaddr,(char *)CBitcoinAddress(address).ToString().c_str());
return(true);
}
fprintf(stderr,"Solver for scriptPubKey failed\n%s\n", scriptPubKey.ToString());
fprintf(stderr,"Solver for scriptPubKey failed\n%s\n", scriptPubKey.ToString().c_str());
return(false);
}
@@ -206,7 +206,7 @@ bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
uint256 blockHash;
bool isValid = false;
if (myGetTransaction(tx.vin[nIn].prevout.hash, txOut, blockHash))
if (myGetTransaction(tx.vin[nIn].prevout.hash, txOut, blockHash) && txOut.vout.size() > nIn)
{
CBlockIndex index;
if (eval->GetBlock(blockHash, index))
@@ -218,7 +218,10 @@ bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
{
// read any available parameters in the output transaction
params.clear();
tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params);
if (tx.vout.size() > 0 && tx.vout[tx.vout.size() - 1].scriptPubKey.IsOpReturn())
{
tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params);
}
isValid = true;
}
}
@@ -388,8 +391,8 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> param
cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0;
if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params");
else if ( ctx.vout.size() == 0 )
return eval->Invalid("no-vouts");
//else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses
// return eval->Invalid("no-vouts");
else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 )
{
//fprintf(stderr,"done CC %02x\n",cp->evalcode);

View File

@@ -168,8 +168,7 @@ bool ValidateStakeTransaction(const CTransaction &stakeTx, CStakeParams &stakePa
if (!validateSig || VerifyScript(stakeTx.vin[0].scriptSig,
srcTx.vout[stakeTx.vin[0].prevout.n].scriptPubKey,
MANDATORY_SCRIPT_VERIFY_FLAGS,
TransactionSignatureChecker(&stakeTx, 0, srcTx.vout[stakeTx.vin[0].prevout.n].nValue,
PrecomputedTransactionData(stakeTx)),
ServerTransactionSignatureChecker(&stakeTx, (uint32_t)0, srcTx.vout[stakeTx.vin[0].prevout.n].nValue, false),
consensusBranchId))
{
return true;
@@ -305,6 +304,34 @@ bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint3
}
}
typedef struct ccFulfillmentCheck {
int32_t childCount;
uint64_t fulfillmentMask;
} ccFulfillmentCheck;
int IsCCFulfilled(CC *cc, ccFulfillmentCheck *ctx);
// to figure out which node is signed
int CCFulfillmentVisitor(CC *cc, struct CCVisitor visitor)
{
ccFulfillmentCheck *pfc = (ccFulfillmentCheck *)(visitor.context);
int fulfilled = cc_isFulfilled(cc);
pfc->fulfillmentMask |= (fulfilled == 0) ? 0 : ((uint64_t)1) << (uint64_t)pfc->childCount;
printf("fullfilled: %x, pfc->fulfillmentMask: %x, pfc->childCount: %d\n", fulfilled, pfc->fulfillmentMask, pfc->childCount);
pfc->childCount++;
return fulfilled;
}
int IsCCFulfilled(CC *cc, ccFulfillmentCheck *ctx)
{
int fulfilled = cc_isFulfilled(cc);
// printf("Root IsFulfilled: %x\n", fulfilled);
struct CCVisitor visitor = {&CCFulfillmentVisitor, NULL, 0, (void *)ctx};
cc_visit(cc, visitor);
return fulfilled;
}
bool CoinbaseGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn)
{
// This also supports a variable blockstomaturity option for backward feature compatibility
@@ -321,15 +348,19 @@ bool CoinbaseGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransa
std::vector<std::vector<unsigned char>> params = std::vector<std::vector<unsigned char>>();
CTransaction txOut;
CC *cc = GetCryptoCondition(tx.vin[nIn].scriptSig);
// this should reflect the truth of whether the first key did sign the fulfillment
bool signedByFirstKey = true;
bool signedByFirstKey = false;
bool validCheat = false;
CC *cc = GetCryptoCondition(tx.vin[nIn].scriptSig);
if (cc)
{
printf("CryptoCondition code %x\n", *cc->code);
ccFulfillmentCheck fc = {0, 0};
IsCCFulfilled(cc, &fc);
// this should reflect the truth of whether the first key did sign the fulfillment
signedByFirstKey = ((fc.fulfillmentMask & (uint64_t)4) != 0);
validCheat = false;
// tx is the spending tx, the cc transaction comes back in txOut
if (GetCCParams(eval, tx, nIn, txOut, preConditions, params))