• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-system / 14981247273

12 May 2025 07:50PM UTC coverage: 82.111% (-0.007%) from 82.118%
14981247273

push

github

web-flow
Merge pull request #1663 from evoskuil/master

Factor program/interpreter ipp's, update includes/inlines, fix sig bu…

308 of 389 new or added lines in 5 files covered. (79.18%)

10314 of 12561 relevant lines covered (82.11%)

3835839.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.08
/include/bitcoin/system/impl/machine/program_construct.ipp
1
/**
2
 * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#ifndef LIBBITCOIN_SYSTEM_MACHINE_PROGRAM_CONSTRUCT_IPP
20
#define LIBBITCOIN_SYSTEM_MACHINE_PROGRAM_CONSTRUCT_IPP
21

22
#include <utility>
23
#include <bitcoin/system/chain/chain.hpp>
24
#include <bitcoin/system/crypto/crypto.hpp>
25
#include <bitcoin/system/data/data.hpp>
26
#include <bitcoin/system/define.hpp>
27
#include <bitcoin/system/math/math.hpp>
28

29
namespace libbitcoin {
30
namespace system {
31
namespace machine {
32

33
// Constructors.
34
// ----------------------------------------------------------------------------
35

36
// Input script run (default/empty stack).
37
// 'tx' must remain in scope, this holds state referenced by weak pointers.
38
// This expectation is guaranteed by the retained tx reference.
39
TEMPLATE
40
inline CLASS::
1,559✔
41
program(const transaction& tx, const input_iterator& input,
42
    uint32_t active_flags) NOEXCEPT
43
  : transaction_(tx),
1,559✔
44
    input_(input),
1,559✔
45
    script_((*input)->script_ptr()),
1,559✔
46
    flags_(bit_and(active_flags, bip342_mask)),
1,559✔
47
    value_(max_uint64),
1,559✔
48
    version_(script_version::unversioned),
1,559✔
49
    primary_()
4,677✔
50
{
51
    script_->clear_offset();
1,559✔
52
}
1,559✔
53

54
// Legacy p2sh or prevout script run (copied input stack - use first).
55
// 'other' must remain in scope, this holds state referenced by weak pointers.
56
// This expectation is guaranteed by the retained transaction_ member reference
57
// and copied program tether (which is not tx state).
58
TEMPLATE
59
inline CLASS::
1,496✔
60
program(const program& other, const script::cptr& script) NOEXCEPT
61
  : transaction_(other.transaction_),
1,496✔
62
    input_(other.input_),
1,496✔
63
    script_(script),
64
    flags_(other.flags_),
1,496✔
65
    value_(other.value_),
1,496✔
66
    version_(other.version_),
1,496✔
67
    primary_(other.primary_)
2,992✔
68
{
69
    script_->clear_offset();
1,496✔
70
}
1,496✔
71

72
// Legacy p2sh or prevout script run (moved input stack/tether - use last).
73
TEMPLATE
74
inline CLASS::
17✔
75
program(program&& other, const script::cptr& script) NOEXCEPT
76
  : transaction_(other.transaction_),
17✔
77
    input_(other.input_),
17✔
78
    script_(script),
79
    flags_(other.flags_),
17✔
80
    value_(other.value_),
17✔
81
    version_(other.version_),
17✔
82
    primary_(std::move(other.primary_))
34✔
83
{
84
    script_->clear_offset();
17✔
85
}
17✔
86

87
// Segwit script run (witness-initialized stack).
88
// 'tx', 'input' (and iterated chain::input) must remain in scope, as these
89
// hold chunk state weak references. A witness pointer is explicitly retained
90
// to guarantee the lifetime of its elements.
91
TEMPLATE
92
inline CLASS::
23✔
93
program(const transaction& tx, const input_iterator& input,
94
    const script::cptr& script, uint32_t active_flags,
95
    script_version version, const chunk_cptrs_ptr& witness) NOEXCEPT
96
  : transaction_(tx),
23✔
97
    input_(input),
23✔
98
    script_(script),
99
    flags_(bit_and(active_flags, bip342_mask)),
23✔
100
    value_((*input)->prevout->value()),
23✔
101
    version_(version),
23✔
102
    witness_(witness),
103
    primary_(projection<Stack>(*witness))
69✔
104
{
105
    script_->clear_offset();
23✔
106
}
23✔
107

108
// Taproot script run (witness-initialized stack).
109
// Same as segwit but with with budget and unstripped bip342 flag.
110
// Sigop budget is 50 plus size of prefixed serialized witness [bip342].
111
// Budget is initialized add1(50) to make it zero-based, avoiding signed type.
112
// This program is never used to construct another, so masked flags_ never mix.
113
TEMPLATE
NEW
114
inline CLASS::
×
115
program(const transaction& tx, const input_iterator& input,
116
    const script::cptr& script, uint32_t active_flags,
117
    script_version version, const chunk_cptrs_ptr& witness, bool) NOEXCEPT
NEW
118
  : transaction_(tx),
×
NEW
119
    input_(input),
×
120
    script_(script),
NEW
121
    flags_(active_flags),
×
NEW
122
    value_((*input)->prevout->value()),
×
NEW
123
    version_(version),
×
124
    witness_(witness),
NEW
125
    primary_(projection<Stack>(*witness)),
×
NEW
126
    budget_(ceilinged_add(
×
127
        add1(chain::signature_cost),
NEW
128
        chain::witness::serialized_size(*witness_, true)))
×
129
{
NEW
130
    script_->clear_offset();
×
NEW
131
}
×
132

133
} // namespace machine
134
} // namespace system
135
} // namespace libbitcoin
136

137
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc