Forbid explicit issuance of 0 asset units

The proper way to issue 0 units of an asset is a null commitment but not
an explicit commitment to 0.

This commit eliminates the issue that some checks in the verification of
the issuance of re-issuance tokes were skipped when issuing 0 asset units
explicitly. This commit also simplifies the control flow of the relevant
code locations.
This commit is contained in:
Tim Ruffing 2018-05-18 20:12:57 +02:00
parent bef2760352
commit e183868516

View file

@ -805,46 +805,44 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve
}
// Process issuance of asset
if (!issuance.nAmount.IsNull()) {
if (!issuance.nAmount.IsValid()) {
return false;
}
if (!issuance.nAmount.IsNull()) {
// Generate asset generator and add to list of surjection targets
ret = secp256k1_generator_generate(secp256k1_ctx_verify_amounts, &gen, assetID.begin());
assert(ret == 1);
CConfidentialAsset issuanceAsset;
issuanceAsset.vchCommitment.resize(CConfidentialAsset::nCommittedSize);
secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, &issuanceAsset.vchCommitment[0], &gen);
targetGenerators.push_back(gen);
// Build value commitment and add to tally
if (issuance.nAmount.IsExplicit()) {
if (!MoneyRange(issuance.nAmount.GetAmount())) {
if (!MoneyRange(issuance.nAmount.GetAmount()) || issuance.nAmount.GetAmount() == 0) {
return false;
}
if (issuance.nAmount.GetAmount() == 0) {
continue;
}
ret = secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explBlinds, issuance.nAmount.GetAmount(), &gen);
// The explBlinds are all 0, and the amount is not 0. So secp256k1_pedersen_commit does not fail.
assert(ret == 1);
}
else if (issuance.nAmount.IsCommitment()) {
else {
assert(issuance.nAmount.IsCommitment());
// Verify range proof
std::vector<unsigned char> vchAssetCommitment(CConfidentialAsset::nExplicitSize);
secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, &vchAssetCommitment[0], &gen);
if (QueueCheck(pvChecks, new CRangeCheck(&issuance.nAmount, tx.wit.vtxinwit[i].vchIssuanceAmountRangeproof, vchAssetCommitment, CScript(), cacheStore)) != SCRIPT_ERR_OK) {
return false;
}
// Here we have issuance.nAmount.IsCommitment() == true
if (secp256k1_pedersen_commitment_parse(secp256k1_ctx_verify_amounts, &commit, &issuance.nAmount.vchCommitment[0]) != 1) {
return false;
}
} else {
return false;
}
vData.push_back(commit);
vpCommitsIn.push_back(p);
p++;
// Rangecheck must be done for blinded amount
if (issuance.nAmount.IsCommitment() && QueueCheck(pvChecks, new CRangeCheck(&issuance.nAmount, tx.wit.vtxinwit[i].vchIssuanceAmountRangeproof, issuanceAsset.vchCommitment, CScript(), cacheStore)) != SCRIPT_ERR_OK) {
return false;
}
}
// Only initial issuance can have reissuance tokens