Skip to content

Fix panic in contract info interface when WASM has env meta but no spec - #2682

Open
Galmanus wants to merge 1 commit into
stellar:mainfrom
Galmanus:fix/2429-interface-unwrap-panic
Open

Fix panic in contract info interface when WASM has env meta but no spec#2682
Galmanus wants to merge 1 commit into
stellar:mainfrom
Galmanus:fix/2429-interface-unwrap-panic

Conversation

@Galmanus

Copy link
Copy Markdown

Fixes #2429.

contractenvmetav0 and contractspecv0 are independent WASM custom sections, so a WASM can carry env meta without a spec. contract info interface guarded on env_meta_base64 being present but then called .unwrap() on spec_base64 — a completely independent field — and panicked instead of reporting no interface present in provided WASM file.

Fix

  • Extract the WASM branch of run() into spec_from_wasm() so it is unit-testable.
  • Replace the unwrap() with a clean NoInterfacePresent error, keeping the existing check order and semantics otherwise.

Tests

Regression tests build minimal WASM modules with wasm-encoder (added as a dev-dependency; already used by soroban-spec-tools tests at the same version):

  • env_meta_without_spec_returns_no_interface_error — the panic case; failed with called Option::unwrap() on a None value before the fix.
  • missing_env_meta_returns_no_interface_error — existing behavior preserved.

…spec

`contractenvmetav0` and `contractspecv0` are independent custom sections,
so a WASM can carry env meta without a spec. The command guarded on
`env_meta_base64` being present but then unwrapped `spec_base64`,
panicking instead of reporting "no interface present".

Extract the WASM branch into `spec_from_wasm` so it is unit-testable,
replace the unwrap with a clean `NoInterfacePresent` error, and add
regression tests that build minimal WASM modules with `wasm-encoder`
(already used by soroban-spec-tools tests).

Fixes stellar#2429
Copilot AI balanced review requested due to automatic review settings August 14, 2026 23:01
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors Soroban contract interface extraction to avoid a potential panic when a WASM contains env meta but no spec, and adds regression coverage for the scenario.

Changes:

  • Extracted WASM spec parsing into spec_from_wasm, adding an explicit guard for missing contractspecv0.
  • Added unit tests that build minimal WASM modules with custom sections to cover missing/partial interface cases.
  • Added wasm-encoder dependency to support generating minimal WASM binaries in tests.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
cmd/soroban-cli/src/commands/contract/info/interface.rs Refactor spec parsing into helper and add regression/unit tests for missing spec sections
cmd/soroban-cli/Cargo.toml Add wasm-encoder dependency used by the new test helpers

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


let result = spec_from_wasm(&wasm);

assert!(matches!(result, Err(Error::NoInterfacePresent())));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Checked this against the enum definition — NoInterfacePresent is a zero-field tuple variant (declared NoInterfacePresent() at line 41), not a unit variant. For a zero-field tuple variant, Err(Error::NoInterfacePresent()) is the correct pattern. The two suggested alternatives don't compile here: Error::NoInterfacePresent fails with E0532 (expected unit variant, found tuple variant) and Error::NoInterfacePresent(_) fails with E0023 (pattern has 1 field, variant has 0). CI compiles and passes on the current form, so I'll keep matches!(result, Err(Error::NoInterfacePresent())).


let result = spec_from_wasm(&wasm);

assert!(matches!(result, Err(Error::NoInterfacePresent())));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same as the assertion above: NoInterfacePresent is a zero-field tuple variant (defined NoInterfacePresent() at line 41), so Err(Error::NoInterfacePresent()) is the correct pattern. Error::NoInterfacePresent would fail with E0532 and Error::NoInterfacePresent(_) with E0023 — neither compiles. Keeping the current form; CI confirms it builds and passes.

walkdir = "2.5.0"
mockito = "1.5.0"
serial_test = "3.0.0"
wasm-encoder = "0.235.0"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

wasm-encoder is already under [dev-dependencies] — it's at line 145, inside the [dev-dependencies] block that starts at line 138. It's only referenced by the #[cfg(test)] module in interface.rs, so it doesn't add a runtime/build dependency for non-test builds. No change needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

Panic on unwrap() of spec_base64 in contract info interface when contract has env_meta but no spec

2 participants