Skip to content

feat: allow re-use of PrecomputedTransactionData during verification #46

@joshdoman

Description

@joshdoman

The ability to re-use deserialized data types makes this library very useful when verifying multiple inputs in a transaction. The only remaining problem is that there is still a risk of quadratic hashing, without a cached PrecomputedTransactionData that can be re-used across inputs.

I'm not sure what the answer is, but I think it may be worth updating the verify API or introducing a second verify_with_precomputed_data API, so that quadratic hashing can be avoided. In either case, a new API to get the precomputed transaction data would be required.

Possible API:

fn get_precomputed_tx_data(
    tx_to: &impl TransactionExt,
) -> Result<PrecomputedTransactionData, KernelError>;

// Uses `precomputed_data` if Some, otherwise proceeds as-is.
fn verify(
    script_pubkey: &impl ScriptPubkeyExt,
    amount: Option<i64>,
    tx_to: &impl TransactionExt,
    precomputed_data: Option<&impl PrecomputedTransactionDataExt>,
    input_index: usize,
    flags: Option<u32>,
    spent_outputs: &[impl TxOutExt],
) -> Result<(), KernelError>;

Alternatively:

fn get_precomputed_tx_data(
    tx_to: &impl TransactionExt,
) -> Result<PrecomputedTransactionData, KernelError>;

fn verify_with_precomputed_data(
    script_pubkey: &impl ScriptPubkeyExt,
    amount: Option<i64>,
    tx_to: &impl TransactionExt,
    precomputed_data: &impl PrecomputedTransactionDataExt,
    input_index: usize,
    flags: Option<u32>,
    spent_outputs: &[impl TxOutExt],
) -> Result<(), KernelError>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions