Skip to content

Task 33: Developers Get No Breakdown of Which Resource Budget Caused a Transaction Failure #347

Description

@grantfox-oss

Soroban smart contracts are subject to strict computational boundaries defined by the network's dynamically shifting fee budgets. Every contract transaction is allocated a specific threshold for CPU instructions, Memory bytes, Ledger Reads, and Ledger Writes. If a contract attempts to execute an instruction or read a byte that pushes it over its budget, the Soroban Virtual Machine will instantly terminate the transaction with a HostError indicating a Budget or Storage limit has been exceeded. Currently, Grat only tells the developer that they ran out of gas, but it does absolutely nothing to help them optimize their code. Developers are left completely guessing whether they were over budget by 1 byte or 10 megabytes, making performance tuning incredibly frustrating.

Issues/what to fix

A rigorous analytical module named ResourceUsageAnalyzer must be developed. This module will ingest the TransactionResultMeta and specifically extract both the resources_allocated (from the initial simulation/fee bump) and the resources_consumed (from the actual execution). The analyzer must iterate through four distinct metrics: CPU, Memory, Reads, and Writes. For each metric, it must perform a mathematical comparison, calculating the exact delta between allocated and consumed. It must determine the precise percentage utilization. If a transaction fails with a BudgetError, this analyzer must specifically flag which of the four metrics breached the 100% threshold. The output must be encapsulated into a ResourceDiagnostics struct, ready to be rendered graphically by downstream formatters.

Files to create / modify

Create: crates/core/src/decode/resource_analyzer.rs
Modify: crates/core/src/decode/mod.rs

Expected result

Developers will receive a highly surgical breakdown of their contract's computational efficiency. If their transaction fails due to a memory limit, Grat will explicitly output: "Memory Utilization: 105% (Allocated: 10,000 bytes, Consumed: 10,500 bytes. Overage: 500 bytes)." This perfectly isolates the optimization targets for the developer.

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