Browse Source

Update stake cheat spend

pull/4/head
Michael Toutonghi 6 years ago
parent
commit
60b798c4b7
  1. 16
      src/cc/CCutils.cpp
  2. 6
      src/cc/StakeGuard.cpp
  3. 53
      src/script/script.cpp
  4. 1
      src/script/script.h

16
src/cc/CCutils.cpp

@ -204,7 +204,6 @@ bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> &params)
{
uint256 blockHash;
bool isValid = false;
if (myGetTransaction(tx.vin[nIn].prevout.hash, txOut, blockHash) && txOut.vout.size() > tx.vin[nIn].prevout.n)
{
@ -220,22 +219,23 @@ bool GetCCParams(Eval* eval, const CTransaction &tx, uint32_t nIn,
params.clear();
if (tx.vout.size() > 0 && tx.vout[tx.vout.size() - 1].scriptPubKey.IsOpReturn())
{
tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params);
if (params.size() == 1)
if (tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params) && params.size() == 1)
{
CScript scr = CScript(params[0]);
if (scr.IsOpReturn())
// printf("Stake cheat parameter opret:\n%s\n", scr.ToString().c_str());
if (!scr.GetPushedData(scr.begin(), params))
{
params.clear();
scr.GetOpretData(params);
return false;
}
else return true;
}
else return false;
}
isValid = true;
else return true;
}
}
}
return isValid;
return false;
}
CPubKey CCtxidaddr(char *txidaddr,uint256 txid)

6
src/cc/StakeGuard.cpp

@ -286,7 +286,6 @@ bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTr
// this attaches an opret to a mutable transaction that provides the necessary evidence of a signed, cheating stake transaction
bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint32_t voutNum, const CTransaction &cheatTx)
{
std::vector<unsigned char> vch;
CDataStream s = CDataStream(SER_DISK, CLIENT_VERSION);
bool isCheater = false;
@ -298,7 +297,7 @@ bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint3
CScript vData = CScript();
cheatTx.Serialize(s);
vch = std::vector<unsigned char>(s.begin(), s.end());
vData << OPRETTYPE_STAKECHEAT << vch;
vData << ((int64_t)OPRETTYPE_STAKECHEAT) << vch;
vOut.scriptPubKey << OP_RETURN << std::vector<unsigned char>(vData.begin(), vData.end());
vOut.nValue = 0;
mtx.vout.push_back(vOut);
@ -396,7 +395,8 @@ bool StakeGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransacti
signedByFirstKey = (IsCCFulfilled(cc, &fc) != 0);
if (!(signedByFirstKey = (vc[0] != 0)) && params.size() == 2 && params[0].size() > 0 && params[0][0] == OPRETTYPE_STAKECHEAT)
if ((!signedByFirstKey && ccp.evalCode == EVAL_STAKEGUARD && ccp.vKeys.size() == 2 && ccp.version == COptCCParams::VERSION) &&
params.size() == 2 && params[0].size() > 0 && params[0][0] == OPRETTYPE_STAKECHEAT)
{
CDataStream s = CDataStream(std::vector<unsigned char>(params[1].begin(), params[1].end()), SER_DISK, CLIENT_VERSION);
bool checkOK = false;

53
src/script/script.cpp

@ -297,39 +297,52 @@ bool CScript::GetBalancedData(const_iterator& pc, std::vector<std::vector<unsign
// this returns true if either there is nothing left and pc points at the end
// if there is data, it also returns all the values as byte vectors in a list of vectors
bool CScript::GetOpretData(std::vector<std::vector<unsigned char>>& vData) const
bool CScript::GetPushedData(CScript::const_iterator pc, std::vector<std::vector<unsigned char>>& vData) const
{
vector<unsigned char> data;
opcodetype opcode;
CScript::const_iterator pc = this->begin();
std::vector<unsigned char> vch1 = std::vector<unsigned char>(1);
vData.clear();
if (GetOp(pc, opcode, data) && opcode == OP_RETURN)
while (pc < end())
{
while (pc < end())
if (GetOp(pc, opcode, data))
{
if (GetOp(pc, opcode, data))
if (opcode == OP_0)
{
if (opcode == OP_0)
{
vch1[0] = 0;
vData.push_back(vch1);
}
else if (opcode >= OP_1 && opcode <= OP_16)
{
vch1[0] = (opcode - OP_1) + 1;
vData.push_back(data);
}
else
{
vData.push_back(data);
}
vch1[0] = 0;
vData.push_back(vch1);
}
else if (opcode >= OP_1 && opcode <= OP_16)
{
vch1[0] = (opcode - OP_1) + 1;
vData.push_back(vch1);
}
else if (opcode > 0 && opcode <= OP_PUSHDATA4 && data.size() > 0)
{
vData.push_back(data);
}
else
return false;
}
return vData.size() != 0;
}
return vData.size() != 0;
}
// this returns true if either there is nothing left and pc points at the end
// if there is data, it also returns all the values as byte vectors in a list of vectors
bool CScript::GetOpretData(std::vector<std::vector<unsigned char>>& vData) const
{
vector<unsigned char> data;
opcodetype opcode;
CScript::const_iterator pc = this->begin();
if (GetOp(pc, opcode, data) && opcode == OP_RETURN)
{
return GetPushedData(pc, vData);
}
else return false;
}
bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector<std::vector<unsigned char>>& vParams) const

1
src/script/script.h

@ -577,6 +577,7 @@ public:
bool IsPayToPublicKey() const;
bool IsPayToScriptHash() const;
bool GetPushedData(CScript::const_iterator pc, std::vector<std::vector<unsigned char>>& vData) const;
bool IsOpReturn() const { return size() > 0 && (*this)[0] == OP_RETURN; }
bool GetOpretData(std::vector<std::vector<unsigned char>>& vData) const;

Loading…
Cancel
Save