[BROKEN] Add CA validation

This commit is contained in:
Steven Roose 2019-03-19 20:39:56 +00:00
parent d53479c9ff
commit 0b5066143d
No known key found for this signature in database
GPG key ID: 7FC91380BB4CE800
23 changed files with 712 additions and 124 deletions

View file

@ -1519,6 +1519,11 @@ public:
::Serialize(s, (int)0);
else
::Serialize(s, txTo.vin[nInput].nSequence);
// Serialize the asset issuance object
if (!txTo.vin[nInput].assetIssuance.IsNull()) {
assert(g_con_elementsmode);
::Serialize(s, txTo.vin[nInput].assetIssuance);
}
}
/** Serialize an output of txTo */
@ -1571,6 +1576,19 @@ uint256 GetSequenceHash(const T& txTo)
return ss.GetHash();
}
template <class T>
uint256 GetIssuanceHash(const T& txTo)
{
CHashWriter ss(SER_GETHASH, 0);
for (const auto& txin : txTo.vin) {
if (txin.assetIssuance.IsNull())
ss << (unsigned char)0;
else
ss << txin.assetIssuance;
}
return ss.GetHash();
}
template <class T>
uint256 GetOutputsHash(const T& txTo)
{
@ -1590,6 +1608,7 @@ PrecomputedTransactionData::PrecomputedTransactionData(const T& txTo)
if (txTo.HasWitness()) {
hashPrevouts = GetPrevoutHash(txTo);
hashSequence = GetSequenceHash(txTo);
hashIssuance = GetIssuanceHash(txTo);
hashOutputs = GetOutputsHash(txTo);
ready = true;
}
@ -1600,13 +1619,14 @@ template PrecomputedTransactionData::PrecomputedTransactionData(const CTransacti
template PrecomputedTransactionData::PrecomputedTransactionData(const CMutableTransaction& txTo);
template <class T>
uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn, int nHashType, const CConfidentialValue& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
{
assert(nIn < txTo.vin.size());
if (sigversion == SigVersion::WITNESS_V0) {
uint256 hashPrevouts;
uint256 hashSequence;
uint256 hashIssuance;
uint256 hashOutputs;
const bool cacheready = cache && cache->ready;
@ -1618,6 +1638,9 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn
hashSequence = cacheready ? cache->hashSequence : GetSequenceHash(txTo);
}
if (!(nHashType & SIGHASH_ANYONECANPAY)) {
hashIssuance = cacheready ? cache->hashIssuance : GetIssuanceHash(txTo);
}
if ((nHashType & 0x1f) != SIGHASH_SINGLE && (nHashType & 0x1f) != SIGHASH_NONE) {
hashOutputs = cacheready ? cache->hashOutputs : GetOutputsHash(txTo);
@ -1633,13 +1656,24 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn
// Input prevouts/nSequence (none/all, depending on flags)
ss << hashPrevouts;
ss << hashSequence;
if (g_con_elementsmode) {
ss << hashIssuance;
}
// The input being signed (replacing the scriptSig with scriptCode + amount)
// The prevout may already be contained in hashPrevout, and the nSequence
// may already be contain in hashSequence.
ss << txTo.vin[nIn].prevout;
ss << scriptCode;
ss << amount;
if (g_con_elementsmode) {
ss << amount;
} else {
ss << amount.GetAmount();
}
ss << txTo.vin[nIn].nSequence;
if (!txTo.vin[nIn].assetIssuance.IsNull()) {
assert(g_con_elementsmode);
ss << txTo.vin[nIn].assetIssuance;
}
// Outputs (none/one/all, depending on flags)
ss << hashOutputs;
// Locktime