Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ix precondition in simplicity_build_txEnv unenforced #281

Open
roconnor-blockstream opened this issue Jan 7, 2025 · 0 comments
Open

ix precondition in simplicity_build_txEnv unenforced #281

roconnor-blockstream opened this issue Jan 7, 2025 · 0 comments

Comments

@roconnor-blockstream
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant