Skip to content

Infer proven post-state balance/allowance deltas (replace event-only approval heuristic) #105

@Th0rgal

Description

@Th0rgal

Problem

Remaining token approvals is currently inferred from Approval events only. This is lossy:

  • transfers/transferFrom can change allowance without emitting a new Approval event (common token behavior)
  • event-only inference can over-report stale approvals
  • users can see movement events that suggest spend happened while UI still warns allowance remains

Goal

Compute post-state token allowances and balance changes from simulation/replay state, and attach RPC proofs so the desktop verifier can validate those post-state claims offline.

Scope

  1. Infer all touched token balances and allowance slots from simulation trace/replay context.
  2. For each touched account/token slot, fetch post-state values at pinned block context and include proofs.
  3. Extend evidence package with a postStateEffects artifact (or equivalent) containing:
    • native balances changed
    • ERC-20 balances changed
    • ERC-20 allowances changed (owner, spender, token, before, after)
    • proof material for each claimed slot/account
  4. Verify these proofs in desktop/CLI against the same anchored state root.
  5. Render approvals as actual post-state deltas (not event heuristic), and keep event-based display as fallback only.

Design constraints

  • Keep chain anchor consistency: simulation/witness/proof must reference same block+state root.
  • Preserve witness-only flow semantics.
  • Do not rely on token event emission behavior for approval correctness.

Acceptance criteria

  • For a tx where allowance is consumed without an Approval event, UI shows correct post-state allowance.
  • For a tx where approval is revoked to zero, UI does not show it as remaining.
  • Post-state effects fail closed when proofs are missing/invalid.
  • Desktop and generator display the same approval/balance conclusions for the same package.
  • Add regression tests covering:
    • no-approval-event allowance decrease
    • explicit revoke-to-zero
    • unchanged allowance
    • partial proof/missing proof failure paths

Related

  • Current heuristic implementation: packages/core/src/lib/simulation/summary.ts (computeRemainingApprovals)
  • Event decoder basis: packages/core/src/lib/simulation/event-decoder.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions