Verus Proof of Stake Compete with Additional ant-fork protection on block 1

This commit is contained in:
Michael Toutonghi
2018-05-13 18:59:06 -07:00
parent 6939648e84
commit 1f722359c1
20 changed files with 458 additions and 53 deletions

View File

@@ -9,6 +9,7 @@
#include "primitives/transaction.h"
#include "serialize.h"
#include "uint256.h"
#include "arith_uint256.h"
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
@@ -88,6 +89,41 @@ public:
{
return (int64_t)nTime;
}
int32_t GetVerusPOSTarget() const
{
uint32_t nBits = 0;
for (const unsigned char *p = nNonce.begin() + 3; p >= nNonce.begin(); p--)
{
nBits += *p;
nBits <<= 8;
}
return nBits;
}
bool isVerusPOSBlock() const
{
arith_uint256 arNonce = UintToArith256(nNonce);
arith_uint256 tmpNonce = ((arNonce << 128) >> 128);
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
hashWriter << ArithToUint256(tmpNonce);
return (nNonce == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce));
}
void SetVerusPOSTarget(int32_t nBits)
{
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
uint256 hash;
arith_uint256 tmpNonce;
arith_uint256 arNonce = UintToArith256(nNonce);
arNonce = ((arNonce >> 32) << 32) | nBits;
tmpNonce = ((arNonce << 128) >> 128);
hashWriter << ArithToUint256(tmpNonce);
nNonce = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce);
}
};
@@ -108,7 +144,6 @@ public:
CBlock(const CBlockHeader &header)
{
SetNull();
*((CBlockHeader*)this) = header;
}
ADD_SERIALIZE_METHODS;

View File

@@ -12,6 +12,7 @@
#include "serialize.h"
#include "uint256.h"
#include "consensus/consensus.h"
#include "hash.h"
#ifndef __APPLE__
#include <stdint.h>
@@ -24,6 +25,8 @@
#include "zcash/JoinSplit.hpp"
#include "zcash/Proof.hpp"
extern uint32_t ASSETCHAINS_MAGIC;
class JSDescription
{
public:
@@ -469,6 +472,28 @@ public:
return a.hash != b.hash;
}
// verus hash will be the same for a given txid, output number, block height, and blockhash of 100 blocks past
static uint256 _GetVerusPOSHash(const uint256 &txid, int32_t voutNum, int32_t height, const uint256 &pastHash, int64_t value)
{
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
hashWriter << ASSETCHAINS_MAGIC;
hashWriter << pastHash;
hashWriter << height;
hashWriter << txid;
hashWriter << voutNum;
return hashWriter.GetHash();
}
uint256 GetVerusPOSHash(int32_t voutNum, int32_t height, const uint256 &pastHash) const
{
uint256 txid = GetHash();
if (voutNum >= vout.size())
return uint256();
return _GetVerusPOSHash(txid, voutNum, height, pastHash, (uint64_t)vout[voutNum].nValue);
}
std::string ToString() const;
};