diff --git a/src/validation.cpp b/src/validation.cpp index 0c50c82f0c..7c34c18cab 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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 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