mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
CT/CA: Unify CTxOutAsset and CTxOutValue into a single templated abstract base class
This commit is contained in:
parent
9ebe6371a1
commit
a2c0f11f8e
21 changed files with 163 additions and 234 deletions
|
|
@ -572,14 +572,14 @@ static Secp256k1Ctx instance_of_secp256k1ctx;
|
|||
class CRangeCheck : public CCheck
|
||||
{
|
||||
private:
|
||||
const CTxOutValue* val;
|
||||
const CConfidentialValue* val;
|
||||
const std::vector<unsigned char>& rangeproof;
|
||||
const CTxOutAsset* asset;
|
||||
const CConfidentialAsset* asset;
|
||||
const CScript* scriptPubKey;
|
||||
const bool store;
|
||||
|
||||
public:
|
||||
CRangeCheck(const CTxOutValue* val_, const std::vector<unsigned char>& rangeproof_, const CTxOutAsset* asset_, const CScript* scriptPubKey_, const bool storeIn) : val(val_), rangeproof(rangeproof_), asset(asset_), scriptPubKey(scriptPubKey_), store(storeIn) {}
|
||||
CRangeCheck(const CConfidentialValue* val_, const std::vector<unsigned char>& rangeproof_, const CConfidentialAsset* asset_, const CScript* scriptPubKey_, const bool storeIn) : val(val_), rangeproof(rangeproof_), asset(asset_), scriptPubKey(scriptPubKey_), store(storeIn) {}
|
||||
|
||||
bool operator()();
|
||||
};
|
||||
|
|
@ -678,8 +678,8 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
for (size_t i = 0; i < tx.vin.size(); ++i)
|
||||
{
|
||||
const CTxOut out = cache.GetOutputFor(tx.vin[i]);
|
||||
const CTxOutValue& val = out.nValue;
|
||||
const CTxOutAsset& asset = out.nAsset;
|
||||
const CConfidentialValue& val = out.nValue;
|
||||
const CConfidentialAsset& asset = out.nAsset;
|
||||
|
||||
if (val.IsNull() || asset.IsNull())
|
||||
return false;
|
||||
|
|
@ -708,7 +708,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
return false;
|
||||
}
|
||||
else {
|
||||
assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize);
|
||||
assert(val.vchCommitment.size() == CConfidentialValue::nCommittedSize);
|
||||
if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1)
|
||||
return false;
|
||||
}
|
||||
|
|
@ -720,11 +720,11 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
}
|
||||
for (size_t i = 0; i < tx.vout.size(); ++i)
|
||||
{
|
||||
const CTxOutValue& val = tx.vout[i].nValue;
|
||||
const CTxOutAsset& asset = tx.vout[i].nAsset;
|
||||
assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize ||
|
||||
val.vchCommitment.size() == CTxOutValue::nExplicitSize);
|
||||
if (tx.vout[i].vchNonceCommitment.size() > CTxOutValue::nCommittedSize || tx.vout[i].vchRangeproof.size() > 5000)
|
||||
const CConfidentialValue& val = tx.vout[i].nValue;
|
||||
const CConfidentialAsset& asset = tx.vout[i].nAsset;
|
||||
assert(val.vchCommitment.size() == CConfidentialValue::nCommittedSize ||
|
||||
val.vchCommitment.size() == CConfidentialValue::nExplicitSize);
|
||||
if (tx.vout[i].vchNonceCommitment.size() > 33 || tx.vout[i].vchRangeproof.size() > 5000)
|
||||
return false;
|
||||
|
||||
if (asset.IsExplicit()) {
|
||||
|
|
@ -768,7 +768,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
|
||||
// Range proofs
|
||||
for (size_t i = 0; i < tx.vout.size(); i++) {
|
||||
const CTxOutValue& val = tx.vout[i].nValue;
|
||||
const CConfidentialValue& val = tx.vout[i].nValue;
|
||||
if (val.IsExplicit())
|
||||
continue;
|
||||
if (!QueueCheck(pvChecks, new CRangeCheck(&val, tx.vout[i].vchRangeproof, &tx.vout[i].nAsset, &tx.vout[i].scriptPubKey, cacheStore))) {
|
||||
|
|
@ -783,7 +783,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
|
||||
for (size_t i = 0; i < tx.vin.size(); i++)
|
||||
{
|
||||
const CTxOutAsset& asset = cache.GetOutputFor(tx.vin[i]).nAsset;
|
||||
const CConfidentialAsset& asset = cache.GetOutputFor(tx.vin[i]).nAsset;
|
||||
if (asset.IsExplicit()) {
|
||||
ret = secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &ephemeral_input_tags[i], asset.GetAsset().begin());
|
||||
assert(ret != 0);
|
||||
|
|
@ -798,7 +798,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
|
|||
|
||||
for (size_t i = 0; i < tx.vout.size(); i++)
|
||||
{
|
||||
const CTxOutAsset& asset = tx.vout[i].nAsset;
|
||||
const CConfidentialAsset& asset = tx.vout[i].nAsset;
|
||||
//No need for surjective proof
|
||||
if (asset.IsExplicit()) {
|
||||
assert(tx.vout[i].vchSurjectionproof.size() == 0);
|
||||
|
|
@ -1851,7 +1851,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
|
|||
}
|
||||
|
||||
// Check for negative or overflow input values
|
||||
const CTxOutValue& value = coins->vout[prevout.n].nValue;
|
||||
const CConfidentialValue& value = coins->vout[prevout.n].nValue;
|
||||
if (value.IsExplicit()) {
|
||||
nValueIn += value.GetAmount();
|
||||
if (!MoneyRange(value.GetAmount()) || !MoneyRange(nValueIn))
|
||||
|
|
@ -1986,7 +1986,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
|
|||
else
|
||||
return state.DoS(100,false, REJECT_INVALID, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(serror)));
|
||||
}
|
||||
const CTxOutValue& value = coins->vout[tx.vin[i].prevout.n].nValue;
|
||||
const CConfidentialValue& value = coins->vout[tx.vin[i].prevout.n].nValue;
|
||||
if (value.IsExplicit())
|
||||
prevValueIn = value.GetAmount();
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue