Warn on missing types in contract spec#2426
Merged
leighmcculloch merged 18 commits intomainfrom Mar 5, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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()insoroban-spec-toolsto detect references to undefined UDTs (with built-in exceptions). - Integrate spec verification into
contract buildto emit warnings post-build. - Add hidden
contract spec-verifysubcommand 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 beforeprint_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 bycollect_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,
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add
Spec::verify()tosoroban-spec-toolsthat checks every UDT referenced in function signatures, event params, and type definitions is defined within the spec. Integrate the check intocontract buildto emit warnings after a successful build. Add a hiddencontract spec-verifysubcommand 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