[kernel] Expose CheckTransaction consensus validation function #33796

pull w0xlt wants to merge 1 commits into bitcoin:master from w0xlt:kernel_checktransaction changing 4 files +364 −8
  1. w0xlt commented at 11:59 pm on November 5, 2025: contributor

    This PR exposes the consensus-level CheckTransaction function through the libbitcoinkernel C API and adds a corresponding C++ wrapper.

    Currently, libkernel only provided script-level validation via btck_script_pubkey_verify and ScriptPubkeyApi<>::Verify.

    AFAIK there was no way to perform context-free consensus checks on a transaction’s structure (e.g., coinbase rules, money-range, duplicate inputs).

    This change introduces a new API:

    0int btck_check_transaction(const btck_Transaction* tx, btck_TxValidationState** out_state);
    

    and a C++ convenience wrapper:

    0std::pair<bool, TxValidationState> btck::CheckTransaction(const Transaction& tx);
    

    Both follow the ownership and error-handling conventions established in bitcoinkernel.h.

    The test suite is extended with cases covering:

    • coinbase scriptSig length bounds
    • empty vin / vout detection
    • negative or out-of-range output values
    • duplicate inputs
    • null prevouts in non-coinbase transactions
  2. [kernel] Expose `CheckTransaction` consensus function a262282abe
  3. DrahtBot commented at 11:59 pm on November 5, 2025: 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/33796.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK TheCharlatan

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. in src/kernel/bitcoinkernel.h:367 in a262282abe
    362+#define btck_TxValidationResult_WITNESS_STRIPPED    ((btck_TxValidationResult)(7))
    363+#define btck_TxValidationResult_CONFLICT            ((btck_TxValidationResult)(8))
    364+#define btck_TxValidationResult_MEMPOOL_POLICY      ((btck_TxValidationResult)(9))
    365+#define btck_TxValidationResult_NO_MEMPOOL          ((btck_TxValidationResult)(10))
    366+#define btck_TxValidationResult_RECONSIDERABLE      ((btck_TxValidationResult)(11))
    367+#define btck_TxValidationResult_UNKNOWN             ((btck_TxValidationResult)(12))
    


    l0rinc commented at 9:04 am on November 6, 2025:
    shouldn’t this be bigger than 12 (or could maybe be 0) so that new values can be added in the future?
  5. TheCharlatan commented at 11:01 am on November 6, 2025: contributor

    Concept ACK on adding more checks. I am not sure how useful this check by itself is though, since it lacks finality, inputs, sigops, amount + fee, and script checks. Are you planning on adding these too and if not, what is the purpose served from surfacing the context-free checks, but not the others?

    I think the unit tests are going a bit too far. We don’t have to verify again that our validation logic works internally and should instead just verify that the function’s contract is correct. If you want to check that the mapping for each of the result enums is correct maybe pass in a few hard-coded transactions instead? We do the same in our unit tests too so maybe just reuse a few of the vectors from test/data/tx_invalid.json?

  6. w0xlt commented at 6:44 pm on November 6, 2025: contributor

    I am not sure how useful this check by itself is … what is the purpose served from surfacing the context‑free checks, but not the others?

    The new API intentionally exposes only the context‑free consensus predicate (consensus/tx_check::CheckTransaction) so callers can fail fast on malformed transactions without needing a kernel context, UTXO set, or policy knobs.

    This gives library users (indexers, gateways, alternative mempool layers, etc.) a cheap pre‑filter to catch structural rule violations like empty vin/vout, out‑of‑range amounts, coinbase scriptSig length bounds, duplicate inputs, or null prevouts in non‑coinbase txs—before doing any stateful or expensive work.

    Script checks are already available via btck_script_pubkey_verify in this API; inputs/fees/sigops/finality all need UTXO and/or chain context and are out of scope for a context‑free entry point.

    think the unit tests are going a bit too far … instead just verify that the function’s contract is correct.

    Agreed. This can be simplified.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-07 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me