Skip to content

fix: validate SVM optional parameter presence - #1449

Merged
Reinis-FRP merged 4 commits into
masterfrom
reinis-frp/consistent-optionals
Aug 5, 2026
Merged

fix: validate SVM optional parameter presence#1449
Reinis-FRP merged 4 commits into
masterfrom
reinis-frp/consistent-optionals

Conversation

@Reinis-FRP

@Reinis-FRP Reinis-FRP commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds consistency validation for SVM instructions that can load optional parameters either from instruction data or from the instruction_params account.

The validation requires each optional argument group to be consistently present or absent, and requires that presence to be opposite the instruction_params account presence. This prevents callers from supplying conflicting values through both input paths.

This fix has been reviewed by auditors and has already been deployed onchain.

Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
@Reinis-FRP
Reinis-FRP force-pushed the reinis-frp/consistent-optionals branch from 9fd883e to 9b62bf2 Compare June 2, 2026 13:09
Reinis-FRP and others added 3 commits June 2, 2026 13:46
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
@Reinis-FRP
Reinis-FRP marked this pull request as ready for review July 17, 2026 12:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b619aa238

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +75 to +77
constraint = has_valid_params_presence(
&[relay_data.is_some(), repayment_chain_id.is_some(), repayment_address.is_some()],
instruction_params.is_some()) @ SvmError::InconsistentOptionalParameters,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Move fill optional-parameter check before unwrapping

When fill_relay is called with relay_data set to None and the optional instruction_params account omitted, this constraint is never reached: Anchor validates the earlier mint and recipient_token_account constraints first, and both unwrap instruction_params.as_ref().unwrap() while it is None. That inconsistent-parameter case still aborts with a panic/program failure instead of returning InconsistentOptionalParameters, so the new validation should be attached to an earlier account such as state before any constraint reads the optional parameters.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for flagging this. I checked the actual generated Rust at 9b619aa238bccc89226bc4904b1dcec77a942c77 using Anchor CLI 0.31.1:

anchor expand -p svm_spoke

The generated FillRelay::try_accounts does not validate the ordinary account constraints in struct declaration order. Its relevant processing order is:

  1. Deserialize the instruction arguments and parse/extract all account wrappers. This does not evaluate the mint or recipient constraint expressions.
  2. Process the fill_status init_if_needed block.
  3. Run has_valid_params_presence(...); on the relay_data = None plus omitted instruction_params case, this returns InconsistentOptionalParameters.
  4. Only after that, run is_relay_hash_valid(...), which contains the first relevant unwrap.
  5. Later, run the mint address constraint and then the recipient ATA constraint, which contain the other unwraps.

This ordering follows directly from the Anchor 0.31.1 generator:

The expansion therefore confirms that the presence check is reached before any of these optional-parameter unwraps. Moving it to state is not necessary for this case, and the current placement is safe against the panic described here.

🤖 Reinis Codex coding agent

@Reinis-FRP
Reinis-FRP merged commit c9b7218 into master Aug 5, 2026
9 checks passed
@Reinis-FRP
Reinis-FRP deleted the reinis-frp/consistent-optionals branch August 5, 2026 12:04
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

Successfully merging this pull request may close these issues.

3 participants