From 3be1c9e0971eeca375b5bf8151b04887a12bbe21 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Thu, 23 Mar 2017 10:55:40 -0400 Subject: [PATCH] Extend sigcache to properly cover all input to each verification --- src/script/sigcache.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 6115030abe..e75e7bdc53 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -45,7 +45,7 @@ public: class CSignatureCache { private: - //! Entries are SHA256(nonce || signature hash || public key || signature): + //! Entries are SHA256(nonce || signature hash || public key || signature || additional commit || CScript). They are used in various ways for different checks uint256 nonce; typedef CuckooCache::cache map_type; map_type setValid; @@ -58,9 +58,9 @@ public: } void - ComputeEntry(uint256& entry, const uint256 &hash, const std::vector& vchSig, const CPubKey& pubkey) + ComputeEntry(uint256& entry, const uint256 &hash, const std::vector& vchSig, const CPubKey& pubkey, const std::vector& vchCommitment, const CScript& scriptPubKey) { - CSHA256().Write(nonce.begin(), 32).Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(&vchSig[0], vchSig.size()).Finalize(entry.begin()); + CSHA256().Write(nonce.begin(), 32).Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(&vchSig[0], vchSig.size()).Write(&vchCommitment[0], vchCommitment.size()).Write(&scriptPubKey[0], scriptPubKey.size()).Finalize(entry.begin()); } bool @@ -133,7 +133,7 @@ void InitSurjectionproofCache() bool CachingTransactionSignatureChecker::VerifySignature(const std::vector& vchSig, const CPubKey& pubkey, const uint256& sighash) const { uint256 entry; - signatureCache.ComputeEntry(entry, sighash, vchSig, pubkey); + signatureCache.ComputeEntry(entry, sighash, vchSig, pubkey, vchSig, CScript()); if (signatureCache.Get(entry, !store)) return true; if (!TransactionSignatureChecker::VerifySignature(vchSig, pubkey, sighash)) @@ -147,7 +147,7 @@ bool CachingRangeProofChecker::VerifyRangeProof(const std::vector { CPubKey pubkey(vchValueCommitment); uint256 entry; - rangeProofCache.ComputeEntry(entry, uint256(), vchRangeProof, pubkey); + rangeProofCache.ComputeEntry(entry, uint256(), vchRangeProof, pubkey, vchAssetCommitment, scriptPubKey); if (rangeProofCache.Get(entry, !store)) { return true; @@ -171,18 +171,29 @@ bool CachingRangeProofChecker::VerifyRangeProof(const std::vector bool CachingSurjectionProofChecker::VerifySurjectionProof(secp256k1_surjectionproof& proof, std::vector& vTags, secp256k1_generator& gen, const secp256k1_context* secp256k1_ctx_verify_amounts) const { + // Serialize objects std::vector vchproof; size_t proof_len = 0; vchproof.resize(secp256k1_surjectionproof_serialized_size(secp256k1_ctx_verify_amounts, &proof)); secp256k1_surjectionproof_serialize(secp256k1_ctx_verify_amounts, &vchproof[0], &proof_len, &proof); + std::vector tagCommit; + tagCommit.resize(33); + CSHA256 sha2; + for (unsigned int i = 0; i vchGen; vchGen.resize(CConfidentialValue::nCommittedSize); secp256k1_generator_serialize(secp256k1_ctx_verify_amounts, &vchGen[0], &gen); CPubKey pubkey(vchGen); uint256 entry; - surjectionProofCache.ComputeEntry(entry, uint256(), vchproof, pubkey); + surjectionProofCache.ComputeEntry(entry, uint256(tagCommit), vchproof, pubkey, vchGen, CScript()); if (surjectionProofCache.Get(entry, !store)) { return true;