Skip to content

DiagnosticEventWalker: pinpoint failing contracts in call chains (#339) - #365

Merged
codeZe-us merged 1 commit into
Toolbox-Lab:mainfrom
Marvelg256:feat/339-diagnostic-event-walker
Jul 19, 2026
Merged

DiagnosticEventWalker: pinpoint failing contracts in call chains (#339)#365
codeZe-us merged 1 commit into
Toolbox-Lab:mainfrom
Marvelg256:feat/339-diagnostic-event-walker

Conversation

@Marvelg256

Copy link
Copy Markdown
Contributor

Summary

Implements DiagnosticEventWalker — a chronological event walker that maintains a contract call stack to identify the exact contract that caused a failure in multi-contract Soroban transactions.

Closes #339

Problem

When a multi-contract Soroban transaction fails (e.g., Contract A → B → C, where C panics), the raw result only shows the top-level invocation failed. Grat would mistakenly blame Contract A for errors deep in Contract C, sending developers on wild goose chases.

Solution

A new module crates/core/src/decode/event_walker.rs provides DiagnosticEventWalker with a locate_failing_contract() method that:

  1. Walks events chronologically — processes DiagnosticEvent objects in the order the VM emitted them
  2. Maintains a call stack — pushes callee contract IDs on fn_call system events, pops on fn_return
  3. Detects failures via multiple indicators:
    • in_successful_contract_call = false (VM flag)
    • ScVal::Error payload (HostError/ContractError return values)
    • Topic keywords: error, panic, revert, hosterror, failed, trap
  4. Halts on first failure — returns the contract ID at the top of the stack at the exact moment of failure
  5. Handles edge cases — first-instruction panics (empty stack fallback to the event's own contract_id), fn_call without contract_id, nested calls with returns

Files Changed

  • crates/core/src/decode/event_walker.rs (new) — 413 lines implementing the walker with 16 unit tests
  • crates/core/src/decode/mod.rs — added pub mod event_walker;

Testing

All 252 tests pass, including 16 new tests covering:

  • Direct failure detection (A calls B, B panics → returns B)
  • Nested chain failure (A → B → C, C panics → returns C)
  • First-instruction panic (empty stack fallback)
  • No-failure scenarios (returns None)
  • Chronological halt (first failure wins)
  • All failure indicators (error, panic, revert, hosterror, ScVal::Error, failed, trap)
  • Stack discipline (push on fn_call, pop on fn_return)
  • System events without contract_id (no stack corruption)

…hains

Implements a chronological event walker that maintains a call stack of
contract IDs (pushing on fn_call, popping on fn_return) to identify
the exact contract that failed in multi-contract Soroban transactions.

Closes Toolbox-Lab#339
@Marvelg256
Marvelg256 force-pushed the feat/339-diagnostic-event-walker branch from b1814f3 to 00c330e Compare July 18, 2026 20:20
@codeZe-us
codeZe-us self-requested a review July 19, 2026 14:22
@codeZe-us
codeZe-us merged commit 37db388 into Toolbox-Lab:main Jul 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task 27: Grat Cannot Identify Which Contract in a Call Chain Actually Failed

2 participants