Skip to content

Task 26: Contract Values Cannot Be Converted Into Readable JSON for Debugging #331

Description

@grantfox-oss

The Soroban Virtual Machine passes all variables, state data, and function arguments using the SCVal (Smart Contract Value) XDR object. An SCVal is a highly complex, recursively nested algebraic data type capable of representing anything from a simple boolean to a massively nested Map of Vectors containing binary data. To provide developers with meaningful diagnostics, Grat must convert these binary SCVal objects into human readable JSON. Without a dedicated converter, Grat developers are forced to read raw hexadecimal bytes or rely on raw Rust Debug dumps (SCVal::Object(SCObject::Map(...))), which are practically unreadable for frontend and Web3 developers who expect standard JavaScript Object Notation.

Issues/what to fix

A sophisticated, recursive transformation engine must be constructed to bridge SCVal and serde_json::Value. The engine must utilize an exhaustive match statement over every single variant of the SCVal enum. Simple types (like SCVal::U32(val)) will map directly to serde_json::json!(val). Complex types are more dangerous: SCVal::Symbol(sym) must be cleanly converted from bytes to a UTF 8 string; SCVal::Vec(vec) must recursively map the converter over every element in the array to produce a serde_json::Value::Array; and SCVal::Map(map) must iterate over key value pairs, recursively converting the keys to JSON strings and the values to JSON objects. Strict limits must be placed on the recursion depth to prevent malicious transactions (e.g., an SCVal nested 10,000 layers deep) from causing a Stack Overflow panic during the conversion process.

Files to create / modify

Create: crates/core/src/decode/scval_to_json.rs

Expected result

Grat will be capable of instantly transforming any cryptographic contract state, function argument, or return value into beautiful, deeply nested JSON objects. This allows the React web application and VSCode extension to render contract state identically to standard Web2 APIs, making Web3 debugging exponentially more accessible.

Contributor telegram group

https://t.me/+sII7WPhll2liMGNk

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions