Skip to content

ix precondition in simplicity_build_txEnv unenforced #281

@roconnor-blockstream

Description

@roconnor-blockstream

One of the preconditions listed in simplicity_build_txEnv is that ix < tx->numInputs.

/* Contstruct a txEnv structure from its components.
* This function will precompute any cached values.
*
* Precondition: NULL != tx
* NULL != taproot
* NULL != genesisHash
* ix < tx->numInputs
*/
txEnv simplicity_build_txEnv(const transaction* tx, const tapEnv* taproot, const sha256_midstate* genesisHash, uint_fast32_t ix);

However at the call site, this is not ensured.

txEnv env = simplicity_build_txEnv(tx, taproot, &genesis_hash, ix);

The ix value is passed straight into simplicity_build_txEnv.

AFAICT, there are no bad consequences to this at the moment. env->ix is only used in elementsJets.c, and it is checked before ever being used as an array index.

The solution is to either list ix in the preconditions of simplicity_elements_execSimplicity, or check the ix value in that function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions