Skip to content

Task 23: Contract Struct Definitions Are Not Parsed From WASM Metadata #328

Description

@grantfox-oss

Within the Soroban ecosystem, smart contracts are compiled into WebAssembly (WASM) binaries. Embedded within these binaries are custom sections containing the contractspecv0 metadata, which strictly defines the data structures (structs, enums, functions) utilized by the contract. While the current decoder.rs successfully extracts functions and error enums, it completely ignores SCSpecEntry::UdtStructV0. Structs are the lifeblood of complex Soroban applications, representing state objects like user balances, configuration parameters, and complex DeFi order books. Without parsing these structures, Grat cannot dynamically decode the internal properties of a returned SCVal object. This forces developers to manually reverse engineer raw XDR arrays into structs, completely defeating the purpose of an automated debugging tool.

Issues/what to fix

The WASM parsing logic inside crates/core/src/spec/decoder.rs must be expanded. The codebase currently iterates through a payload of ScSpecEntry objects. We must add a new match arm specifically for ScSpecEntry::UdtStructV0(struct_spec). When this entry is matched, the parser must algorithmically extract the struct's name and iteratively map over its fields. Each field contains a name and a corresponding ScSpecTypeDef (which defines if the field is a U32, a String, or another nested Struct). This extracted data must be mapped into a new Rust struct (e.g., ContractStructDef), serialized into an optimized, cacheable format, and appended to the overarching ContractSpec object. Crucially, the implementation must be memory safe, ensuring that malformed WASM binaries with infinite recursive struct definitions cannot trigger a Stack Overflow during the parsing phase.

Files to create / modify

Modify: crates/core/src/spec/decoder.rs

Expected result

The SpecParser will become fully aware of all custom data structures defined by a smart contract. When a transaction returns a complex struct, Grat will leverage this parsed metadata to accurately map the raw XDR array elements to their human readable field names, transforming a cryptic list of bytes into a perfectly readable, labeled JSON object.

Contributor telegram group

https://t.me/+sII7WPhll2liMGNk

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions