diff --git a/src/blind.cpp b/src/blind.cpp index 7ee5b9811b..a79367bd6f 100644 --- a/src/blind.cpp +++ b/src/blind.cpp @@ -57,7 +57,7 @@ bool UnblindOutput(const CKey &key, const CTxOut& txout, CAmount& amount_out, ui return false; if (secp256k1_pedersen_commitment_parse(secp256k1_blind_context, &commit, &txout.nValue.vchCommitment[0]) != 1) return false; - int res = secp256k1_rangeproof_rewind(secp256k1_blind_context, blinding_factor_out.begin(), &amount, msg, &msg_size, nonce.begin(), &min_value, &max_value, &commit, &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size(), NULL, 0, &gen); + int res = secp256k1_rangeproof_rewind(secp256k1_blind_context, blinding_factor_out.begin(), &amount, msg, &msg_size, nonce.begin(), &min_value, &max_value, &commit, &txout.nValue.vchRangeproof[0], txout.nValue.vchRangeproof.size(), txout.scriptPubKey.size() ? &txout.scriptPubKey.front() : NULL, txout.scriptPubKey.size(), &gen); secp256k1_generator recoveredGen; if (!res || amount > (uint64_t)MAX_MONEY || !MoneyRange((CAmount)amount) || msg_size != 64 || secp256k1_generator_generate_blinded(secp256k1_blind_context, &recoveredGen, msg+32, msg+64) != 1 || !memcmp(&gen, &recoveredGen, 33)) { @@ -237,7 +237,7 @@ bool BlindOutputs(std::vector& input_blinding_factors, const std::vect memcpy(assetsMessage+32, assetblindptrs[assetblindptrs.size()-1], 32); // Sign rangeproof - int res = secp256k1_rangeproof_sign(secp256k1_blind_context, &value.vchRangeproof[0], &nRangeProofLen, 0, &commit, blindptrs.back(), nonce.begin(), std::min(std::max((int)GetArg("-ct_exponent", 0), -1),18), std::min(std::max((int)GetArg("-ct_bits", 32), 1), 51), amount, assetsMessage, sizeof(assetsMessage), NULL, 0, &gen); + int res = secp256k1_rangeproof_sign(secp256k1_blind_context, &value.vchRangeproof[0], &nRangeProofLen, 0, &commit, blindptrs.back(), nonce.begin(), std::min(std::max((int)GetArg("-ct_exponent", 0), -1),18), std::min(std::max((int)GetArg("-ct_bits", 32), 1), 51), amount, assetsMessage, sizeof(assetsMessage), out.scriptPubKey.size() ? &out.scriptPubKey.front() : NULL, out.scriptPubKey.size(), &gen); value.vchRangeproof.resize(nRangeProofLen); // TODO: do something smarter here assert(res); diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index f913da8529..d6c6ec2149 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -143,7 +143,7 @@ bool CachingTransactionSignatureChecker::VerifySignature(const std::vector& vchRangeProof, const std::vector& vchCommitment, const std::vector& vchAssetTag, const secp256k1_context* secp256k1_ctx_verify_amounts) const +bool CachingRangeProofChecker::VerifyRangeProof(const std::vector& vchRangeProof, const std::vector& vchCommitment, const std::vector& vchAssetTag, const CScript& scriptPubKey, const secp256k1_context* secp256k1_ctx_verify_amounts) const { CPubKey pubkey(vchCommitment); uint256 entry; @@ -162,7 +162,7 @@ bool CachingRangeProofChecker::VerifyRangeProof(const std::vector if (secp256k1_generator_parse(secp256k1_ctx_verify_amounts, &tag, &vchAssetTag[0]) != 1) return false; - if (!secp256k1_rangeproof_verify(secp256k1_ctx_verify_amounts, &min_value, &max_value, &commit, vchRangeProof.data(), vchRangeProof.size(), NULL, 0, &tag)) { + if (!secp256k1_rangeproof_verify(secp256k1_ctx_verify_amounts, &min_value, &max_value, &commit, vchRangeProof.data(), vchRangeProof.size(), scriptPubKey.size() ? &scriptPubKey.front() : NULL, scriptPubKey.size(), &tag)) { return false; } diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 0282d9845c..a7c700f748 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -42,7 +42,7 @@ public: store = storeIn; }; - bool VerifyRangeProof(const std::vector& vchRangeProof, const std::vector& vchCommitment, const std::vector& vchAssetTag, const secp256k1_context* ctx) const; + bool VerifyRangeProof(const std::vector& vchRangeProof, const std::vector& vchCommitment, const std::vector& vchAssetTag, const CScript& scriptPubKey, const secp256k1_context* ctx) const; }; diff --git a/src/validation.cpp b/src/validation.cpp index a114ecded1..1e1f647732 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -574,10 +574,11 @@ class CRangeCheck : public CCheck private: const CTxOutValue* val; const CTxOutAsset* asset; + const CScript* scriptPubKey; const bool store; public: - CRangeCheck(const CTxOutValue* val_, const CTxOutAsset* asset_, const bool storeIn) : val(val_), asset(asset_), store(storeIn) {} + CRangeCheck(const CTxOutValue* val_, const CTxOutAsset* asset_, const CScript* scriptPubKey_, const bool storeIn) : val(val_), asset(asset_), scriptPubKey(scriptPubKey_), store(storeIn) {} bool operator()(); }; @@ -632,7 +633,7 @@ bool CRangeCheck::operator()() return true; } - return CachingRangeProofChecker(store).VerifyRangeProof(val->vchRangeproof, val->vchCommitment, asset->vchAssetTag, secp256k1_ctx_verify_amounts); + return CachingRangeProofChecker(store).VerifyRangeProof(val->vchRangeproof, val->vchCommitment, asset->vchAssetTag, *scriptPubKey, secp256k1_ctx_verify_amounts); }; bool CBalanceCheck::operator()() @@ -774,7 +775,7 @@ bool VerifyAmounts(const CCoinsViewCache& cache, const CTransaction& tx, std::ve const CTxOutValue& val = tx.vout[i].nValue; if (val.IsAmount()) continue; - if (!QueueCheck(pvChecks, new CRangeCheck(&val, &tx.vout[i].nAsset, cacheStore))) { + if (!QueueCheck(pvChecks, new CRangeCheck(&val, &tx.vout[i].nAsset, &tx.vout[i].scriptPubKey, cacheStore))) { return false; } }