Skip to content

Commit 2527387

Browse files
committed
Add script::clear_offset() and change program asserts to resets.
1 parent e75e0b4 commit 2527387

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

include/bitcoin/system/chain/script.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class BC_API script
161161
bool is_oversized() const NOEXCEPT;
162162
bool is_unspendable() const NOEXCEPT;
163163

164+
/// Reset mutable signature hashing op_codeseparator offset.
165+
void clear_offset() const NOEXCEPT;
166+
164167
protected:
165168
script(const operations& ops, bool valid, bool easier, bool failer,
166169
bool roller, size_t size) NOEXCEPT;

include/bitcoin/system/impl/machine/program.ipp

+11-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ program(const transaction& tx, const input_iterator& input,
5050
version_(script_version::unversioned),
5151
primary_()
5252
{
53-
BC_ASSERT(script_->offset == script_->ops().begin());
53+
script_->clear_offset();
5454
}
5555

5656
// Legacy p2sh or prevout script run (copied input stack - use first).
@@ -68,7 +68,7 @@ program(const program& other, const script::cptr& script) NOEXCEPT
6868
version_(other.version_),
6969
primary_(other.primary_)
7070
{
71-
BC_ASSERT(script_->offset == script_->ops().begin());
71+
script_->clear_offset();
7272
}
7373

7474
// Legacy p2sh or prevout script run (moved input stack/tether - use last).
@@ -83,7 +83,7 @@ program(program&& other, const script::cptr& script) NOEXCEPT
8383
version_(other.version_),
8484
primary_(std::move(other.primary_))
8585
{
86-
BC_ASSERT(script_->offset == script_->ops().begin());
86+
script_->clear_offset();
8787
}
8888

8989
// Segwit script run (witness-initialized stack).
@@ -104,7 +104,7 @@ program(const transaction& tx, const input_iterator& input,
104104
witness_(witness),
105105
primary_(projection<Stack>(*witness))
106106
{
107-
BC_ASSERT(script_->offset == script_->ops().begin());
107+
script_->clear_offset();
108108
}
109109

110110
// Taproot script run (witness-initialized stack).
@@ -128,7 +128,7 @@ program(const transaction& tx, const input_iterator& input,
128128
primary_(projection<Stack>(*witness)),
129129
budget_(ceilinged_add(add1(chain::signature_budget), witness_size))
130130
{
131-
BC_ASSERT(script_->offset == script_->ops().begin());
131+
script_->clear_offset();
132132
}
133133

134134
// Public.
@@ -841,7 +841,12 @@ ecdsa_prepare(ec_signature& signature, hash_digest& hash,
841841
if (!ecdsa::parse_endorsement(sighash_flags, distinguished, *endorsement))
842842
return false;
843843

844-
// TODO: re-evaluate multisig hash caching.
844+
// TODO: create array of 6 pointers (48 bytes).
845+
// TODO: map each pointer type to contiguous array element.
846+
// TODO: look up in array before computing hash, store after computing.
847+
// TODO: store as program member, reset after each op_multisig.
848+
// TODO: total cost is 6x8=48 bytes per thread, search/assign array.
849+
// TODO: no hash function and no alloc/realloc.
845850
////hash_cache cache{};
846851
////const auto& hash = cache.at(sighash_flags);
847852

src/chain/script.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ bool script::is_unspendable() const NOEXCEPT
587587
return operation::is_reserved(code) || operation::is_invalid(code);
588588
}
589589

590+
void script::clear_offset() const NOEXCEPT
591+
{
592+
offset = ops_.begin();
593+
}
594+
590595
BC_POP_WARNING()
591596
BC_POP_WARNING()
592597

0 commit comments

Comments
 (0)