Skip to content

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

@leighmcculloch

Description

@leighmcculloch

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog (Not Ready)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions