Skip to content

kernel: expose witness stack and scriptSig for btck_TransactionInput - #35380

Merged
sedited merged 2 commits into
bitcoin:masterfrom
pzafonte:kernel-api-txin-witness-stack
Jul 14, 2026
Merged

sedited merged 2 commits into
bitcoin:masterfrom
pzafonte:kernel-api-txin-witness-stack

Conversation

@pzafonte

@pzafonte pzafonte commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Silent payments scanning needs the public key from every input. For SegWit inputs it is in the witness stack. For P2PKH inputs it is in scriptSig. Without these new functions, callers must deserialize the raw transaction themselves to reach that data, which is difficult and error-prone.

Introduces a btck_WitnessStack type and adds the following functions:

Witness stack:
btck_transaction_input_get_witness_stack: returns a non-owning const btck_WitnessStack* view
btck_witness_stack_count_items : item count
btck_witness_stack_get_item_at : single item by index via btck_WriteBytes
btck_witness_stack_copy / btck_witness_stack_destroy: lifecycle for owned copies

scriptSig:
btck_transaction_input_get_script_sig: full scriptSig via btck_WriteBytes

All functions are exposed in the C++ wrapper via WitnessStackView, WitnessStack, and WitnessStackApi , and GetScriptSig().

@DrahtBot

DrahtBot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35380.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK sedited, musaHaruna, stickies-v
Concept ACK theStack, w0xlt, yuvicc, yancyribbens

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@github-project-automation github-project-automation Bot moved this to Architecture & Performance in The libbitcoinkernel Project May 26, 2026
@sedited sedited moved this from Architecture & Performance to API Development in The libbitcoinkernel Project May 26, 2026
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task Alpine (musl): https://github.com/bitcoin/bitcoin/actions/runs/26449143818/job/77864724232
LLM reason (✨ experimental): CI failed because compilation of test_kernel errored out: bitcoinkernel_wrapper.h used assert(...) without including it (so assert was not declared).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@stickies-v stickies-v left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, seems useful to expose.

Small motivation nit:

Without access to it, kernel API callers cannot extract the sender key from these input types which is a requirement for silent payments scanning.

Callers can, but they have to parse the entire transaction, so exposing these functions obviously makes that easier and less error-prone.

Comment thread src/kernel/bitcoinkernel.h Outdated
* @param[in] transaction_input Non-null.
* @return The number of witness stack items.
*/
BITCOINKERNEL_API size_t btck_transaction_input_get_witness_stack_num_items(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we use _count for similar functions, so would stay consistent with btck_transaction_input_count_witness_stack_items

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Updated in 34897f3

Comment thread src/test/kernel/test_kernel.cpp Outdated
Transaction segwit_tx{hex_string_to_byte_vec("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000")};
TransactionInputView segwit_input = segwit_tx.GetInput(0);
BOOST_CHECK_EQUAL(segwit_input.GetWitnessStackNumItems(), 4);
BOOST_CHECK_EQUAL(segwit_input.GetWitnessStackItem(0).size(), 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to test full equality rather than just the size

@pzafonte pzafonte May 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the tests in 34897f3

Comment thread src/kernel/bitcoinkernel.h Outdated
* @param[in] index Index of the witness stack item.
* @param[in] writer Non-null, function pointer for writing bytes.
* @param[in] user_data Nullable, passed back through the writer callback.
* @return 0 on success, -1 if the index is out of bounds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the writer impl, -1 can also indicate that writing failed. As a general pattern, I wonder if it makes sense to wholesale return the writer error code. Alternatively we could catch the writer error code, log it, and then returning a pre-defined writer error code, so we get e.g. 0 on success, -1 on out of bounds, and -2 on write failure?

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from f09656e to f196825 Compare May 26, 2026 14:26
@pzafonte pzafonte changed the title kernel: expose witness stack items for btck_TransactionInput kernel: expose witness stack and scriptSig for btck_TransactionInput May 26, 2026
@pzafonte

Copy link
Copy Markdown
Contributor Author

Callers can, but they have to parse the entire transaction, so exposing these functions obviously makes that easier and less error-prone.

Updated the title and description to clarify motivation and reflect both commits.

@theStack

Copy link
Copy Markdown
Contributor

Concept ACK

@w0xlt

w0xlt commented May 26, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@yuvicc yuvicc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
return btck_transaction_input_count_witness_stack_items(impl());
}

std::vector<std::byte> GetWitnessStackItem(size_t index) const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could crash the program when an invalid index is passed?

test
BOOST_CHECK_THROW(segwit_input.GetWitnessStackItem(4), std::out_of_range);
output Log
unknown location:0: fatal error: in "btck_transaction_input": signal: SIGABRT (application abort requested)

I think the cause might be here at L318 - L320:

L318 - L320
if (to_bytes(object, write, &user_data) != 0) {
    std::rethrow_exception(user_data.exception);
}

When passing an index out of bounds, the C API returns -1, and the user_data.exception remains nullptr. Passing nullptr to std::rethrow_exception results in undefined behaviour (UB). Probably add a bounds check here?

diff
  if (to_bytes(object, write, &user_data) != 0) {
      if (user_data.exception) std::rethrow_exception(user_data.exception);
      throw std::runtime_error("Kernel API call failed");
  }

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from f196825 to a398cd8 Compare May 29, 2026 15:47
@pzafonte

pzafonte commented May 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Double checking myself.

Looking at src/validation.cpp:3869-L3871
const auto& witness_stack{block.vtx[0]->vin[0].scriptWitness.stack};
if (witness_stack.size() != 1 || witness_stack[0].size() != 32) {

And src/core_io.cpp:463-464
txinwitness.reserve(tx.vin[i].scriptWitness.stack.size()); for (const auto& item : tx.vin[i].scriptWitness.stack) {

I don't think valid usage would ever reach an unverified index given the count function is available, so assert feels more appropriate here?

@sedited sedited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop the description in the commit message of what the witness data is needed for. There are many use cases for this, and I don't think enumerating them is useful.

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
@@ -8,6 +8,7 @@
#include <kernel/bitcoinkernel.h>

#include <array>
#include <cassert>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this include must be from a prior revision. Can you remove it?

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
@@ -586,6 +587,27 @@ class TransactionInputApi
{
return btck_transaction_input_get_sequence(impl());
}

size_t GetWitnessStackNumItems() const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be called CountWitnessStackItems.

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from a398cd8 to 46a4654 Compare June 4, 2026 15:41
@DrahtBot

DrahtBot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/26962501443/job/79556335400
LLM reason (✨ experimental): CI failed due to a C++ build error: btck_transaction_input_get_script_sig is an undeclared identifier in bitcoinkernel_wrapper.h (compiling bitcoin-chainstate.cpp).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch 2 times, most recently from 7af5abc to 269e39b Compare June 4, 2026 18:46
@DrahtBot DrahtBot removed the CI failed label Jun 4, 2026

@sedited sedited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 269e39b2dc41f99f6184120f648f5ab3c1c93b7d

@DrahtBot
DrahtBot requested review from stickies-v and theStack June 11, 2026 07:59
@DrahtBot
DrahtBot requested a review from stickies-v June 15, 2026 10:32

@musaHaruna musaHaruna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I don't think valid usage would ever reach an unverified index given the count function is available, so assert feels more appropriate here?

Looking at the code through the lenses of a newbie, While assert(index < stack.size()); prevents Undefined Behavior by stopping execution immediately, and usage (like in validation.cpp or core_io.cpp) safely guards indices, I don't think it's ideal for the shared library, because the endpoint is consumed by external runtimes and language bindings (Go, Rust, JS) via FFI, we cannot guarantee valid usage from the caller.

More importantly, in production Release builds where NDEBUG is defined, this assert will be completely stripped out. If an external caller does pass an invalid index by mistake, it will lead to undefined behavior or a segmentation fault via stack[index].

Would it make sense to perform a runtime bounds check instead?

int btck_transaction_input_get_witness_stack_item(const btck_TransactionInput* input, size_t index, btck_WriteBytes writer, void* user_data)
{
    const std::vector<std::vector<unsigned char>>& stack{btck_TransactionInput::get(input).scriptWitness.stack};
    if (index >= stack.size()) {
        return -1; 
    }
    return writer(stack[index].data(), stack[index].size(), user_data);
}

Then the C++ wrapper utility (write_bytes) could handle non-exception failures, as suggested by @yuvicc:

  if (to_bytes(object, write, &user_data) != 0) {
      if (user_data.exception) std::rethrow_exception(user_data.exception);
      throw std::runtime_error("Kernel API call failed");
  }

That would also allow the proposed unit test to pass:

BOOST_CHECK_THROW(segwit_input.GetWitnessStackItem(4), std::out_of_range);

@stickies-v stickies-v left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
@@ -320,6 +320,36 @@ std::vector<std::byte> write_bytes(const T* object, int (*to_bytes)(const T*, bt
return bytes;
}

template <typename T>
std::vector<std::byte> write_bytes(const T* object, size_t index, int (*to_bytes)(const T*, size_t, btck_WriteBytes, void*))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your previous approach (c6d532414406cff5d31819e10adbf04042a65746) you, just used a Ctx wrapper. Any reason you changed it to this overload? I thought the wrapper was quite elegant? The new approach is a lot of unnecessary duplication.

(nit: if you update, Item seems like a more helpful name than Ctx.)

git diff on fa221030ac
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index d6b06d3c13..3bfd4a48ac 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -320,36 +320,6 @@ std::vector<std::byte> write_bytes(const T* object, int (*to_bytes)(const T*, bt
     return bytes;
 }
 
-template <typename T>
-std::vector<std::byte> write_bytes(const T* object, size_t index, int (*to_bytes)(const T*, size_t, btck_WriteBytes, void*))
-{
-    std::vector<std::byte> bytes;
-    struct UserData {
-        std::vector<std::byte>* bytes;
-        std::exception_ptr exception;
-    };
-    UserData user_data = UserData{.bytes = &bytes, .exception = nullptr};
-
-    constexpr auto const write = +[](const void* buffer, size_t len, void* user_data) -> int {
-        auto& data = *reinterpret_cast<UserData*>(user_data);
-        auto& bytes = *data.bytes;
-        try {
-            auto const* first = static_cast<const std::byte*>(buffer);
-            auto const* last = first + len;
-            bytes.insert(bytes.end(), first, last);
-            return 0;
-        } catch (...) {
-            data.exception = std::current_exception();
-            return -1;
-        }
-    };
-
-    if (to_bytes(object, index, write, &user_data) != 0) {
-        std::rethrow_exception(user_data.exception);
-    }
-    return bytes;
-}
-
 template <typename CType>
 class View
 {
@@ -614,7 +584,11 @@ public:
 
     std::vector<std::byte> Item(size_t index) const
     {
-        return write_bytes(impl(), index, btck_witness_stack_get_item);
+        struct Item { const btck_WitnessStack* stack; size_t index; };
+        Item ctx{impl(), index};
+        return write_bytes(&ctx, +[](const Item* item, btck_WriteBytes w, void* ud) {
+            return btck_witness_stack_get_item(item->stack, item->index, w, ud);
+        });
     }
 
     MAKE_RANGE_METHOD(Items, Derived, &WitnessStackApi<Derived>::Count, &WitnessStackApi<Derived>::Item, *static_cast<const Derived*>(this))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was considering consistency with the other write_bytes calls but I agree about duplication that the overload creates. Reducing the duplication would require refactoring write_bytes itself, though I felt that would be of scope for this PR. I'll revert to the Ctx wrapper.

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
return btck_witness_stack_count(impl());
}

std::vector<std::byte> Item(size_t index) const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: quite a few naming inconsistencies wrt other functions, e.g. typically we prefix getters here with Get. Also btck_witness_stack_get_item_at and btck_witness_stack_count_items.

Comment thread src/kernel/bitcoinkernel.cpp Outdated

int btck_transaction_input_get_script_sig(const btck_TransactionInput* input, btck_WriteBytes writer, void* user_data)
{
return writer(btck_TransactionInput::get(input).scriptSig.data(), btck_TransactionInput::get(input).scriptSig.size(), user_data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would create a const auto& script_sig{btck_TransactionInput::get(input).scriptSig}; here

Comment thread src/kernel/bitcoinkernel.h Outdated
* @param[in] user_data Nullable, passed back through the writer callback.
* @return The return value of the writer. Aborts if index is out of bounds.
*/
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_input_get_witness_stack_item(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the btck_WitnessStack approach.

meta-nit: would suggest to either post a link to an alternative branch if you don't want to update the PR branch yet as you're looking for feedback, or update the PR branch with a properly rebased version, this is kind of the worst of both worlds.

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from fa22103 to d6cc918 Compare July 3, 2026 17:45
@yancyribbens

Copy link
Copy Markdown
Contributor

Concept ACK

@stickies-v stickies-v left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d6cc918c482f16b2caa1e8c56f449136f3aa41f4

meta-nit: people can already see the PR edit history by clicking on the "edited" link. For new reviewers, and our git tree (PR description gets included in the merge commit) just reflecting the current status rather than a full historical record is more straightforward.

Comment thread src/kernel/bitcoinkernel_wrapper.h Outdated
std::vector<std::byte> GetItem(size_t index) const
{
struct Item { const btck_WitnessStack* stack; size_t index; };
Item ctx{impl(), index};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
Item ctx{impl(), index};
Item item{impl(), index};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/kernel/bitcoinkernel.h Outdated
* @param[in] index Index of the item in the witness stack.
* @param[in] writer Non-null, function pointer for writing bytes.
* @param[in] user_data Nullable, passed back through the writer callback.
* @return The return value of the writer. Aborts if index is out of bounds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be more appropriately documented as a @pre, e.g. @pre index < btck_witness_stack_count_items(witness_stack)

@pzafonte pzafonte Jul 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I agree with the use of @pre though I dropped it from #34885 since it would have been the first use in bitcoinkernel.h and other functions with similar assert-on-OOB behavior don't document it that way. Noting it here in case it's worth aligning across the file.

Comment thread src/kernel/bitcoinkernel.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
* Holds information on the @ref btck_TransactionOutPoint, @ref btck_WitnessStack and script_sig held within.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@DrahtBot
DrahtBot requested review from musaHaruna and sedited July 6, 2026 17:35
Transaction segwit_tx{hex_string_to_byte_vec("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000")};
TransactionInputView segwit_input = segwit_tx.GetInput(0);
WitnessStackView ws = segwit_input.GetWitnessStack();
BOOST_CHECK_EQUAL(ws.CountItems(), 4);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a CheckRange(ws.Items(), ws.CountItems());?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckRange calls .get() on each element and Items() returns std::vector<std::byte>, which has no .get(), so it won't pass CI as is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another meta comment: before pushing, always make sure that the code compiles locally for you, and that the unit and functional tests pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, sorry about that. My local build and test scripts were configured improperly, and it looked like it was passing locally. Fixed the configuration issue on my end.

@DrahtBot
DrahtBot requested a review from sedited July 6, 2026 19:11
@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from d6cc918 to 0277cbb Compare July 7, 2026 21:58
@pzafonte

pzafonte commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

meta-nit: people can already see the PR edit history by clicking on the "edited" link. For new reviewers, and our git tree (PR description gets included in the merge commit) just reflecting the current status rather than a full historical record is more straightforward.

Thanks & Done, updated the description to reflect the current state.

@DrahtBot

DrahtBot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/28901571778/job/85739321433
LLM reason (✨ experimental): CI failed at build time because src/test/kernel/test_kernel.cpp wouldn’t compile (std::vector<std::byte> has no member get()), causing test_kernel to fail.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@pzafonte
pzafonte force-pushed the kernel-api-txin-witness-stack branch from 0277cbb to 6667dc4 Compare July 8, 2026 12:39
@DrahtBot DrahtBot removed the CI failed label Jul 8, 2026

@sedited sedited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6667dc4

@DrahtBot
DrahtBot requested a review from stickies-v July 13, 2026 20:46

@musaHaruna musaHaruna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6667dc

The new approach of introducing a btck_WitnessStack type looks cleaner than adding more witness-specific functions to btck_TransactionInput. I think this is a more appropriate abstraction for the witness stack.

* @param[in] writer Non-null, function pointer for writing bytes.
* @param[in] user_data Nullable, passed back through the writer callback.
* @return The return value of the writer.
* @pre index < btck_witness_stack_count_items(witness_stack)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Incase a need to push arises again, this can be aligned

Suggested change
* @pre index < btck_witness_stack_count_items(witness_stack)
* @pre index < btck_witness_stack_count_items(witness_stack)

@stickies-v stickies-v left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6667dc4

@DrahtBot
DrahtBot requested a review from stickies-v July 14, 2026 12:17
@sedited
sedited merged commit 8d9fbf7 into bitcoin:master Jul 14, 2026
28 checks passed
@github-project-automation github-project-automation Bot moved this from API Development to Done or Closed or Rethinking in The libbitcoinkernel Project Jul 14, 2026
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jul 19, 2026
…ig for btck_TransactionInput

2129e97 kernel: expose scriptSig for btck_TransactionInput (Peter Zafonte)
9a7a217 kernel: expose witness stack for btck_TransactionInput (Peter Zafonte)

Pull request description:

  Silent payments scanning  needs the public key from every input. For SegWit inputs it is in the witness stack. For P2PKH inputs it is in scriptSig. Without these new functions, callers must deserialize the raw transaction themselves to reach that data, which is difficult and error-prone.

  Introduces a `btck_WitnessStack` type and adds the following functions:

  **Witness stack:**
  `btck_transaction_input_get_witness_stack`:  returns a non-owning `const btck_WitnessStack* `view
  `btck_witness_stack_count_items `: item count
  `btck_witness_stack_get_item_at `: single item by index via btck_WriteBytes
  `btck_witness_stack_copy` / `btck_witness_stack_destroy`: lifecycle for owned copies

  **scriptSig:**
  `btck_transaction_input_get_script_sig`: full scriptSig via btck_WriteBytes

  All functions are exposed in the C++ wrapper via `WitnessStackView`, `WitnessStack`, and `WitnessStackApi` , and `GetScriptSig()`.

ACKs for top commit:
  sedited:
    ACK 2129e97
  musaHaruna:
    ACK [6667dc](bitcoin/bitcoin@2129e97)
  stickies-v:
    ACK 2129e97

Tree-SHA512: b5e9d32ec87a5f5a9fea5652ed69737eae1d1f9cfb777544b96d703bbd057c114e0b7afae4e9e9d09b8b546694b14fb923b747c04a8f0211ab6caa015d06967d
sedited pushed a commit to sedited/rust-bitcoinkernel that referenced this pull request Jul 28, 2026
…d9ec7f3d4

70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses
7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response
773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only
8d9e4f8dbd8 Merge bitcoin/bitcoin#35633: wallet: avoid call bumpfeediscount with negative values
c4216e885a6 Merge bitcoin/bitcoin#35723: fuzz: Drop unnecessary mutexes
240d5f743aa fuzz: Drop unnecessary mutexes
cf0368fb76e Merge bitcoin/bitcoin#35720: ipc: Update libmultiprocess subtree and drop fuzz test workaround
2d4065d1fe4 Merge bitcoin/bitcoin#35718: ci: Update lint container dependencies
8d9fbf76664 Merge bitcoin/bitcoin#35380: kernel: expose witness stack and scriptSig for btck_TransactionInput
fab8eeed82c fuzz: clang-format LIMITED_WHILE
fa0d777ce2a fuzz: Clang-format LIMITED_WHILE like while
fa1a9bde5a6 fuzz: Remove unused workaround after fix in libmultiprocess byte-span serializer
fa55385ab36 fuzz: Use LIMITED_WHILE over for-loop with consumed size integral
fa911d815db Merge commit '6d5f753921578eefdd3fce64cfc8ee7951b6cbc4' into HEAD
6d5f7539215 Squashed 'src/ipc/libmultiprocess/' changes from 28e056576a..e8de5c7b68
900a7785bf5 ci: use Ubuntu 26.04 for lint container
058a73a0aea ci: use uv 11.x
14f4ddcb554 ci: mypy 2.3.0
54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job
b0e09511586 ci: disable Qt build in OpenBSD cross job
734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD
ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings
e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip
11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY
e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members
fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code
441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds
0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0
1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess
d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide
a2e4cd7ad2a depends: capnp 1.5.0
7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp`
c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage
63c5f9d22c0 test: Remove `mock_process.cpp`
ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet
b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option
930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4
9b2b3f4ec6f doc: archive release notes for v29.4
297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job
e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact
e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed
a8223bb4e62 wallet: Introduce WalletError with machine-readable error code
fad5809cb92 doc: Update enum class constant naming style guide
7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate
629df81e4c6 Remove myself as security contact
d164a043426 node: smooth oversized `-dbcache` warnings
d9080639804 chainparams: delete my DNS seed
e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk
3679f1ecf5e index: Don't commit ahead of the flushed chainstate
65735728a5a index: Remove return value from Commit()
09c06960c6a validation: track last flushed block
13c02b5466d test: add test for index commits ahead of the last flushed block
c43b7a1115f ci: add netBSD cross CI job
699c21aea47 depends: add netbsd_LDFLAGS
777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen
d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet
ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path
a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12
707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3
6667dc4eec7 kernel: expose scriptSig for btck_TransactionInput
e6de3a2d3c7 kernel: expose witness stack for btck_TransactionInput
3ae3a94f2bd wallet: avoid call bumpfeediscount with negative values
dab7f2c984b test: cover -externalip/onlynet interaction in functional test
657a5aa3f3d test: cover -externalip bypassing -onlynet
8c87e32bd39 net: let -externalip bypass -onlynet
f4af02e827b net: add an add_even_if_unreachable argument to AddLocal
2bab6bc73f2 refactor: Drop support for FreeBSD < 14
91b5c8a07c6 refactor: Remove FreeBSD-specific workaround
56701ff6d5c doc: Clarify supported *BSD releases
6d0ea4cf5bd doc: add release notes
a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage
4c9de7d5b32 external_signer: validate fingerprint from enumerate response
fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields
4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction
9e62e4b1f34 test: slow down rescaning process
a2b0bfcd854 wallet: Drop mapValue from CWalletTx
cb99864c91c wallet: Throw if unknown entry is found in mapValue
98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables
7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables
2155e913d3e wallet: Make CWalletTx "from" and "message" member variables
c6ba98dcc8a wallet: Drop mapValue from CommitTransaction
00abb174a80 wallet: Pass comment and comment_to to CommitTransaction
1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue
72db4accbf5 coins: drop stale cursor null checks
3d2f2d8de09 coins: pass UTXO stats view by reference
35aedb28236 coins: drop cursor from base view
c6fbe2f66cf coins: pass DB view to cursor users
336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip
a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts

git-subtree-dir: libbitcoinkernel-sys/bitcoin
git-subtree-split: 70d9ec7f3d452789d04dce81dc02db0b3b778bb5
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
…ig for btck_TransactionInput

6667dc4eec7b458893920eb7f8631bdf2467c046 kernel: expose scriptSig for btck_TransactionInput (Peter Zafonte)
e6de3a2d3c78d5b72f57bd6a5d711fed97ca70c1 kernel: expose witness stack for btck_TransactionInput (Peter Zafonte)

Pull request description:

  Silent payments scanning  needs the public key from every input. For SegWit inputs it is in the witness stack. For P2PKH inputs it is in scriptSig. Without these new functions, callers must deserialize the raw transaction themselves to reach that data, which is difficult and error-prone.

  Introduces a `btck_WitnessStack` type and adds the following functions:

  **Witness stack:**
  `btck_transaction_input_get_witness_stack`:  returns a non-owning `const btck_WitnessStack* `view
  `btck_witness_stack_count_items `: item count
  `btck_witness_stack_get_item_at `: single item by index via btck_WriteBytes
  `btck_witness_stack_copy` / `btck_witness_stack_destroy`: lifecycle for owned copies

  **scriptSig:**
  `btck_transaction_input_get_script_sig`: full scriptSig via btck_WriteBytes

  All functions are exposed in the C++ wrapper via `WitnessStackView`, `WitnessStack`, and `WitnessStackApi` , and `GetScriptSig()`.

ACKs for top commit:
  sedited:
    ACK 6667dc4eec7b458893920eb7f8631bdf2467c046
  musaHaruna:
    ACK [6667dc](bitcoin/bitcoin@6667dc4)
  stickies-v:
    ACK 6667dc4eec7b458893920eb7f8631bdf2467c046

Tree-SHA512: b5e9d32ec87a5f5a9fea5652ed69737eae1d1f9cfb777544b96d703bbd057c114e0b7afae4e9e9d09b8b546694b14fb923b747c04a8f0211ab6caa015d06967d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done or Closed or Rethinking

Development

Successfully merging this pull request may close these issues.

10 participants