Update stake cheat spend
This commit is contained in:
@@ -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>> ¶ms)
|
CTransaction &txOut, std::vector<std::vector<unsigned char>> &preConditions, std::vector<std::vector<unsigned char>> ¶ms)
|
||||||
{
|
{
|
||||||
uint256 blockHash;
|
uint256 blockHash;
|
||||||
bool isValid = false;
|
|
||||||
|
|
||||||
if (myGetTransaction(tx.vin[nIn].prevout.hash, txOut, blockHash) && txOut.vout.size() > tx.vin[nIn].prevout.n)
|
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();
|
params.clear();
|
||||||
if (tx.vout.size() > 0 && tx.vout[tx.vout.size() - 1].scriptPubKey.IsOpReturn())
|
if (tx.vout.size() > 0 && tx.vout[tx.vout.size() - 1].scriptPubKey.IsOpReturn())
|
||||||
{
|
{
|
||||||
tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params);
|
if (tx.vout[tx.vout.size() - 1].scriptPubKey.GetOpretData(params) && params.size() == 1)
|
||||||
if (params.size() == 1)
|
|
||||||
{
|
{
|
||||||
CScript scr = CScript(params[0]);
|
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();
|
return false;
|
||||||
scr.GetOpretData(params);
|
|
||||||
}
|
}
|
||||||
|
else return true;
|
||||||
}
|
}
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
isValid = true;
|
else return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isValid;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPubKey CCtxidaddr(char *txidaddr,uint256 txid)
|
CPubKey CCtxidaddr(char *txidaddr,uint256 txid)
|
||||||
|
|||||||
@@ -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
|
// 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)
|
bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint32_t voutNum, const CTransaction &cheatTx)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<unsigned char> vch;
|
std::vector<unsigned char> vch;
|
||||||
CDataStream s = CDataStream(SER_DISK, CLIENT_VERSION);
|
CDataStream s = CDataStream(SER_DISK, CLIENT_VERSION);
|
||||||
bool isCheater = false;
|
bool isCheater = false;
|
||||||
@@ -298,7 +297,7 @@ bool MakeCheatEvidence(CMutableTransaction &mtx, const CTransaction &ccTx, uint3
|
|||||||
CScript vData = CScript();
|
CScript vData = CScript();
|
||||||
cheatTx.Serialize(s);
|
cheatTx.Serialize(s);
|
||||||
vch = std::vector<unsigned char>(s.begin(), s.end());
|
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.scriptPubKey << OP_RETURN << std::vector<unsigned char>(vData.begin(), vData.end());
|
||||||
vOut.nValue = 0;
|
vOut.nValue = 0;
|
||||||
mtx.vout.push_back(vOut);
|
mtx.vout.push_back(vOut);
|
||||||
@@ -396,7 +395,8 @@ bool StakeGuardValidate(struct CCcontract_info *cp, Eval* eval, const CTransacti
|
|||||||
|
|
||||||
signedByFirstKey = (IsCCFulfilled(cc, &fc) != 0);
|
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);
|
CDataStream s = CDataStream(std::vector<unsigned char>(params[1].begin(), params[1].end()), SER_DISK, CLIENT_VERSION);
|
||||||
bool checkOK = false;
|
bool checkOK = false;
|
||||||
|
|||||||
@@ -295,6 +295,41 @@ bool CScript::GetBalancedData(const_iterator& pc, std::vector<std::vector<unsign
|
|||||||
return netPushes == 0;
|
return netPushes == 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::GetPushedData(CScript::const_iterator pc, std::vector<std::vector<unsigned char>>& vData) const
|
||||||
|
{
|
||||||
|
vector<unsigned char> data;
|
||||||
|
opcodetype opcode;
|
||||||
|
std::vector<unsigned char> vch1 = std::vector<unsigned char>(1);
|
||||||
|
|
||||||
|
vData.clear();
|
||||||
|
|
||||||
|
while (pc < end())
|
||||||
|
{
|
||||||
|
if (GetOp(pc, opcode, data))
|
||||||
|
{
|
||||||
|
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(vch1);
|
||||||
|
}
|
||||||
|
else if (opcode > 0 && opcode <= OP_PUSHDATA4 && data.size() > 0)
|
||||||
|
{
|
||||||
|
vData.push_back(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vData.size() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
// this returns true if either there is nothing left and pc points at the end
|
// 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
|
// 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::GetOpretData(std::vector<std::vector<unsigned char>>& vData) const
|
||||||
@@ -302,34 +337,12 @@ bool CScript::GetOpretData(std::vector<std::vector<unsigned char>>& vData) const
|
|||||||
vector<unsigned char> data;
|
vector<unsigned char> data;
|
||||||
opcodetype opcode;
|
opcodetype opcode;
|
||||||
CScript::const_iterator pc = this->begin();
|
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)
|
if (GetOp(pc, opcode, data) && opcode == OP_RETURN)
|
||||||
{
|
{
|
||||||
while (pc < end())
|
return GetPushedData(pc, vData);
|
||||||
{
|
|
||||||
if (GetOp(pc, opcode, data))
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return vData.size() != 0;
|
|
||||||
}
|
}
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector<std::vector<unsigned char>>& vParams) const
|
bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector<std::vector<unsigned char>>& vParams) const
|
||||||
|
|||||||
@@ -577,6 +577,7 @@ public:
|
|||||||
bool IsPayToPublicKey() const;
|
bool IsPayToPublicKey() const;
|
||||||
|
|
||||||
bool IsPayToScriptHash() 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 IsOpReturn() const { return size() > 0 && (*this)[0] == OP_RETURN; }
|
||||||
bool GetOpretData(std::vector<std::vector<unsigned char>>& vData) const;
|
bool GetOpretData(std::vector<std::vector<unsigned char>>& vData) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user