From 185b2d4f2faa843600ef495d2af3d7fec327f939 Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 5 Oct 2018 17:20:23 -0700 Subject: [PATCH] move things around and some debugging code for odd issues --- src/cc/CoinbaseGuard.cpp | 7 +++++-- src/cc/CoinbaseGuard.h | 39 --------------------------------------- src/komodo_bitcoind.h | 16 ++++++++++++++++ src/script/standard.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 41 deletions(-) diff --git a/src/cc/CoinbaseGuard.cpp b/src/cc/CoinbaseGuard.cpp index 0b6f7b049..3db0d835e 100644 --- a/src/cc/CoinbaseGuard.cpp +++ b/src/cc/CoinbaseGuard.cpp @@ -255,10 +255,13 @@ bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTr uint256 utxo = hw.GetHash(); uint32_t height = 0; - for (int i = 0; i < ccp.vData[2].size(); i++) + int i, dataLen = ccp.vData[2].size(); + for (i = dataLen - 1; i >= 0; i--) { - height = height << 8 + ccp.vData[2][i]; + height = (height << 8) + ccp.vData[2][i]; } + // strange issue + printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen); if (utxo == uint256(ccp.vData[0])) { diff --git a/src/cc/CoinbaseGuard.h b/src/cc/CoinbaseGuard.h index 625d97e5b..a36f8476a 100644 --- a/src/cc/CoinbaseGuard.h +++ b/src/cc/CoinbaseGuard.h @@ -20,45 +20,6 @@ #define DEFAULT_STAKE_TXFEE 0 -class CStakeParams -{ - public: - static const uint32_t STAKE_MINPARAMS = 4; - static const uint32_t STAKE_MAXPARAMS = 5; - - uint32_t srcHeight; - uint32_t blkHeight; - uint256 prevHash; - CPubKey pk; - - CStakeParams() : srcHeight(0), blkHeight(0), prevHash(), pk() {} - - CStakeParams(const std::vector> &vData); - - CStakeParams(uint32_t _srcHeight, uint32_t _blkHeight, const uint256 &_prevHash, const CPubKey &_pk) : - srcHeight(_srcHeight), blkHeight(_blkHeight), prevHash(_prevHash), pk(_pk) {} - - std::vector AsVector() - { - std::vector ret; - CScript scr = CScript(); - scr << OPRETTYPE_STAKEPARAMS; - scr << srcHeight; - scr << blkHeight; - scr << std::vector(prevHash.begin(), prevHash.end()); - - if (pk.IsValid()) - { - scr << std::vector(pk.begin(), pk.end()); - } - - ret = std::vector(scr.begin(), scr.end()); - return ret; - } - - bool IsValid() { return srcHeight != 0; } -}; - bool UnpackStakeOpRet(const CTransaction &stakeTx, std::vector> &vData); bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6d3863f06..f6e96fc28 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -20,6 +20,7 @@ #include "primitives/nonce.h" #include "consensus/params.h" #include "komodo_defs.h" +#include "script/standard.h" int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); @@ -1454,6 +1455,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ return(isPoS != 0); } +bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams); bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating); // for now, we will ignore slowFlag in the interest of keeping success/fail simpler for security purposes @@ -1510,6 +1512,20 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) { validHash = false; } + else + { + // make sure prev block hash and block height are correct + CStakeParams p; + if (validHash = GetStakeParams(pblock->vtx[txn_count-1], p)) + { + if (p.prevHash != pblock->hashPrevBlock || p.blkHeight != height) + { + printf("ERROR: invalid block data for stake tx\nblkHash: %s\ntxBlkHash: %s\nblkHeight: %d\ntxBlkHeight: %d\n", + pblock->hashPrevBlock.GetHex().c_str(), p.prevHash.GetHex().c_str(), height, p.blkHeight); + validHash = false; + } + } + } } } if (validHash) diff --git a/src/script/standard.h b/src/script/standard.h index 561f09cd8..8536b56df 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -106,6 +106,45 @@ class COptCCParams std::vector AsVector(); }; +class CStakeParams +{ + public: + static const uint32_t STAKE_MINPARAMS = 4; + static const uint32_t STAKE_MAXPARAMS = 5; + + uint32_t srcHeight; + uint32_t blkHeight; + uint256 prevHash; + CPubKey pk; + + CStakeParams() : srcHeight(0), blkHeight(0), prevHash(), pk() {} + + CStakeParams(const std::vector> &vData); + + CStakeParams(uint32_t _srcHeight, uint32_t _blkHeight, const uint256 &_prevHash, const CPubKey &_pk) : + srcHeight(_srcHeight), blkHeight(_blkHeight), prevHash(_prevHash), pk(_pk) {} + + std::vector AsVector() + { + std::vector ret; + CScript scr = CScript(); + scr << OPRETTYPE_STAKEPARAMS; + scr << srcHeight; + scr << blkHeight; + scr << std::vector(prevHash.begin(), prevHash.end()); + + if (pk.IsValid()) + { + scr << std::vector(pk.begin(), pk.end()); + } + + ret = std::vector(scr.begin(), scr.end()); + return ret; + } + + bool IsValid() { return srcHeight != 0; } +}; + /** Check whether a CTxDestination is a CNoDestination. */ bool IsValidDestination(const CTxDestination& dest);