Skip to content

Commit 3032cab

Browse files
committed
Style.
1 parent 262fba5 commit 3032cab

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/chain/transaction_sighash_v0.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ bool transaction::version0_sighash(hash_digest& out,
7272
stream::out::fast stream{ out };
7373
hash::sha256x2::fast sink{ stream };
7474

75-
///////////////////////////////////////////////////////////////////////////
76-
// TODO: update cache calls.
77-
///////////////////////////////////////////////////////////////////////////
78-
7975
sink.write_4_bytes_little_endian(version_);
8076
sink.write_bytes(!anyone ? double_hash_points() : null_hash);
8177
sink.write_bytes(!anyone && all ? double_hash_sequences() : null_hash);

src/chain/transaction_sighash_v1.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ uint32_t transaction::subscript_v1(const script& script) NOEXCEPT
5757
// ext_flags and annex flag are combined into one byte, who knows why.
5858
uint8_t transaction::spend_type_v1(bool annex, bool tapscript) const NOEXCEPT
5959
{
60-
const auto ext_flags = to_value(tapscript ?
61-
extension::tapscript : extension::taproot);
60+
const auto ext_flag = to_value(tapscript ? extension::tapscript :
61+
extension::taproot);
6262

63-
return set_right(shift_left(ext_flags), zero, annex);
63+
return set_right(shift_left(ext_flag), zero, annex);
6464
}
6565

6666
// NOT THREAD SAFE
6767
// Concurrent input validation for a tx unsafe due to on-demand hash caching.
68+
// TODO: may be more optimal to not cache single output hash as use is rare.
6869
bool transaction::version1_sighash(hash_digest& out,
6970
const input_iterator& input, const script& script, uint64_t value,
7071
const hash_cptr& tapleaf, uint8_t sighash_flags) const NOEXCEPT
@@ -80,6 +81,18 @@ bool transaction::version1_sighash(hash_digest& out,
8081
const auto single = (flag == coverage::hash_single);
8182
const auto all = (flag == coverage::hash_all);
8283

84+
// ************************************************************************
85+
// CONSENSUS: Guards public interface only, node always populates prevout.
86+
// ************************************************************************
87+
if (anyone && is_null(in.prevout))
88+
return false;
89+
90+
// ************************************************************************
91+
// CONSENSUS: Taproot finally eliminates one_hash (null_hash in v0) return.
92+
// ************************************************************************
93+
if (single && output_overflow(input_index(input)))
94+
return false;
95+
8396
// Create tagged hash writer.
8497
stream::out::fast stream{ out };
8598
hash::sha256t::fast<"TapSighash"> sink{ stream };
@@ -106,10 +119,6 @@ bool transaction::version1_sighash(hash_digest& out,
106119

107120
if (anyone)
108121
{
109-
// This implies a parameterization error, and will fail the script.
110-
if (is_null(in.prevout))
111-
return false;
112-
113122
in.point().to_data(sink);
114123
sink.write_8_bytes_little_endian(value);
115124
in.prevout->script().to_data(sink, true);
@@ -127,13 +136,8 @@ bool transaction::version1_sighash(hash_digest& out,
127136

128137
if (single)
129138
{
130-
const auto index = input_index(input);
131-
if (output_overflow(index))
132-
return false;
133-
134139
// Hash is cached for use with each single sigop in the same script.
135-
// TODO: it may be more optimal to not cache, since benefit is rare.
136-
sink.write_bytes(outputs_->at(index)->get_hash());
140+
sink.write_bytes(outputs_->at(input_index(input))->get_hash());
137141
}
138142

139143
// Additional for tapscript [bip342].
@@ -145,11 +149,6 @@ bool transaction::version1_sighash(hash_digest& out,
145149
sink.write_4_bytes_little_endian(subscript_v1(script));
146150
}
147151

148-
// TODO: write position pertains to the hash instance (written at flush).
149-
// Total length at most 206 bytes (!anyone, no epoch/tapscript) [bip341].
150-
////BC_ASSERT(!anyone && sink.get_write_position() == (add1(206u) + 37));
151-
////BC_ASSERT( anyone && sink.get_write_position() == (add1(157u) + 37));
152-
153152
sink.flush();
154153
return true;
155154
}

0 commit comments

Comments
 (0)