Skip to content

Task 29: Grat Cannot Decode Which Function and Arguments a Transaction Actually Called #342

Description

@grantfox-oss

Every Soroban transaction begins with a Host Function Invocation, which is the exact command instructing the VM to execute a specific function on a specific contract with a specific set of arguments. In the raw XDR, this invocation is encoded as an untyped array of raw bytes (SCVec). Without decoding this invocation, developers cannot verify if they accidentally passed the wrong variables to their contract. Currently, Grat has no logic to map the raw argument array against the contract's actual function signature, meaning it cannot confidently tell the user what function they actually called or what parameters they supplied.

Issues/what to fix

A new analytical module named FunctionCallDecoder must be created. This module takes the raw XDR HostFunction object as input. First, it must extract the target function_name (a Symbol) and the raw args (SCVec). It must then utilize the SpecParser to retrieve the contract's ContractFunction metadata that matches the function_name. Once matched, the decoder must utilize a zip algorithm to iterate over the function's expected parameter list alongside the raw XDR arguments array simultaneously. For each pair, it must utilize the SCVal to JSON Converter to parse the argument, attaching the expected parameter name to the output. If the number of provided arguments does not match the expected parameters, the decoder must intercept the arity mismatch and throw a highly descriptive GratError::ArityMismatch.

Files to create / modify

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

Expected result

Grat will be able to reconstruct the exact function call that initiated the transaction. Developers will be presented with a beautiful, fully labeled summary of their invocation (e.g., transfer(from: "G...", to: "G...", amount: 1000)), making it incredibly easy to spot logical errors or typos in their input payloads.

Contributor telegram group

https://t.me/+sII7WPhll2liMGNk

Metadata

Metadata

Assignees

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