Skip to content

Commit 262fba5

Browse files
committed
Fix v1 sighash annex serialization.
1 parent dc29f85 commit 262fba5

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

include/bitcoin/system/chain/annex.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BC_API annex
3939

4040
inline size_t size() const NOEXCEPT;
4141
inline const data_chunk& data() const NOEXCEPT;
42-
inline const hash_digest hash() const NOEXCEPT;
42+
inline const hash_digest hash(bool prefix) const NOEXCEPT;
4343
inline operator bool() const NOEXCEPT;
4444

4545
/// The stack adheres to the annex pattern [bip341].

include/bitcoin/system/impl/chain/annex.ipp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <bitcoin/system/data/data.hpp>
2424
#include <bitcoin/system/define.hpp>
2525
#include <bitcoin/system/hash/hash.hpp>
26+
#include <bitcoin/system/stream/stream.hpp>
2627

2728
namespace libbitcoin {
2829
namespace system {
@@ -72,9 +73,18 @@ inline const data_chunk& annex::data() const NOEXCEPT
7273
return data_ ? *data_ : empty_annex();
7374
}
7475

75-
inline const hash_digest annex::hash() const NOEXCEPT
76+
inline const hash_digest annex::hash(bool prefix) const NOEXCEPT
7677
{
77-
return sha256_hash(data());
78+
if (!prefix)
79+
return sha256_hash(data());
80+
81+
hash_digest out{};
82+
stream::out::fast stream{ out };
83+
hash::sha256::fast sink{ stream };
84+
sink.write_variable(size());
85+
sink.write_bytes(data());
86+
sink.flush();
87+
return out;
7888
}
7989

8090
// static

src/chain/transaction_sighash_v1.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ bool transaction::version1_sighash(hash_digest& out,
122122

123123
if (annex)
124124
{
125-
sink.write_variable(annex.size());
126-
sink.write_bytes(annex.hash());
125+
sink.write_bytes(annex.hash(true));
127126
}
128127

129128
if (single)

0 commit comments

Comments
 (0)