Refactor verifyamounts to accept all 4 (un)blinded configurations

This commit is contained in:
Gregory Sanders 2017-02-22 15:31:43 -08:00
parent 3836bad390
commit eccff6b060

View file

@ -682,55 +682,6 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
if (val.IsNull() || asset.IsNull())
return false;
if (val.IsAmount()) {
if (!MoneyRange(val.GetAmount()))
return false;
if (val.GetAmount() == 0)
continue;
if (asset.IsAssetID()) {
uint256 fixedAsset;
asset.GetAssetID(fixedAsset);
assert(secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &gen, fixedAsset.begin()));
}
else if (asset.IsAssetCommitment()) {
if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchAssetTag[0]) != 1)
return false;
}
else {
assert(false);
return false;
}
if (secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explBlinds, val.GetAmount(), &gen) != 1)
return false;
}
else
{
assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize);
if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1)
return false;
}
memcpy(p, &commit, sizeof(secp256k1_pedersen_commitment));
vpCommitsIn.push_back(p);
p++;
}
}
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 (val.vchNonceCommitment.size() > CTxOutValue::nCommittedSize || val.vchRangeproof.size() > 5000)
return false;
if (val.IsAmount()) {
if (!MoneyRange(val.GetAmount()))
return false;
if (asset.IsAssetID()) {
uint256 fixedAsset;
asset.GetAssetID(fixedAsset);
@ -745,24 +696,69 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
return false;
}
if (val.IsAmount()) {
if (!MoneyRange(val.GetAmount()))
return false;
if (val.GetAmount() == 0)
continue;
if (secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explBlinds, val.GetAmount(), &gen) != 1)
return false;
}
else {
assert(val.vchCommitment.size() == CTxOutValue::nCommittedSize);
if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1)
return false;
}
memcpy(p, &commit, sizeof(secp256k1_pedersen_commitment));
vpCommitsIn.push_back(p);
p++;
}
}
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 (val.vchNonceCommitment.size() > CTxOutValue::nCommittedSize || val.vchRangeproof.size() > 5000)
return false;
if (asset.IsAssetID()) {
uint256 fixedAsset;
asset.GetAssetID(fixedAsset);
assert(secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &gen, fixedAsset.begin()));
}
else if (asset.IsAssetCommitment()) {
if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchAssetTag[0]) != 1)
return false;
}
else {
assert(false);
return false;
}
if (val.IsAmount()) {
if (!MoneyRange(val.GetAmount()))
return false;
if (val.GetAmount() == 0)
continue;
if (secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explBlinds, val.GetAmount(), &gen) != 1)
return false;
}
else
{
if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &val.vchCommitment[0]) != 1)
return false;
}
memcpy(p, &commit, sizeof(secp256k1_pedersen_commitment));
vpCommitsOut.push_back(p);
p++;
}
// Check balance