{
  "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved.",
  "engine": {
    "tries": 478406,
    "hits": 45134,
    "hit_rate": 0.09434334665773285,
    "calls": 701765,
    "seeds": [
      10005100,
      10005163
    ],
    "calibration": {
      "loop_iterations": 100,
      "measured_extra_gas_per_iteration_block": 22889.0,
      "calibration_seeds": [
        10005132,
        10005163
      ],
      "tries_extra_gas": 10950239064,
      "hits_extra_gas": 1033082200,
      "v0_sum_ok_gas": 93399019735,
      "v1_sum_ok_gas": 104349258799,
      "v2_sum_ok_gas": 94432101935,
      "V0_mean_gas": 133091.59011207457,
      "V1_mean_gas": 148695.44476997285,
      "V2_mean_gas": 134563.70998126152,
      "calibration_V0_sum_ok_gas": 47349340483,
      "calibration_loop_sum_ok_gas": 55499907382,
      "branch_overhead_sensitivity": "The gas inversion includes the conditional branch and is approximate; allowing a 0..337 count branch-cost correction moves hit_rate to about 0.0936..0.0943."
    },
    "reference_replica_hit_rate": 0.7833859154613871,
    "reference_counts": {
      "hits": 279592,
      "misses": 77310,
      "source_artifact": "https://api.imd.fun/artifacts/5718a00bf95a80e2c2f0073071fa9b94d59be643e3e577793b9fd3e9cd2cc354"
    },
    "max_peak_gas_primary_variants": 207699,
    "out_of_gas_primary_variants": 0
  },
  "tolerance_scan": {
    "measurement": "Same 100-round burn on accepts; V2 minus matched no-burn V0; divide by the measured 22,889 gas burn.",
    "results": [
      {
        "relative_tolerance": "1e-9",
        "tries_estimate": 478406,
        "hits_gas_estimate_raw": 478743,
        "hits_estimate_capped": 478406,
        "hit_rate_estimate_capped": 1.0,
        "burn_gas_delta": 10957948372,
        "calls": 701765,
        "max_peak_gas": 207791,
        "out_of_gas": 0,
        "note": "Raw inversion is 337 above tries (0.07%); capped at the physical maximum. The two tolerances have identical measured gas totals."
      },
      {
        "relative_tolerance": "1e-6",
        "tries_estimate": 478406,
        "hits_gas_estimate_raw": 478743,
        "hits_estimate_capped": 478406,
        "hit_rate_estimate_capped": 1.0,
        "burn_gas_delta": 10957948372,
        "calls": 701765,
        "max_peak_gas": 207791,
        "out_of_gas": 0,
        "note": "Raw inversion is 337 above tries (0.07%); capped at the physical maximum. The two tolerances have identical measured gas totals."
      }
    ],
    "replica_reference_hit_rate": 0.7833859154613871
  },
  "edges_equal_lean": true,
  "router_differs": true,
  "differences": [
    {
      "what": "CFMM quote invariant: Rust recomputes k from the current floating-point reserves at each quote; replica uses the fixed K=1,000,000 in quote updates. This is consistent with the exact-test hit-rate collapse, but the causal contribution is not isolated.",
      "engine_line": "amm_sim_rs/src/amm/cfmm.rs:131, 152, 180 \u2014 https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/amm/cfmm.rs#L131",
      "replica_line": "research/solved/replica2.py:11, 50-60, 104-108 \u2014 https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py#L11",
      "size_of_effect": "Observed exact hit rate 9.43% on the engine versus 78.34% in the pinned replica reference (\u221268.90 percentage points); this aggregate gap is not attributable to k alone."
    },
    {
      "what": "Two-pool split algebra matches. Execution order differs: Rust constructs [submission, normalizer] and executes the first AMM leg before the second; replica executes rival u2 before own u1. Both legs are computed from the same pre-execution reserves and affect separate pools.",
      "engine_line": "simulation/engine.rs:120 and market/router.rs:194-210 \u2014 https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs#L120",
      "replica_line": "research/solved/replica2.py:103-112 \u2014 https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py#L103",
      "size_of_effect": "Zero on split amounts and final pool reserves in this independent-pool route; callback timing differs, and the router algebra itself is the same."
    },
    {
      "what": "Engine callback TradeInfo amounts and reserves are converted through Wad::from_f64 (18 decimal places, truncating to i128); replica passes Python float state directly.",
      "engine_line": "amm_sim_rs/src/amm/cfmm.rs:211-218 and types/wad.rs:32 \u2014 https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/types/wad.rs#L32",
      "replica_line": "research/solved/replica2.py:70-75, 108-113 \u2014 https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py#L70",
      "size_of_effect": "Callback values pass through f64 multiplication by 1e18 and an i128 cast; the resulting rounding/truncation varies with magnitude. Its exact-label impact was not isolated."
    }
  ],
  "engine_exact_test": {
    "formula": {
      "buy": "A_i=sqrt(x_i*(1-f_i)*y_i); r=A_1/A_2; Y_1=clamp((r*(y_2+(1-f_2)*Y_total)-y_1)/((1-f_1)+r*(1-f_2)),0,Y_total).",
      "sell": "B_i=sqrt(y_i*(1-f_i)*x_i); r=B_1/B_2; X_1=clamp((r*(x_2+(1-f_2)*X_total)-x_1)/((1-f_1)+r*(1-f_2)),0,X_total)."
    },
    "state_needed": [
      "Both pools' pretrade reserves",
      "Both directional fees",
      "Order side and total order size (and fair price to convert sell size)."
    ],
    "callback_has_state": false,
    "reason": "The engine applies these same router formulas, but afterSwap TradeInfo exposes only the submission pool trade and post-trade reserves; it does not expose the normalizer reserves or the unsplit total order. qHit therefore cannot reproduce the exact router decision from callback state alone."
  },
  "ledger": {
    "engine_seeds_used": {
      "range_inclusive": [
        10005100,
        10005163
      ],
      "n_seeds": 64,
      "completed_arms_primary": [
        "V0",
        "V1",
        "V2",
        "LEAN",
        "V1b",
        "V2b",
        "Vcal100",
        "V1log",
        "V1t",
        "VcalAll100"
      ],
      "completed_arms_tolerance": [
        "V0_tol1e9",
        "V2_tol1e9",
        "V0_tol1e6",
        "V2_tol1e6"
      ],
      "gas_calibration_range_used": [
        10005132,
        10005163
      ],
      "gas_calibration_n": 32,
      "burnt_or_failed_seed_rows": 0,
      "main_driver_burnt_or_failed_seed_rows": 0,
      "meaning": "Completed primary/tolerance ledgers report no burnt or failed rows."
    },
    "driver_artifact": "https://api.imd.fun/artifacts/764c9461a9f3bab6e277178f4bb48553d1b97c6cca33bed016f7c9bfd611cc42",
    "excluded_interrupted_attempt": {
      "range": [
        10005100,
        10005131
      ],
      "arm": "VcalAll100",
      "returned_rows": 0,
      "note": "A duplicate calibration driver attempt was interrupted; its rows are excluded. The successful loop calibration uses only 10005132..10005163."
    }
  },
  "not_done": [
    "The share of the hit-rate gap caused specifically by the recomputed CFMM k was not isolated with an engine counterfactual; replica2.py also states that its RNG stream differs from Rust.",
    "Tolerance hit estimates saturate at the try ceiling; the gas method cannot resolve the last ~0.07% from per-try branch overhead."
  ]
}
