← Back to Pull requests

fix(runtime): UAF causing nondeterministic slot mismatches #1697

Closed
unknown closed this pull request without merging on Jul 14, 2026 13:29 UTC
View on GitHub
unknown unknown commented on Jul 08, 2026 14:44 UTC
Author

Intent

  • Fix slot hash mismatch caused by racey ProgramMap logic
  • sequenceDiagram
        participant A as Worker A
        participant M as ProgramMap
        participant B as Worker B
    
        A->>M: contains(P)? no
        B->>M: contains(P)? no
        Note over A,B: no lock held, each loads its own copy
        A->>A: loadProgram → E
        B->>B: loadProgram → E'
    
        A->>M: fetchPut(P, E) → inserts E
        A->>M: get(P) → copies handle into E
        Note over A: VM dereferences E, no lock
    
        B->>M: fetchPut(P, E') → inserts E', returns E
        B->>B: deinit(E) → frees E's buffers
        A--xA: VM reads freed buffers → UAF
    

    Implementation

  • Replaced the ProgramMap.fetchPut call in loadIfProgram with new ProgramMap.putIfAbsent call
  • Ramifications

  • These updates ensure a racing concurrent first-load can no longer replace and free a cached program that another worker is still executing against. Invoking the same program only takes a read-only account lock, so two workers can both miss the cache and load in parallel. The losing worker now discards its redundant copy instead of fetchPut-ing over the live entry. This fixes the use-after-free that caused divergent account writes and a non-deterministic bank hash.

  • While trying to reproduce this slot hash mismatch using replay-offline, I ran into several successful runs outputting 0 mismatches even though previous runs had mismatches. Due to the racey nature of this bug, the current state of replay-offline could _potentially_ overwrite any captured Ledger with correct slot hashes, concealing the bug entirely. An update to replay-offline _can_ be made involving adding a flag to Ledger and any other related data structs, but this that can be done in a separate PR.
  • Tests

  • Added a regression test to this codepath
  • Diff: 229 lines (+171 / -58) across 2 files Reviewer: ajw221 Review duration: 8565m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 229 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.325
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1697"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.0% (MEDIUM) · Higher = larger blast radius
    37.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.6% · Safe to merge
    14.6%
    Repository