{
 "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved: the replica, Gaussian filter, fee rule, qm tables and exact-arithmetic arb/retail tell that everything here runs on and edits are his. fastlean (compiled LEANBASE) from artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0; LEANBASE reference from artifact efb8e653f8fd061cecf3e92b186470c9c96c5188523364b60ed101e9672869aa; QLX5 source from artifact 1ef80bfb6d6791b877b1f4048a5e63cf2ae54153e6e8763ae3f8ab13132dfb15; all built on Taylor's work.",
 "mech": "drift: a per-step drift of the mean of ln p in the Gaussian filter's prediction step (LEAN keeps the mean and grows only the variance)",
 "already_present": {
  "value": false,
  "where": "Not in the policy. real.py RealPolicy.on_trade (the only place the belief is predicted forward): per elapsed step it does `v += SIG2` and, for silent steps, truncates to the no-arb interval; the mean m is never shifted. tellpol.py only sets the arb flag / cuts RHO by the grid chance, stalerival.py only adds the wad rounding and the staleness rival pull, leanbase.py only replaces the tell's label; none touches the prediction. The QLX5 contract is the same: its update() has `for(uint256 i=0;i<n;i++){v+=893025000000;(,m,v)=trunc(m,v,lo,hi);}` then `v+=893025000000;` (source lines 170-172, sha256 e183e5bc3fb794b7067703b10a7da9920267aa5f4caa968e16ca101b02338f40).",
  "check_of_the_price_process": "The drift is real in both simulators. Replica (replica2.py): `drift = -0.5 * sigma * sigma`, `p *= math.exp(drift + sigma * pr.gauss(0.0, 1.0))`. Engine (benedictbrady/amm-challenge@6b6921f8d463314aa7c96234e1be25a25245f704, price_process.rs): `drift_term: (mu - 0.5 * sigma * sigma) * dt`, with gbm_mu=0.0 and gbm_dt=1.0 in amm_competition/competition/config.py. So ln p drifts by -sigma^2/2 per step and the config adds no other drift. At the filter's fixed sigma 0.000945 that is -4.465e-7 per step = -0.0045 bps, against a per-step sd of 9.45 bps (ratio 4.7e-4); over the run's sigma range 0.000882..0.001008 it is -3.89e-7..-5.08e-7. The filter's mean is re-pinned at every trade read as the arb and the prediction covers at most 13 steps, so the omitted drift is at most 0.058 bps of bias in m.",
  "nearest_variant_tested": "not needed: the mechanism itself was absent and was tested as stated"
 },
 "definition": {
  "formula": "At a step's first callback (dt = t - t_last >= 1), before Taylor's update: repeat min(dt-1, 12) times { m += d_s; v += SIG2; (m, v) = trunc(m, v, lo, hi) }; then m += d; v += SIG2. d = c * D0, D0 = -SIG2/2 = -4.465125e-07 (ln units per step; SIG2 = 0.000945^2, Taylor's constant); d_s = d when dmode = 0, 0 when dmode = 1. Everything after (arb likelihood, truncation, soft update, rival clip, table lookup) is unchanged and sees the shifted m. c = 1, dmode = 0 is the exact GBM drift at the filter's sigma; d = 0 is LEAN.",
  "parameters": {
   "c": "multiple of the exact drift -SIG2/2 (c=1 exact; other values test whether any constant log-drift helps)",
   "dmode": "0 = every step the variance is grown for (silent steps capped at 12, and this step); 1 = this step only"
  },
  "state_kept": "none new: one compile-time constant; m and v are the filter state LEAN already keeps",
  "inputs_used": "timestamp only (the dt that LEAN already computes); nothing beyond what afterSwap is handed",
  "implementation": "edit of the compiled code (fastlean.on_trade, two added lines; F grows by drift and dmode; load(amm_dir, ..., drift=0.0, dmode=0)); the hook is not used",
  "parity": {
   "drift_0_vs_unpatched_fastlean": "128 of 128 seeds bit-identical (64000..64063, 10000..10063), mean edge 527.8724874783702",
   "vs_cpython_reference_with_the_same_two_lines_added_to_real.py": [
    {
     "c": 0,
     "dmode": 0,
     "a0": 0.35,
     "ainf": 0.35,
     "tau": 2.0,
     "n": 4,
     "max_abs_diff": 0.0,
     "bit_identical": 4
    },
    {
     "c": 1,
     "dmode": 0,
     "a0": 0.35,
     "ainf": 0.35,
     "tau": 2.0,
     "n": 4,
     "max_abs_diff": 0.0,
     "bit_identical": 4
    },
    {
     "c": 64,
     "dmode": 1,
     "a0": 0.35,
     "ainf": 0.35,
     "tau": 2.0,
     "n": 4,
     "max_abs_diff": 0.0,
     "bit_identical": 4
    },
    {
     "c": -16,
     "dmode": 0,
     "a0": 0.0,
     "ainf": 0.7,
     "tau": 1.0,
     "n": 4,
     "max_abs_diff": 0.0,
     "bit_identical": 4
    }
   ],
   "cpython_seeds": "64000..64003, run.py leanbase:Policy soft=1 qm=qm_k1e-5.json; c=0 row is plain LEANBASE"
  }
 },
 "settings_tried": [
  {
   "parameters": {
    "c": 1,
    "dmode": 0,
    "drift_ln_per_step": -4.465125e-07
   },
   "n": 1024,
   "mean_diff": -0.00129,
   "se": 0.002729,
   "dropped_early": false,
   "seeds_positive": 509
  },
  {
   "parameters": {
    "c": 1,
    "dmode": 1,
    "drift_ln_per_step": -4.465125e-07
   },
   "n": 1024,
   "mean_diff": 0.00238,
   "se": 0.002831,
   "dropped_early": false,
   "seeds_positive": 533
  },
  {
   "parameters": {
    "c": -1,
    "dmode": 0,
    "drift_ln_per_step": 4.465125e-07
   },
   "n": 1024,
   "mean_diff": 0.001922,
   "se": 0.002545,
   "dropped_early": false,
   "seeds_positive": 535
  },
  {
   "parameters": {
    "c": 2,
    "dmode": 0,
    "drift_ln_per_step": -8.93025e-07
   },
   "n": 1024,
   "mean_diff": 0.001299,
   "se": 0.002702,
   "dropped_early": false,
   "seeds_positive": 520
  },
  {
   "parameters": {
    "c": 4,
    "dmode": 0,
    "drift_ln_per_step": -1.78605e-06
   },
   "n": 1024,
   "mean_diff": -0.001881,
   "se": 0.002857,
   "dropped_early": false,
   "seeds_positive": 503
  },
  {
   "parameters": {
    "c": 8,
    "dmode": 0,
    "drift_ln_per_step": -3.5721e-06
   },
   "n": 1024,
   "mean_diff": -0.001214,
   "se": 0.00293,
   "dropped_early": false,
   "seeds_positive": 510
  },
  {
   "parameters": {
    "c": 16,
    "dmode": 0,
    "drift_ln_per_step": -7.1442e-06
   },
   "n": 1024,
   "mean_diff": -0.003844,
   "se": 0.003264,
   "dropped_early": false,
   "seeds_positive": 516
  },
  {
   "parameters": {
    "c": 32,
    "dmode": 0,
    "drift_ln_per_step": -1.42884e-05
   },
   "n": 1024,
   "mean_diff": -0.004325,
   "se": 0.003718,
   "dropped_early": false,
   "seeds_positive": 521
  },
  {
   "parameters": {
    "c": 64,
    "dmode": 0,
    "drift_ln_per_step": -2.85768e-05
   },
   "n": 1024,
   "mean_diff": -0.009597,
   "se": 0.004729,
   "dropped_early": false,
   "seeds_positive": 497
  },
  {
   "parameters": {
    "c": -4,
    "dmode": 0,
    "drift_ln_per_step": 1.78605e-06
   },
   "n": 1024,
   "mean_diff": 0.002116,
   "se": 0.002578,
   "dropped_early": false,
   "seeds_positive": 513
  },
  {
   "parameters": {
    "c": -16,
    "dmode": 0,
    "drift_ln_per_step": 7.1442e-06
   },
   "n": 1024,
   "mean_diff": 0.004422,
   "se": 0.003334,
   "dropped_early": false,
   "seeds_positive": 519
  },
  {
   "parameters": {
    "c": -64,
    "dmode": 0,
    "drift_ln_per_step": 2.85768e-05
   },
   "n": 1024,
   "mean_diff": 0.001894,
   "se": 0.004442,
   "dropped_early": false,
   "seeds_positive": 524
  }
 ],
 "selection": {
  "seeds": "64000..65023 in 8 rounds of 128, every setting paired with LEAN (a0=0.35 ainf=0.35 tau=2) on the same seeds",
  "drop_rule": "mean_diff + 3*se < 0 after any round; se = sd(paired differences, n-1)/sqrt(n)",
  "outcome": "no setting was dropped and none is told apart from zero: all 12 means lie in -0.0096..+0.0044 with se 0.0025..0.0047; the largest |z| is 2.0 (c=64, negative)",
  "lean_mean_edge_64000_65023": 539.018328
 },
 "chosen": {
  "parameters": {
   "c": -16,
   "dmode": 0,
   "drift_ln_per_step": 7.1442e-06
  },
  "rule": "highest mean_diff among settings not dropped after 1,024 seeds (rule fixed in the driver before the run)",
  "caveat": "a noise pick: +0.0044 se 0.0033 on the choosing seeds, and its sign is opposite to the true drift (it pushes m up by 0.071 bps per step). The exact drift (c=1, dmode=0) scored -0.0013 se 0.0027."
 },
 "report": {
  "vs_lean": {
   "n": 2048,
   "mean_diff": 0.003879,
   "se": 0.002265,
   "seeds_positive": 1014,
   "seeds_negative": 1034,
   "base_mean_edge": 536.603391,
   "with_drift_mean_edge": 536.60727
  },
  "on_age": {
   "n": 2048,
   "mean_diff": -0.000171,
   "se": 0.002565,
   "seeds_positive": 1022,
   "seeds_negative": 1026,
   "base_mean_edge": 536.6231,
   "with_drift_mean_edge": 536.622929
  },
  "seeds": "10000..12047, run once; vs_lean = LEAN+drift minus LEAN (a0=0.35 ainf=0.35 tau=2); on_age = AGE+drift minus AGE (a0=0 ainf=0.7 tau=1)",
  "context": "AGE minus LEAN on the same 2,048 replica seeds, from the two baseline arms of this run: +0.0197 se 0.0041"
 },
 "promote": false,
 "verdict": "No gain. Drift in the prediction step is worth 0.00 +- 0.003 on the replica at any of the 12 settings; the report gives +0.0039 se 0.0023 on LEAN and -0.0002 se 0.0026 on AGE, both far below +0.03. Not promoted.",
 "contract_cost": {
  "storage_words": 0,
  "characters": {
   "exact_drift_c1": 32,
   "chosen_c_minus16": 34,
   "c1_this_step_only": 16,
   "of": "QLX5 source 47,230 -> 47,262 (c=1) or 47,264 (c=-16) of 50,000; the statement is `m-=446512500000;` (c=1) or `m+=7144200000000;` (c=-16) inside the silent-step loop and once after it"
  },
  "runtime_bytes": {
   "base": 22440,
   "exact_drift_c1": 22462,
   "chosen_c_minus16": 22464,
   "c1_this_step_only": 22454,
   "how": "measured: QLX5 compiled here with solc 0.8.24+commit.e11b9ed9 (binary sha256 fb03a29a517452b9f12bcf459ef37d0a543765bb3bbc911e70a87d6a37c30d5f), optimizer 200 runs, viaIR, paris, the settings in the engine repo's amm_competition/evm/compiler.py; the unedited source gives 22,440, the figure in the brief. +22 bytes (c=1), +24 (c=-16), of 24,576"
  },
  "gas": {
   "estimate": "one constant push and one add per elapsed step, at most 13 per callback: of the order of 100-200 gas by opcode count (not measured in isolation)",
   "measured_in_a_scratch_forge_harness": {
    "what": "gasleft() around three external afterSwap calls on synthetic trades (first trade at t=1; t=30 with 12 silent steps; t=31), same compiler settings; not the engine's peak measure",
    "base": [
     164642,
     190315,
     164750
    ],
    "exact_drift_c1": [
     164617,
     190058,
     164978
    ],
    "chosen_c_minus16": [
     164673,
     190277,
     164962
    ],
    "c1_this_step_only": [
     164614,
     190118,
     165051
    ],
    "reading": "changes of -257..+301 gas per callback with no relation to the number of added operations: the viaIR optimizer lays the function out differently and the shifted m takes slightly different numeric paths. Against a peak of about 208,000 of 245,000 this is immaterial, but the engine peak of an edited contract was not measured."
   }
  }
 },
 "patch_zb64": "eNq1Vltv2zYUfvevOGsfLMWUIilOnKTwkBZougBFgaEGCizwDFqiYra6RaSduL9+36F87dah2FAZsHguPN+58VBBEJA8zaWxhZLVbhE2695gMKD5P4tubigYxiMxogG/4oRubnr0koL/+dD7t68/vHn98S0bMznlRS3txfA+TqbXFFEpKKaVoIRMshB0Rvlc0JBySV5bL6tMZZQrZUhXlNdtqnxB52QaQRfU6FmBAASN6PlJ0CWtn8hrWrXS9dJQq4xqV4qeZGZ8h61hhJEvAYwnItttjymtrPNgXaUqYyeMLhTzhgQnrGpnlmHnTwwrgQKXOsMMvlGRD6oXvKS7DcoQKB8+Cbp9I7BxpisNG7JbkHtud7kYQfdTJAgJkHhJXeWCrFwKZGOzM5du0Rv8N4SrH0YQlLU651dZZ4rxHE2etqqkLNCZkubU8fxrsgtFuS4Qf98Qcp/p1Oq6ImNVQ2W9QuVYpUSTUZ1TUVFD8zXdImRqVEuqkI1BjVlfMFilni3Z2u1ayVZLlASmP969S8ibyHVRM1IHSTLLzJEm1VWx9kOiCZjqWaYWomKpuHecYquaQqeybxhLVpljqupBV8oFoGGjaetUGSPg6skYVhovMPqhlH8mpwkNyK3pK0ov7XH8uX7mUJxcGwrY6dMkdDnkZCLsS9f0sLpS7brL0pH/2PbQ1k+u2cljUdeKThUupbJpgAHkOBGbALCHpV1MnHOfe3p8KHFslxzkpqtnFEaMtj2dNEfTMCjeYY9uqs/aeqlMF2o8aZcKJyhTOTU1srd2feIZdJDRgu7Qgf51zzWcye+jKaBLaRdhUT94cQQc/xULYhaAckTChBM68ozJ2/vzqaOGHXXRUefHqheODKNuYJ1diSsMrOFwO7C2zwLhjKmQcxpDfc8v6kP3OvMn5MEgBTgLkQ9nF/rvOqc7HQmdvb0Sqi7qV7TqlvG0N9hKs9ZFMoI0aw3WYOjc9QH7xTVQhVG82JvkKsx44LWyelBeqSsvs0COUdbER6p35vmBOTb9i7N2DX8GjGJ6hzpwDVxux2P27KvgAcyO23ZZpR4TAjnCoND+HsdhfAvR+zfrRXOUwm9SzAa1mc2X6y78A8Xv5fkPeIqhtLLf8ZW74eLqiq+vUcS32LYZWmWXbUUY3W4Wek8+MOKITk4ovuwRfgF3NmSZJ8tylulW0GM57j+Wsy+xCs7Dz6au+oJ7f9zH36zU2ZYno3EUnp13A3WzxFQdJ2h61OmnGN4MaDCjzZAeR9vz9+LFi4mcF5i6GLa7aclXoWzTBcEFldoakwc3mE0XoVn4FPzqRpBdNgXm47KazSVEQPuiTAiDneUJ8s6+hS6eulGVV5uw4cJ9rtGhuwgRiL8t3O8/uumx5D1cw1F84WqYDMXlrob8TYAvgjG5yTPjDwJvssHgSzmf8zljvpfPcYAl8+SeJze6d+BUTSjbVq69+/3dydfmFMm060aNoeDuV78XdHfo4Z6uhyb3/U9Rf+pvewr0b7N5Yw5Y6N7dEiXcESii7xx2Hk43h+yngojjgbEZMk6xu8a321wz+VP/6OC8FoQcfRR7/9ix5H3/MGGbzwy/uw3cqfoLO3L6cg==",
 "patch_note": "unified diff with a/fastlean/fastlean.py, b/fastlean/fastlean.py headers against the fastlean.py of artifact a88ff982eba7e078bc6ccb1555b90a211c00c9fd76ec90a62ab13a4074f2c3d0 (30,721 bytes); apply with `patch -p1` from the directory holding fastlean/. Checked: applies cleanly and reproduces the file that was run.",
 "environment": "CPython 3.12.3, numpy 2.2.6, llvmlite 0.44.0, numba 0.61.2 (cp312 manylinux x86_64 wheels from PyPI, sha256 checked against PyPI metadata, unpacked; this machine has no pip), Linux x86_64. Research files by tell/fetch.sh at gtmcknight/amm-sim@66604b3426d8e97a73e2c39940b9b4dece51cc73 (34 files, 0 mismatched), as the replica artifact's run lines say.",
 "not_done": [
  "Replica only. No engine run, no gate (P, Q, T, F, G, E), no Solidity contract delivered, nothing submitted.",
  "Only the chosen setting (c=-16) was run on the report seeds 10000..12047, once, as the method says; the exact drift (c=1) was scored on the choosing seeds only.",
  "The drift uses the filter's fixed sigma. A per-run drift would need a per-run sigma, which is spent, and was not tested.",
  "The drift is applied to at most 13 steps, like the variance (silent steps beyond 12 are not predicted by LEAN either); no drift was added to the rival estimate.",
  "Tested on LEAN and on AGE in fastlean, not on QLX5: fastlean has no split test. The contract edits were compiled for size and timed in a scratch harness only; their fees were not compared with the patched replica.",
  "The engine afterSwap peak of an edited contract was not measured; the gas figures are an opcode estimate and three synthetic callbacks.",
  "The kit's setup_fast.sh, score.py and baseline banks were not used: the replica artifact's own run lines were followed and the paired statistics were computed directly from the per-seed edges.",
  "CPython cross-check of the edit covers 16 runs (4 parameter sets x 4 seeds), all bit-identical; that is a test, not a proof.",
  "real.py at the credited commit 4812a638 differs from the 66604b34 copy the replica ports (callback signature, diagnostics, docstring); its prediction step has the same two `v += SIG2` lines, checked by reading, not by running."
 ]
}