kernel: expose scriptSig for btck_TransactionInput
What changed, and why it matters
This commit adds a new public function to the Bitcoin Core 'bitcoinkernel' library that lets callers read the scriptSig data from a transaction input. A scriptSig is the part of a Bitcoin transaction input that typically contains a signature and public key proving ownership of the coins being spent. The change only exposes already-existing data through a new API; it does not alter validation rules, consensus logic, or memory handling in a way that would create a security vulnerability. It is a routine API completeness improvement with an accompanying test.
No security action required. Reviewers may optionally verify that the new test vectors match the expected scriptSig values for the referenced transactions, but this is a normal code-quality/API-completeness review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces btck_transaction_input_get_script_sig() in the bitcoinkernel C API, plus a C++ wrapper GetScriptSig() and a unit test. The implementation retrieves the existing CScript scriptSig member from a btck_TransactionInput and writes it out through a caller-supplied btck_WriteBytes callback. The pattern is identical to other read-only serialization helpers in the same file. No memory is allocated by the library for the caller, no parsing of untrusted data occurs beyond the existing transaction deserialization, and no new trust assumptions are introduced.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +29 / −0
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index 92700d16..89674765 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -715,6 +715,12 @@ const btck_WitnessStack* btck_transaction_input_get_witness_stack(const btck_Tra
return btck_WitnessStack::ref(&btck_TransactionInput::get(input).scriptWitness);
}
+int btck_transaction_input_get_script_sig(const btck_TransactionInput* input, btck_WriteBytes writer, void* user_data)
+{
+ const auto& script_sig{btck_TransactionInput::get(input).scriptSig};
+ return writer(script_sig.data(), script_sig.size(), user_data);
+}
+
void btck_transaction_input_destroy(btck_TransactionInput* input)
{
delete input;
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index 09b1caf0..b2228165 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -1697,6 +1697,20 @@ BITCOINKERNEL_API uint32_t btck_transaction_input_get_sequence(
BITCOINKERNEL_API const btck_WitnessStack* btck_transaction_input_get_witness_stack(
const btck_TransactionInput* transaction_input) BITCOINKERNEL_ARG_NONNULL(1);
+/**
+ * @brief Serialize the script sig of a transaction input through the passed
+ * in callback.
+ *
+ * @param[in] transaction_input Non-null.
+ * @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.
+ */
+BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_input_get_script_sig(
+ const btck_TransactionInput* transaction_input,
+ btck_WriteBytes writer,
+ void* user_data) BITCOINKERNEL_ARG_NONNULL(1, 2);
+
/**
* Destroy the transaction input.
*/
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index f84a06ed..b5bee731 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -635,6 +635,10 @@ public:
return WitnessStackView{btck_transaction_input_get_witness_stack(impl())};
}
+ std::vector<std::byte> GetScriptSig() const
+ {
+ return write_bytes(impl(), btck_transaction_input_get_script_sig);
+ }
};
class TransactionInputView : public View<btck_TransactionInput>, public TransactionInputApi<TransactionInputView>
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index 8dc63fd6..f156dc97 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -518,6 +518,10 @@ BOOST_AUTO_TEST_CASE(btck_transaction_input)
BOOST_CHECK_EQUAL(ws_0.CountItems(), 0);
BOOST_CHECK(ws_0.Items().empty());
+ // P2PKH: DER sig + compressed pubkey push.
+ BOOST_CHECK(input_0.GetScriptSig() == hex_string_to_byte_vec("473044022004893432347f39beaa280e99da595681ddb20fc45010176897e6e055d716dbfa022040a9e46648a5d10c33ef7cee5e6cf4b56bd513eae3ae044f0039824b02d0f44c012102982331a52822fd9b62e9b5d120da1d248558fac3da3a3c51cd7d9c8ad3da760e"));
+ BOOST_CHECK(input_1.GetScriptSig() == hex_string_to_byte_vec("473044022068bcedc7fe39c9f21ad318df2c2da62c2dc9522a89c28c8420ff9d03d2e6bf7b0220132afd752754e5cb1ea2fd0ed6a38ec666781e34b0e93dc9a08f2457842cf5660121033aeb9c079ea3e08ea03556182ab520ce5c22e6b0cb95cee6435ee17144d860cd"));
+
// P2WSH input: OP_0, sig, sig, redeem_script (0, 71, 71, 105 bytes); no scriptSig.
Transaction segwit_tx{hex_string_to_byte_vec("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000")};
TransactionInputView segwit_input = segwit_tx.GetInput(0);
@@ -535,6 +539,7 @@ BOOST_AUTO_TEST_CASE(btck_transaction_input)
WitnessStack owned_ws_0{ws_0};
WitnessStack owned_ws{ws};
CheckHandle(owned_ws_0, owned_ws);
+ BOOST_CHECK(segwit_input.GetScriptSig().empty());
}
BOOST_AUTO_TEST_CASE(btck_precomputed_txdata) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.