From 7ad4d950a4e029be5adb0fb76f394c831e397f1e Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Tue, 22 May 2018 16:54:43 +0200 Subject: [PATCH 1/2] Reject issuances with explicit values but non-empty range proofs --- src/validation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 55351d7365..cf871f7dc3 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -719,6 +719,10 @@ static bool VerifyIssuanceAmount(secp256k1_pedersen_commitment& commit, secp256k if (!MoneyRange(value.GetAmount()) || value.GetAmount() == 0) { return false; } + if (!vchRangeproof.empty()) { + return false; + } + ret = secp256k1_pedersen_commit(secp256k1_ctx_verify_amounts, &commit, explBlinds, value.GetAmount(), &gen); // The explBlinds are all 0, and the amount is not 0. So secp256k1_pedersen_commit does not fail. From 6f80bcedfedf030f31147d611dd2dc796227974b Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Fri, 18 May 2018 17:40:22 +0200 Subject: [PATCH 2/2] Remove redundant checks of size of range proof and surjection proof The checks are redudant because too large range proofs and surjection proofs will be rejected by libsecp256k1. Furthermore, the checks are not precise, and they are anyway not present in other similar code locations. --- src/validation.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index cf871f7dc3..93679ea74d 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -905,10 +905,9 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve { const CConfidentialValue& val = tx.vout[i].nValue; const CConfidentialAsset& asset = tx.vout[i].nAsset; - const CTxOutWitness* ptxoutwit = tx.wit.vtxoutwit.size() <= i? NULL: &tx.wit.vtxoutwit[i]; - if (!asset.IsValid() || (ptxoutwit && ptxoutwit->vchSurjectionproof.size() > 5000)) + if (!asset.IsValid()) return false; - if (!val.IsValid() || (ptxoutwit && ptxoutwit->vchRangeproof.size() > 5000)) + if (!val.IsValid()) return false; if (!tx.vout[i].nNonce.IsValid()) return false; @@ -977,7 +976,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve assert(ret != 0); secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, &vchAssetCommitment[0], &gen); } - if (!ptxoutwit || ptxoutwit->vchRangeproof.size() > 5000) { + if (!ptxoutwit) { return false; } if (QueueCheck(pvChecks, new CRangeCheck(&val, ptxoutwit->vchRangeproof, vchAssetCommitment, tx.vout[i].scriptPubKey, cacheStore)) != SCRIPT_ERR_OK) { @@ -997,7 +996,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve } continue; } - if (!ptxoutwit || ptxoutwit->vchSurjectionproof.size() > 5000) + if (!ptxoutwit) return false; if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &gen, &asset.vchCommitment[0]) != 1) return false;