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

Open
#2,429 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
cli

Research direction

Start at cmd/soroban-cli/src/commands/contract/info/interface.rs around lines 55-59 and inspect how the two WASM metadata fields are handled. Run stellar contract info interface against a WASM binary with env_meta but no spec; done means it returns NoInterfacePresent instead of panicking.

Written by the indexing model from the issue text.

Description

bug
What version are you using?

All versions containing the current implementation of contract info interface (at least as of commit aef2923).

What did you do?

Ran stellar contract info interface against a WASM binary that contains the contractenvmetav0 custom section but omits the contractspecv0 custom section.

What did you expect to see?

A user-friendly error message (NoInterfacePresent), consistent with how the command handles other cases of missing metadata.

What did you see instead?

The CLI panics with an unwrap() on None at cmd/soroban-cli/src/commands/contract/info/interface.rs:59.

Root cause: The guard at line 55 checks whether env_meta_base64 is Some, but line 59 then calls .unwrap() on spec_base64 — a completely independent field. These two fields come from separate WASM custom sections (contractenvmetav0 and contractspecv0) and there is no guarantee that the presence of one implies the presence of the other.

let spec = Spec::new(&wasm_bytes)?;

if spec.env_meta_base64.is_none() {
    return Err(NoInterfacePresent());
}

(spec.spec_base64.unwrap(), spec.spec)  // panics if spec_base64 is None

Suggested fix:

let spec = Spec::new(&wasm_bytes)?;

let base64 = spec.spec_base64.ok_or(NoInterfacePresent())?;
let _ = spec.env_meta_base64.ok_or(NoInterfacePresent())?;

(base64, spec.spec)
Dominant language
Rust
Stars
123
Forks
141
Avg merge
2d 21h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/stellar-cli

All issues in stellar/stellar-cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.