Skip to content

Warn on missing and duplicate types in contract spec - #2426

Merged
leighmcculloch merged 18 commits into
mainfrom
test-spec
Mar 5, 2026
Merged

Warn on missing and duplicate types in contract spec#2426
leighmcculloch merged 18 commits into
mainfrom
test-spec

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Mar 4, 2026

Copy link
Copy Markdown
Member

What

Add Spec::verify() to soroban-spec-tools that checks every UDT referenced in function signatures, event params, and type definitions is defined within the spec. Integrate the check into contract build to emit warnings after a successful build. Add a hidden contract spec-verify subcommand for standalone verification of a WASM file.

Why

Contracts can compile and deploy with incomplete specs when referenced types are missing — for example, due to spec shaking in the SDK. Downstream tooling such as bindings generators and explorers silently fail when types are unresolvable. Surfacing this at build time gives developers an early, actionable signal.

This will also act as a backup safety to help alert us and developers if changes we make and experiment with wrt spec shaking in #2353 cause specs to disappear that were otherwise needed.

Close #2425

@leighmcculloch
leighmcculloch requested review from fnando and mootz12 March 4, 2026 03:02
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Mar 4, 2026
@leighmcculloch
leighmcculloch marked this pull request as ready for review March 4, 2026 03:26
@leighmcculloch
leighmcculloch requested a review from a team as a code owner March 4, 2026 03:27
Copilot AI review requested due to automatic review settings March 4, 2026 03:27

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

Adds contract-spec verification to catch missing user-defined types (UDTs) referenced by function signatures/events/types, and surfaces issues as warnings during stellar contract build, with an additional hidden contract spec-verify command for ad-hoc checks.

Changes:

  • Implement Spec::verify() in soroban-spec-tools to detect references to undefined UDTs (with built-in exceptions).
  • Integrate spec verification into contract build to emit warnings post-build.
  • Add hidden contract spec-verify subcommand to verify a WASM’s spec on demand.

Reviewed changes

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

File Description
cmd/soroban-cli/src/commands/contract/spec_verify.rs New hidden CLI command to run spec verification against a provided WASM.
cmd/soroban-cli/src/commands/contract/mod.rs Wires the hidden spec-verify subcommand into the contract command tree and error plumbing.
cmd/soroban-cli/src/commands/contract/build.rs Runs Spec::verify() after a successful build and prints warnings.
cmd/crates/soroban-spec-tools/src/lib.rs Adds the Spec::verify() implementation, warning type, and unit tests.
Comments suppressed due to low confidence (2)

cmd/soroban-cli/src/commands/contract/build.rs:348

  • This verification block re-reads the built WASM from disk even though the build step already has the pre- and post-optimization bytes in memory. Consider verifying against the existing wasm_bytes/optimized_wasm_bytes (or moving verification before print_build_summary), to avoid redundant IO and reduce the chance of silently skipping verification due to an unexpected read failure.
                // Verify spec references after build
                match fs::read(&final_path) {
                    Ok(final_wasm_bytes) => {
                        match soroban_spec_tools::Spec::from_wasm(&final_wasm_bytes) {
                            Ok(spec) => {
                                for w in spec.verify() {
                                    print.warnln(format!("{}: {}", p.name, w));
                                }

cmd/crates/soroban-spec-tools/src/lib.rs:183

  • verify() can emit duplicate warnings when the same undefined UDT appears multiple times in a single type (e.g., both key and value of a map, or repeated tuple elements), because it unconditionally pushes a warning for every occurrence returned by collect_udt_names. Consider deduplicating by (context, type_name) before pushing to keep build output actionable and avoid warning spam.
                    &input.type_,
                    defined,
                    warnings,
                );
            }
            for output in f.outputs.iter() {
                check_type(
                    &format!("function '{fn_name}' output"),
                    output,

Comment thread cmd/soroban-cli/src/commands/contract/build.rs Outdated
Comment thread cmd/soroban-cli/src/commands/contract/build.rs Outdated
@leighmcculloch
leighmcculloch enabled auto-merge (squash) March 4, 2026 04:17

@mootz12 mootz12 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.

Minor comments inline

Comment thread cmd/soroban-cli/src/commands/contract/spec_verify.rs Outdated
Comment thread cmd/soroban-cli/src/commands/contract/build.rs Outdated
mootz12 and others added 8 commits March 4, 2026 15:18
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
Agent: Claude Code
Agent-Model: claude-opus-4-6
Agent-Session-Id: f65498dc-5afc-4d50-9ebd-ffb1a358a428
@leighmcculloch
leighmcculloch merged commit f8fa22a into main Mar 5, 2026
36 of 37 checks passed
@leighmcculloch
leighmcculloch deleted the test-spec branch March 5, 2026 03:07
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Mar 5, 2026
@leighmcculloch leighmcculloch changed the title Warn on missing types in contract spec Warn on missing and duplicate types in contract spec Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Warn on missing types in contract spec during contract build

3 participants