diff options
author | Andrew Chow <achow101-github@achow101.com> | 2018-08-07 16:59:53 -0700 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2018-08-09 18:39:56 -0700 |
commit | e306be742932d4ea5aca0ea4768e54b2fc3dc6a0 (patch) | |
tree | 29777760bfbb33ee879fe33e50297a7ddd7a1bef /src/script | |
parent | 48b1473c898129a99212e2db36c61cf93625ea17 (diff) |
Use 72 byte dummy signatures when watching only inputs may be used
With watching only inputs, we do not know how large the signatures
for those inputs will be as their signers may not have implemented
71 byte signatures. Thus we estimate their fees using the 72 byte
dummy signature to ensure that we pay enough fees.
This only effects fundrawtransaction when includeWatching is true.
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/sign.cpp | 22 | ||||
-rw-r--r-- | src/script/sign.h | 4 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/script/sign.cpp b/src/script/sign.cpp index c103e3c2f0..66d942d7c5 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -417,22 +417,25 @@ public: const DummySignatureChecker DUMMY_CHECKER; class DummySignatureCreator final : public BaseSignatureCreator { +private: + char m_r_len = 32; + char m_s_len = 32; public: - DummySignatureCreator() {} + DummySignatureCreator(char r_len, char s_len) : m_r_len(r_len), m_s_len(s_len) {} const BaseSignatureChecker& Checker() const override { return DUMMY_CHECKER; } bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override { // Create a dummy signature that is a valid DER-encoding - vchSig.assign(71, '\000'); + vchSig.assign(m_r_len + m_s_len + 7, '\000'); vchSig[0] = 0x30; - vchSig[1] = 68; + vchSig[1] = m_r_len + m_s_len + 4; vchSig[2] = 0x02; - vchSig[3] = 32; + vchSig[3] = m_r_len; vchSig[4] = 0x01; - vchSig[4 + 32] = 0x02; - vchSig[5 + 32] = 32; - vchSig[6 + 32] = 0x01; - vchSig[6 + 32 + 32] = SIGHASH_ALL; + vchSig[4 + m_r_len] = 0x02; + vchSig[5 + m_r_len] = m_s_len; + vchSig[6 + m_r_len] = 0x01; + vchSig[6 + m_r_len + m_s_len] = SIGHASH_ALL; return true; } }; @@ -450,7 +453,8 @@ bool LookupHelper(const M& map, const K& key, V& value) } -const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(); +const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32); +const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32); const SigningProvider& DUMMY_SIGNING_PROVIDER = SigningProvider(); bool IsSolvable(const SigningProvider& provider, const CScript& script) diff --git a/src/script/sign.h b/src/script/sign.h index 96ef59fbe8..a614d17a9f 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -80,8 +80,10 @@ public: bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override; }; -/** A signature creator that just produces 72-byte empty signatures. */ +/** A signature creator that just produces 71-byte empty signatures. */ extern const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR; +/** A signature creator that just produces 72-byte empty signatures. */ +extern const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR; typedef std::pair<CPubKey, std::vector<unsigned char>> SigPair; |