{
  "item": "b",
  "blocked": null,
  "seeds": {
    "kind": "tuning",
    "start": 755000,
    "end_inclusive": 755511,
    "n": 512
  },
  "arms": [
    {
      "name": "A0",
      "sha256": "df2817ba4ec233a456eb45909faa4a706efe0fabd1734a908fe52545f4d07577",
      "params": [
        2,
        0.16509179839500446,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.08260855527069544,
      "se": 0.02615383820069299,
      "worst": [
        {
          "seed": 755184,
          "d": -3.19241275933814
        },
        {
          "seed": 755421,
          "d": -1.6255413885160124
        },
        {
          "seed": 755338,
          "d": -1.4452036106595187
        },
        {
          "seed": 755259,
          "d": -1.3405771372343906
        },
        {
          "seed": 755415,
          "d": -1.1658411894392202
        }
      ],
      "retail_edge_delta": {
        "mean": 0.030697037738120603,
        "se": 0.026075292708078016
      },
      "arb_edge_delta": {
        "mean": 0.05191151753257543,
        "se": 0.00756578124721146
      },
      "gas": {
        "max_ok": 202431,
        "init_max_ok": 243099,
        "oog": 0
      }
    },
    {
      "name": "A1",
      "sha256": "4412d77f41389d6775b1a4034241e6fcf5a6b24553bfe91580d1050081fa9c86",
      "params": [
        2,
        0,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.0,
      "se": 0.0,
      "worst": [
        {
          "seed": 755000,
          "d": 0.0
        },
        {
          "seed": 755001,
          "d": 0.0
        },
        {
          "seed": 755002,
          "d": 0.0
        },
        {
          "seed": 755003,
          "d": 0.0
        },
        {
          "seed": 755004,
          "d": 0.0
        }
      ],
      "retail_edge_delta": {
        "mean": 0.0,
        "se": 0.0
      },
      "arb_edge_delta": {
        "mean": 0.0,
        "se": 0.0
      },
      "gas": {
        "max_ok": 194762,
        "init_max_ok": 220981,
        "oog": 0
      }
    },
    {
      "name": "A2",
      "sha256": "1dbc72dd655ec669af2ffccb7d7bdbfdcc570f50be884ca45a5e8cd9132210f1",
      "params": [
        0,
        0.16509179839500446,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": -0.15511866235911387,
      "se": 0.032808250388781296,
      "worst": [
        {
          "seed": 755184,
          "d": -4.215500345432474
        },
        {
          "seed": 755169,
          "d": -2.1306811242819776
        },
        {
          "seed": 755331,
          "d": -1.6618793690030316
        },
        {
          "seed": 755315,
          "d": -1.5388769914144405
        },
        {
          "seed": 755474,
          "d": -1.507051688226511
        }
      ],
      "retail_edge_delta": {
        "mean": 1.5027722547558953,
        "se": 0.03368684156975433
      },
      "arb_edge_delta": {
        "mean": -1.6578909171150082,
        "se": 0.010135033554353723
      },
      "gas": {
        "max_ok": 201886,
        "init_max_ok": 243081,
        "oog": 0
      }
    },
    {
      "name": "A3",
      "sha256": "a2e17c5f53f91fe381eefb996e010e7d148224a5600083284d7f099a8cd615f4",
      "params": [
        1,
        0.16509179839500446,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.14684892673332106,
      "se": 0.025318421898088035,
      "worst": [
        {
          "seed": 755184,
          "d": -3.141555439119088
        },
        {
          "seed": 755421,
          "d": -1.428209461533413
        },
        {
          "seed": 755338,
          "d": -1.2267397314544723
        },
        {
          "seed": 755083,
          "d": -1.1461833286266483
        },
        {
          "seed": 755169,
          "d": -1.034659874461795
        }
      ],
      "retail_edge_delta": {
        "mean": 0.5484581174639763,
        "se": 0.024942790155411922
      },
      "arb_edge_delta": {
        "mean": -0.40160919073065415,
        "se": 0.006969673154155109
      },
      "gas": {
        "max_ok": 202016,
        "init_max_ok": 243081,
        "oog": 0
      }
    },
    {
      "name": "A4",
      "sha256": "21896aeaca2c7fc040fd4be2a2e40acd6a097c1e9bb1a73bc2b08a6eec5e0b70",
      "params": [
        2,
        0.16509179839500446,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        1
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.1472382011404515,
      "se": 0.025308732147702562,
      "worst": [
        {
          "seed": 755184,
          "d": -3.139671422480319
        },
        {
          "seed": 755421,
          "d": -1.4259428116819208
        },
        {
          "seed": 755338,
          "d": -1.206254678137043
        },
        {
          "seed": 755083,
          "d": -1.1352243405549416
        },
        {
          "seed": 755169,
          "d": -1.055653990259998
        }
      ],
      "retail_edge_delta": {
        "mean": 0.5442945343742531,
        "se": 0.02496848809307302
      },
      "arb_edge_delta": {
        "mean": -0.39705633323380096,
        "se": 0.0069215550268203535
      },
      "gas": {
        "max_ok": 202431,
        "init_max_ok": 243099,
        "oog": 0
      }
    },
    {
      "name": "A5",
      "sha256": "5f0db9c99bec4d2a5f13ad413a75ae0bd4c1f13701132650f64a2e91b308d71c",
      "params": [
        2,
        0.16509179839500446,
        0.95,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.054242054420672536,
      "se": 0.025925451669871168,
      "worst": [
        {
          "seed": 755184,
          "d": -3.2077689363296713
        },
        {
          "seed": 755421,
          "d": -1.8225962885627496
        },
        {
          "seed": 755338,
          "d": -1.399296986130139
        },
        {
          "seed": 755398,
          "d": -1.1192135561500436
        },
        {
          "seed": 755259,
          "d": -1.109841064324769
        }
      ],
      "retail_edge_delta": {
        "mean": -0.23569710811551114,
        "se": 0.026266419771924163
      },
      "arb_edge_delta": {
        "mean": 0.2899391625361858,
        "se": 0.008842245983193385
      },
      "gas": {
        "max_ok": 202374,
        "init_max_ok": 243099,
        "oog": 0
      }
    },
    {
      "name": "A6",
      "sha256": "460f9c49347fef9dae4e51260054ba8fd039608081213282428e4b73b92919c6",
      "params": [
        2,
        0.33,
        0.9909893448132306,
        0.6684959838546022,
        1.5946627692375024,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.06777491217355314,
      "se": 0.029630936249091085,
      "worst": [
        {
          "seed": 755184,
          "d": -3.2806852279154555
        },
        {
          "seed": 755195,
          "d": -2.2365681653297997
        },
        {
          "seed": 755509,
          "d": -1.5955892105703242
        },
        {
          "seed": 755338,
          "d": -1.5765387816853718
        },
        {
          "seed": 755236,
          "d": -1.5593925185095259
        }
      ],
      "retail_edge_delta": {
        "mean": 0.1898717437844697,
        "se": 0.030300210916653945
      },
      "arb_edge_delta": {
        "mean": -0.12209683161091694,
        "se": 0.01149890522190627
      },
      "gas": {
        "max_ok": 202375,
        "init_max_ok": 243099,
        "oog": 0
      }
    },
    {
      "name": "A7",
      "sha256": "f74dc27ad46e2d5cd7abba4d044e9a72678da022ea5e856c74dc5f7723b937ea",
      "params": [
        2,
        0.16509179839500446,
        0.9909893448132306,
        0.6684959838546022,
        1.0,
        80.0
      ],
      "n": 512,
      "mean_diff_vs_v10": 0.12480796652406678,
      "se": 0.02580673604867117,
      "worst": [
        {
          "seed": 755184,
          "d": -3.3232531434746306
        },
        {
          "seed": 755421,
          "d": -1.5439063357208056
        },
        {
          "seed": 755338,
          "d": -1.3710833189909408
        },
        {
          "seed": 755169,
          "d": -1.1146979679722335
        },
        {
          "seed": 755083,
          "d": -1.0413367866543695
        }
      ],
      "retail_edge_delta": {
        "mean": 0.672579277319101,
        "se": 0.025167033768783906
      },
      "arb_edge_delta": {
        "mean": -0.5477713107950344,
        "se": 0.007012894580095652
      },
      "gas": {
        "max_ok": 202350,
        "init_max_ok": 243090,
        "oog": 0
      }
    },
    {
      "name": "V10",
      "sha256": "cd9bdb45ab0537ad25c4fd90ca8618898cef6386de3df65f192eaef65fbca245",
      "params": null,
      "n": 512,
      "mean_diff_vs_v10": 0.0,
      "se": 0.0,
      "worst": [
        {
          "seed": 755000,
          "d": 0.0
        },
        {
          "seed": 755001,
          "d": 0.0
        },
        {
          "seed": 755002,
          "d": 0.0
        },
        {
          "seed": 755003,
          "d": 0.0
        },
        {
          "seed": 755004,
          "d": 0.0
        }
      ],
      "retail_edge_delta": {
        "mean": 0.0,
        "se": 0.0
      },
      "arb_edge_delta": {
        "mean": 0.0,
        "se": 0.0
      },
      "gas": {
        "max_ok": 194759,
        "init_max_ok": 220981,
        "oog": 0
      }
    }
  ],
  "pairwise": {
    "A0_minus_A4": {
      "mean": -0.06462964586975606,
      "se": 0.013185736663509487
    },
    "A0_minus_A2": {
      "mean": 0.2377272176298093,
      "se": 0.02957460994886188
    }
  },
  "interpretation": "Learned size carries the gain: A3-A2=+0.30197 (SE 0.02419); count-only A2 loses 0.15512 vs V10. RS1 gains 0.08261 (SE 0.02615). Strong quote correction hurts net edge: A0-A4=-0.06463 (SE 0.01319); correction-off A3 likewise beats A0. Size scale 1.0 also beats RS1 by 0.04220 (SE 0.01564). Retention 0.95 weakens the gain; mix 0.33 is not clearly different. A1 equals V10 on every seed. These findings apply to this tuning block only.",
  "notes": {
    "parameter_order": [
      "structure",
      "mix",
      "retention",
      "rate_scale",
      "size_scale",
      "quote_correction_slope"
    ],
    "method": "Each arm once on all 512 seeds, independently vs VanillaStrategy; supplied V10 harness, 20-seed chunks, run_batch workers=8. Paired SE uses sample SD/sqrt(512). No search; no seeds >=5000000.",
    "reconstruction": "Supplied V10 harness reconstructs arb edge as negative optimal arb profit from prior-step final spot/quotes and current fair price, fixed initial k; retail edge = total minus arb. Initial fee 0.0004. These are numerical reconstructions.",
    "zero_mix": "A1 exactly equals V10 in edge, reconstructed arb and retail on every seed.",
    "validation": "amm-match validate passed for V10 and all A0..A7; StarterStrategy setup validation passed. Input hashes and A0 regenerated identity verified. All simulation callback error counters checked zero.",
    "gas_scope": "max_ok and init_max_ok are submission maxima; oog counts all roles and callbacks over all chunks.",
    "calibration": {
      "name": "CH",
      "n": 1000,
      "seeds_inclusive": [
        0,
        999
      ],
      "mean_edge": 525.5258821780834,
      "expected": 525.5258821780834
    },
    "source_urls": {
      "RS1": "https://api.imdnotdead.fun/artifacts/7322427b95805d2d17d6c2a78be725cf814b2ef29eccd042492708915f12ca0f",
      "V10": "https://api.imdnotdead.fun/artifacts/33f54e81f3372088e9eced52c0174f310ac348af98ef5727b73785c088679194"
    },
    "repository_commit": "6b6921f8d463314aa7c96234e1be25a25245f704",
    "wheel_sha256": "aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a",
    "measurement_source": "Local execution, not prior artifact measurements. Worst lists five lowest per-seed total edge differences. V10 params null denotes unmodified reference. No board claim.",
    "reproduction": {
      "v10_code": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {AMMStrategyBase} from \"./AMMStrategyBase.sol\";\nimport {TradeInfo} from \"./IAMMStrategy.sol\";\n\ncontract Strategy is AMMStrategyBase {\n    uint256 constant ELAPSED_CAP = 8;\n    uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n    uint256 constant DIR_DECAY = 750000000000000000;\n    uint256 constant ACT_DECAY = 530000000000000000;\n    uint256 constant SIZE_DECAY = 530000000000000000;\n    uint256 constant TOX_DECAY = 910000000000000000;\n    uint256 constant SIGMA_DECAY = 690000000000000000;\n    uint256 constant LAMBDA_DECAY = 990000000000000000;\n    uint256 constant SIZE_BLEND_DECAY = 828000000000000000;\n    uint256 constant TOX_BLEND_DECAY = 51000000000000000;\n    uint256 constant ACT_BLEND_DECAY = 985000000000000000;\n    uint256 constant PHAT_ALPHA = 270000000000000000;\n    uint256 constant PHAT_ALPHA_RETAIL = 60000000000000000;\n    uint256 constant PHAT_ALPHA_SAME = 120000000000000000;\n    uint256 constant REVERT_U = 0;\n    uint256 constant DIR_IMPACT_MULT = 4;\n    uint256 constant GATE_SIGMA_MULT = 7200000000000000000;\n    uint256 constant MIN_GATE = 30000000000000000;\n    uint256 constant TRADE_TOX_BOOST = 3500 * BPS;\n    uint256 constant STALE_ATTRACT_FRAC = 1050000000000000000;\n    uint256 constant RET_CAP = WAD / 35;\n    uint256 constant TOX_CAP = WAD / 5;\n    uint256 constant TRADE_RATIO_CAP = WAD / 5;\n    uint256 constant LAMBDA_CAP = 1820000000000000000;\n    uint256 constant STEP_COUNT_CAP = 64;\n    uint256 constant BASE_FEE = 4 * BPS;\n    uint256 constant SIGMA_COEF = 200000000000000000;\n    uint256 constant LAMBDA_COEF = 12 * BPS;\n    uint256 constant FLOW_SIZE_COEF = 4842 * BPS;\n    uint256 constant TOX_COEF = 300 * BPS;\n    uint256 constant TOX_QUAD_COEF = 15000 * BPS;\n    uint256 constant ACT_COEF = 91843 * BPS;\n    uint256 constant DIR_COEF = 20 * BPS;\n    uint256 constant DIR_TOX_COEF = 100 * BPS;\n    uint256 constant STALE_DIR_COEF = 6850 * BPS;\n    uint256 constant SIGMA_TOX_COEF = 500 * BPS;\n    uint256 constant TAIL_KNEE = 600 * BPS;\n    uint256 constant TAIL_SLOPE_PROTECT = 930000000000000000;\n    uint256 constant TAIL_SLOPE_ATTRACT = 850000000000000000;\n\n    function afterInitialize(uint256 initialX, uint256 initialY) external override returns (uint256, uint256) {\n        slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[3] = WAD; \n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[13] = 902500000000; slots[14] = slots[5]; \n        return (BASE_FEE, BASE_FEE);\n    }\n\n    function afterSwap(TradeInfo calldata trade) external override returns (uint256, uint256) {\n        uint256 prevBidFee = slots[0]; uint256 prevAskFee = slots[1]; uint256 lastTs = uint64(slots[2]);\n        uint256 dirState = slots[3]; uint256 actEma = slots[4]; uint256 pHat = slots[5];\n        uint256 sigmaHat = slots[6]; uint256 lambdaHat = slots[7]; uint256 sizeHat = slots[8];\n        uint256 toxEma = slots[9]; uint256 stepTradeCount = slots[10];\n\n        uint256 sigmaForFast = sigmaHat;\n        uint256 fastHat = slots[14];\n        uint256 uncertainty = slots[13];\n        uint256 silent = trade.timestamp > lastTs ? trade.timestamp - lastTs : 0;\n        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            uint256 elapsed = elapsedRaw > ELAPSED_CAP ? ELAPSED_CAP : elapsedRaw;\n            dirState = _decayCentered(dirState, DIR_DECAY, elapsed);\n            actEma = wmul(actEma, _powWad(ACT_DECAY, elapsed));\n            sizeHat = wmul(sizeHat, _powWad(SIZE_DECAY, elapsed));\n            toxEma = wmul(toxEma, _powWad(TOX_DECAY, elapsed));\n            if (stepTradeCount > 0 && elapsedRaw > 0) {\n                uint256 lambdaInst = (stepTradeCount * WAD) / elapsedRaw;\n                if (lambdaInst > LAMBDA_CAP) lambdaInst = LAMBDA_CAP;\n                lambdaHat = wmul(lambdaHat, LAMBDA_DECAY) + wmul(lambdaInst, WAD - LAMBDA_DECAY);\n            }\n            // Process variance is propagated inside the censored update.\n            if (uncertainty > 100000000000000) uncertainty = 100000000000000;\n            stepTradeCount = 0;\n        }\n\n        bool firstInStep = stepTradeCount == 0;\n        uint256 spot = trade.reserveX > 0 ? wdiv(trade.reserveY, trade.reserveX) : pHat;\n        if (pHat == 0) pHat = spot;\n\n        uint256 feeUsed = trade.isBuy ? prevBidFee : prevAskFee;\n        uint256 gamma = feeUsed < WAD ? WAD - feeUsed : 0;\n        uint256 pImplied;\n        if (gamma == 0) { pImplied = spot; }\n        else { pImplied = trade.isBuy ? wmul(spot, gamma) : wdiv(spot, gamma); }\n\n        // S: infer a no-trade interval center from the last post-trade spot.\n        uint256 silenceScale = WAD;\n        if (firstInStep && silent > 1) {\n            uint256 g = silent - 1;\n            if (g > 1) g = 1;\n            uint256 w = WAD - _powWad(800000000000000000, g);\n            uint256 s = slots[2] >> 64;\n            if (s == 0) s = pHat;\n            uint256 c = (wmul(s, WAD - prevBidFee) + wdiv(s, WAD - prevAskFee)) / 2;\n            if (c >= pHat) pHat += wmul(w, c - pHat);\n            else pHat -= wmul(w, pHat - c);\n            silenceScale = WAD - wmul(300000000000000000, w);\n        }\n\n        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 prePhat = pHat;\n            bool secondPrint = !firstInStep && stepTradeCount == 1;\n            bool sameDir = false; bool oppDir = false;\n            if (secondPrint) {\n                bool up2 = pImplied >= pHat;\n                uint256 d1 = slots[12];\n                if (d1 != 0) { sameDir = (d1 == 1) == up2; oppDir = !sameDir; }\n                if (sameDir) alpha = PHAT_ALPHA_SAME;\n            }\n            if (firstInStep) { slots[12] = pImplied >= pHat ? 1 : 2; }\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            alpha = wmul(alpha, silenceScale);\n            adaptiveGate = wmul(adaptiveGate, silenceScale);\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\n            if (oppDir && REVERT_U > 0) {\n                uint256 pre = slots[11];\n                if (pre > pHat) pHat = pHat + wmul(pre - pHat, REVERT_U);\n                else pHat = pHat - wmul(pHat - pre, REVERT_U);\n            }\n            if (firstInStep) {\n                if (ret > RET_CAP) ret = RET_CAP;\n                sigmaHat = wmul(sigmaHat, SIGMA_DECAY) + wmul(ret, WAD - SIGMA_DECAY);\n            }\n        }\n\n        // Interior retail routing equalizes fee-adjusted marginal prices.\n        // Subsequent trades in a step cannot be the initial arbitrage trade.\n        if (!firstInStep && feeUsed > 30 * BPS && gamma > 0) {\n            uint256 normalSpot = trade.isBuy\n                ? wdiv(wmul(spot, gamma), WAD - 30 * BPS)\n                : wdiv(wmul(spot, WAD - 30 * BPS), gamma);\n            pHat = wmul(pHat, 90 * WAD / 100) + wmul(normalSpot, 10 * WAD / 100);\n        }\n\n        // Censored assumed-density posterior. No external or future inputs.\n        (fastHat, uncertainty) = _posterior(PosteriorInput(\n            fastHat, uncertainty, pImplied, spot, slots[2] >> 64,\n            prevBidFee, prevAskFee, firstInStep, silent, trade.isBuy,\n            trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0\n        ));\n        slots[13] = uncertainty;\n        slots[14] = fastHat;\n        uint256 tradeRatio = trade.reserveY > 0 ? wdiv(trade.amountY, trade.reserveY) : 0;\n        if (tradeRatio > TRADE_RATIO_CAP) tradeRatio = TRADE_RATIO_CAP;\n\n        if (tradeRatio > SIGNAL_THRESHOLD) {\n            uint256 push = tradeRatio * DIR_IMPACT_MULT;\n            if (push > WAD / 4) push = WAD / 4;\n            if (trade.isBuy) {\n                dirState = dirState + push;\n                if (dirState > 2 * WAD) dirState = 2 * WAD;\n            } else {\n                dirState = dirState > push ? dirState - push : 0;\n            }\n            actEma = wmul(actEma, ACT_BLEND_DECAY) + wmul(tradeRatio, WAD - ACT_BLEND_DECAY);\n            sizeHat = wmul(sizeHat, SIZE_BLEND_DECAY) + wmul(tradeRatio, WAD - SIZE_BLEND_DECAY);\n            if (sizeHat > WAD) sizeHat = WAD;\n        }\n\n        uint256 tox = pHat > 0 ? wdiv(absDiff(spot, pHat), pHat) : 0;\n        if (tox > TOX_CAP) tox = TOX_CAP;\n        toxEma = wmul(toxEma, TOX_BLEND_DECAY) + wmul(tox, WAD - TOX_BLEND_DECAY);\n        uint256 toxSignal = toxEma;\n\n        stepTradeCount = stepTradeCount + 1;\n        if (stepTradeCount > STEP_COUNT_CAP) stepTradeCount = STEP_COUNT_CAP;\n\n        uint256 flowSize = wmul(lambdaHat, sizeHat);\n        uint256 fBase = BASE_FEE + wmul(SIGMA_COEF, sigmaHat) + wmul(LAMBDA_COEF, lambdaHat) + wmul(FLOW_SIZE_COEF, flowSize);\n        uint256 fMid = fBase + wmul(TOX_COEF, toxSignal) + wmul(TOX_QUAD_COEF, wmul(toxSignal, toxSignal)) + wmul(ACT_COEF, actEma);\n        fMid = fMid + wmul(SIGMA_TOX_COEF, wmul(sigmaHat, toxSignal));\n\n        uint256 dirDev; bool sellPressure;\n        if (dirState >= WAD) { dirDev = dirState - WAD; sellPressure = true; }\n        else { dirDev = WAD - dirState; sellPressure = false; }\n\n        uint256 skew = wmul(DIR_COEF, dirDev) + wmul(DIR_TOX_COEF, wmul(dirDev, toxSignal));\n        uint256 bidFee; uint256 askFee;\n        if (sellPressure) {\n            bidFee = fMid + skew;\n            askFee = fMid > skew ? fMid - skew : 0;\n        } else {\n            askFee = fMid + skew;\n            bidFee = fMid > skew ? fMid - skew : 0;\n        }\n\n        {\n            uint256 staleHat = wmul(pHat, 700000000000000000) + wmul(fastHat, 300000000000000000);\n            uint256 staleTox = wdiv(absDiff(spot, staleHat), staleHat);\n            if (staleTox > TOX_CAP) staleTox = TOX_CAP;\n            uint256 staleShift = wmul(STALE_DIR_COEF, staleTox);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= staleHat) {\n                bidFee = bidFee + staleShift;\n                askFee = askFee > attractShift ? askFee - attractShift : 0;\n            } else {\n                askFee = askFee + staleShift;\n                bidFee = bidFee > attractShift ? bidFee - attractShift : 0;\n            }\n        }\n\n        {\n            bool tradeAligned = (trade.isBuy && spot >= pHat) || (!trade.isBuy && spot < pHat);\n            if (tradeAligned) {\n                uint256 tradeBoost = wmul(TRADE_TOX_BOOST, tradeRatio);\n                if (!firstInStep && tradeBoost > 16 * BPS) tradeBoost = 16 * BPS;\n                if (trade.isBuy) { bidFee = bidFee + tradeBoost; }\n                else { askFee = askFee + tradeBoost; }\n            }\n        }\n\n        if (sellPressure) {\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_PROTECT));\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_ATTRACT));\n        } else {\n            askFee = clampFee(_compressTailWithSlope(askFee, TAIL_SLOPE_PROTECT));\n            bidFee = clampFee(_compressTailWithSlope(bidFee, TAIL_SLOPE_ATTRACT));\n        }\n\n        if (firstInStep) {\n            if (askFee > bidFee && bidFee > 30 * BPS) bidFee = 30 * BPS;\n            else if (bidFee > askFee && askFee > 30 * BPS) askFee = 30 * BPS;\n        }\n\n        if (bidFee > askFee && askFee > 36 * BPS) askFee = 36 * BPS;\n        else if (askFee > bidFee && bidFee > 36 * BPS) bidFee = 36 * BPS;\n\n        slots[0] = bidFee; slots[1] = askFee; slots[2] = (spot << 64) | trade.timestamp;\n        slots[3] = dirState; slots[4] = actEma; slots[5] = pHat;\n        slots[6] = sigmaHat; slots[7] = lambdaHat; slots[8] = sizeHat;\n        slots[9] = toxEma; slots[10] = stepTradeCount;\n\n        return (bidFee, askFee);\n    }\n\n\n    struct PosteriorInput {\n        uint256 mu; uint256 v; uint256 obs; uint256 spot; uint256 preSpot;\n        uint256 bid; uint256 ask; bool first; uint256 silent; bool buy; uint256 size;\n    }\n    function _posterior(PosteriorInput memory x) internal pure returns (uint256, uint256) {\n        if (x.mu == 0) x.mu = x.spot;\n        if (x.v < 10000000000) x.v = 10000000000;\n        uint256 lo = wmul(x.preSpot, WAD-x.bid);\n        uint256 hi = wdiv(x.preSpot, WAD-x.ask);\n        if (x.first) {\n            if (x.silent>1 && x.preSpot>0) {\n                uint256 elapsed=x.silent>8?8:x.silent;\n                x.v += 902500000000*(elapsed-1);\n                (x.mu,x.v)=_band(x.mu,x.v,lo,hi);\n            }\n            x.v+=902500000000;\n        }\n        uint256 mRetail = x.mu;\n        uint256 vRetail = x.v;\n        // A missing own-pool trade is a censored price observation.\n        if (x.first && x.preSpot > 0) {\n            (mRetail, vRetail) = _band(x.mu, x.v, lo, hi);\n        }\n        if (!x.first) {\n            // A later print is retail. Only an interior route is an observation\n            // of the other pool, with explicit observation uncertainty.\n            uint256 fee = x.buy ? x.bid : x.ask;\n            if (fee > 30 * BPS) {\n                uint256 normal = x.buy ? wdiv(wmul(x.spot, WAD-fee), WAD-30*BPS)\n                    : wdiv(wmul(x.spot, WAD-30*BPS), WAD-fee);\n                uint256 residual = wdiv(absDiff(normal, x.mu),x.mu);\n                uint256 noise = 9000000000000 + wmul(residual,residual);\n                uint256 k = wdiv(x.v,x.v+noise);\n                return (_blend(x.mu,normal,k),wmul(x.v,WAD-k));\n            }\n            return (x.mu,x.v);\n        }\n        uint256 e = wdiv(absDiff(x.obs,x.mu),x.mu);\n        uint256 totalV = x.v + 22500000000;\n        uint256 z = wdiv(wmul(e,e),totalV);\n        uint256 density = _powWad(wdiv(WAD,WAD+z/8),4);\n        uint256 odds = wmul(density,wdiv(4000000000000000,_isqrt(totalV*WAD)));\n        if (x.size > 3000000000000000) odds = wmul(odds,4*WAD/10);\n        if (x.silent > 1) odds = wmul(odds,8*WAD/10);\n        uint256 sd = _isqrt(x.v*WAD);\n        uint256 width = wdiv(hi-lo,x.mu);\n        uint256 distance = x.mu<lo?lo-x.mu:(x.mu>hi?x.mu-hi:0);\n        uint256 zBand = wdiv(wdiv(distance,x.mu),sd);\n        uint256 mass = wmul(wdiv(width,width+2*sd),wdiv(WAD,WAD+wmul(zBand,zBand)));\n        if (mass < WAD/100) mass = WAD/100;\n        odds = wdiv(odds,mass);\n        uint256 prob = wdiv(odds,WAD+odds);\n        uint256 kArb = wdiv(x.v,totalV);\n        uint256 mArb = _blend(x.mu,x.obs,kArb);\n        uint256 mean = _blend(mRetail,mArb,prob);\n        uint256 between = wdiv(absDiff(mArb,mRetail),x.mu);\n        uint256 variance = wmul(prob,wmul(x.v,WAD-kArb)) + wmul(WAD-prob,vRetail)\n            + wmul(wmul(prob,WAD-prob),wmul(between,between));\n        if (variance > 100000000000000) variance = 100000000000000;\n        return (mean,variance);\n    }\n    function _blend(uint256 a,uint256 b,uint256 w) internal pure returns(uint256) {\n        return b>=a ? a+wmul(b-a,w) : a-wmul(a-b,w);\n    }\n    function _band(uint256 mu,uint256 v,uint256 lo,uint256 hi) internal pure returns(uint256,uint256) {\n        // Soft interval likelihood avoids discontinuities at quadrature nodes.\n        uint256 sd=wmul(mu,_isqrt(v*WAD));\n        uint256[3] memory acc;\n        for(uint256 j=0;j<7;j++) {\n            uint256 p=j<3 ? (mu>(3-j)*sd?mu-(3-j)*sd:1) : mu+(j-3)*sd;\n            uint256 w=j==3?72:(j==2||j==4?45:(j==1||j==5?10:1));\n            uint256 distance=p<lo?lo-p:(p>hi?p-hi:0);\n            uint256 z=sd>0?wdiv(distance,sd):0;\n            uint256 likelihood=wdiv(WAD,WAD+4*wmul(z,z));\n            w=wmul(w*WAD,likelihood);\n            acc[0]+=w;acc[1]+=wmul(w,p);\n            uint256 d=wdiv(absDiff(p,mu),mu);\n            acc[2]+=wmul(w,wmul(d,d));\n        }\n        uint256 m=wdiv(acc[1],acc[0]);\n        uint256 d=wdiv(absDiff(m,mu),mu);\n        uint256 second=wdiv(acc[2],acc[0]);\n        return(m,second>wmul(d,d)?second-wmul(d,d):10000000000);\n    }\n\n    function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) {\n        if (fee <= TAIL_KNEE) return fee;\n        return TAIL_KNEE + wmul(fee - TAIL_KNEE, slope);\n    }\n\n    function _powWad(uint256 factor, uint256 exp) internal pure returns (uint256 result) {\n        result = WAD;\n        while (exp > 0) {\n            if (exp & 1 == 1) result = wmul(result, factor);\n            factor = wmul(factor, factor);\n            exp >>= 1;\n        }\n    }\n\n    function _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) {\n        uint256 mul = _powWad(decayFactor, elapsed);\n        if (centered >= WAD) { return WAD + wmul(centered - WAD, mul); }\n        uint256 below = wmul(WAD - centered, mul);\n        return below < WAD ? WAD - below : 0;\n    }\n\n    // Floor square root: bit-length seed and seven Newton steps (all uint256).\n    function _isqrt(uint256 x) internal pure returns (uint256 r) {\n        if (x == 0) return 0;\n        unchecked {\n            uint256 y = x;\n            r = 1;\n            if (y >> 128 != 0) { y >>= 128; r <<= 64; }\n            if (y >> 64 != 0) { y >>= 64; r <<= 32; }\n            if (y >> 32 != 0) { y >>= 32; r <<= 16; }\n            if (y >> 16 != 0) { y >>= 16; r <<= 8; }\n            if (y >> 8 != 0) { y >>= 8; r <<= 4; }\n            if (y >> 4 != 0) { y >>= 4; r <<= 2; }\n            if (y >> 2 != 0) { r <<= 1; }\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            r = (r + x / r) >> 1;\n            uint256 t = x / r;\n            return r < t ? r : t;\n        }\n    }\n\n    function getName() external pure override returns (string memory) { return \"censored_10\"; }\n}\n",
      "generator_source": "def generate(base,p):\n kind,mix,decay,scale,sscale,correction=p\n mix=int(mix*1e18);decay=int(decay*1e18)\n s=base.replace('(fastHat, uncertainty) = _posterior','uint256 arbProbability;\\n        (fastHat, uncertainty, arbProbability) = _posterior')\n s=s.replace('internal pure returns (uint256, uint256) {\\n        if (x.mu', 'internal pure returns (uint256, uint256, uint256) {\\n        if (x.mu')\n s=s.replace('wmul(x.v,WAD-k));','wmul(x.v,WAD-k),0);').replace('return (x.mu,x.v);','return (x.mu,x.v,0);').replace('return (mean,variance);','return (mean,variance,prob);')\n insert=f'''\n        if ({mix} > 0) {{\n            uint256 packedFlow = slots[15];\n            uint256 rate = uint80(packedFlow);\n            uint256 count = uint80(packedFlow >> 80);\n            uint256 meanSize = uint80(packedFlow >> 160);\n            if (rate == 0) rate = 400000000000000000;\n            if (meanSize == 0) meanSize = 2000000000000000;\n            if (isNewStep) {{\n                uint256 inst = count / silent;\n                if (inst > 3 * WAD) inst = 3 * WAD;\n                uint256 retention = _powWad({decay}, silent > 64 ? 64 : silent);\n                rate = wmul(rate, retention) + wmul(inst, WAD-retention);\n                count = 0;\n            }}\n            uint256 weight = firstInStep ? WAD-arbProbability : WAD;\n            uint256 correctedWeight = weight;\n            if ({kind} == 2) {{\n                uint256 missing = wmul(feeUsed, {int(correction*1e18)});\n                if (missing > WAD/2) missing = WAD/2;\n                correctedWeight = wdiv(weight, WAD-missing);\n            }}\n            count += correctedWeight;\n            uint256 learning = wmul(WAD-{decay}, weight);\n            meanSize = _blend(meanSize, tradeRatio, learning);\n            slots[15]=rate | (count << 80) | (meanSize << 160);\n            uint256 retailRate = wmul(rate, {int(scale*1e18)});\n            uint256 retailSize = {kind} == 0 ? sizeHat : wmul(meanSize,{int(sscale*1e18)});\n            lambdaHat = _blend(lambdaHat,retailRate,{mix});\n            sizeHat = _blend(sizeHat,retailSize,{mix});\n        }}\n'''\n s=s.replace('        uint256 flowSize =', '        uint256 originalLambda = lambdaHat; uint256 originalSize = sizeHat;\\n'+insert+'        uint256 flowSize =')\n s=s.replace('        uint256 dirDev;', '        lambdaHat = originalLambda; sizeHat = originalSize;\\n        uint256 dirDev;')\n s=s.replace(\"slots[13] = 902500000000;\", \"slots[15] = 400000000000000000 | (uint256(2000000000000000) << 160); slots[13] = 902500000000;\") if mix else s\n return s\n",
      "instructions": "Use generate(v10_code, arm.params) for A0..A7; V10 uses v10_code directly. UTF-8 source SHA256 must match each arm. Use the supplied V10 harness_source functions with start=755000,n=512 and independently run each arm vs compiled VanillaStrategy, workers=8. No search or selection.",
      "harness_functions": "import argparse,hashlib,json,math\nfrom pathlib import Path\nimport numpy as np\nimport amm_sim_rs as sim\nfrom amm_competition.evm.compiler import SolidityCompiler\n\n\ndef configs(start,n):\n    configs=[]\n    for seed in range(start,start+n):\n        rng=np.random.default_rng(seed)\n        size=rng.uniform(19.,21.)\n        rate=rng.uniform(.6,1.)\n        sigma=rng.uniform(.000882,.001008)\n        configs.append(sim.SimulationConfig(n_steps=10000,initial_price=100.,\n            initial_x=100.,initial_y=10000.,gbm_mu=0.,gbm_sigma=sigma,gbm_dt=1.,\n            retail_arrival_rate=rate,retail_mean_size=size,retail_size_sigma=1.2,\n            retail_buy_prob=.5,seed=seed))\n    return configs\n\n\ndef decomposition(r,initial_fee=.0004):\n    # Fees are outside reserves, so k stays fixed up to floating-point roundoff.\n    # The arb acts before retail, using the preceding step's final spot and fees.\n    steps=r.steps\n    fair=np.array([s.fair_price for s in steps])\n    spots=np.array([r.initial_fair_price]+[s.spot_prices['submission'] for s in steps[:-1]])\n    bids=np.array([initial_fee]+[s.fees['submission'][0] for s in steps[:-1]])\n    asks=np.array([initial_fee]+[s.fees['submission'][1] for s in steps[:-1]])\n    x0,y0=r.initial_reserves['submission'];k=x0*y0\n    x=np.sqrt(k/spots);y=np.sqrt(k*spots)\n    ga=1-asks;gb=1-bids\n    out=np.minimum(np.maximum(x-np.sqrt(k/(ga*fair)),0),.99*x)\n    paid=(k/(x-out)-y)/ga\n    buyprofit=np.where(out>0,np.maximum(out*fair-paid,0),0)\n    gross=np.maximum((np.sqrt(k*gb/fair)-x)/gb,0)\n    received=y-k/(x+gb*gross)\n    sellprofit=np.where(gross>0,np.maximum(received-gross*fair,0),0)\n    arb=-float(np.sum(np.where(spots<fair,buyprofit,sellprofit)))\n    return arb,r.edges['submission']-arb\n\n\ndef aggregate(chunks):\n    out={}\n    for chunk in chunks:\n        for row in chunk['raw']:\n            key=(row['role'],row['callback'])\n            dest=out.setdefault(key,{'role':row['role'],'callback':row['callback']})\n            for k,v in row.items():\n                if k in ['role','callback']:continue\n                dest[k]=max(dest.get(k,0),v) if k=='max_ok_gas' else dest.get(k,0)+v\n    return list(out.values())\n\n\ndef run(source,start,n,vanilla,compiler):\n    compiled=compiler.compile(source)\n    assert compiled.success,compiled.errors\n    rows=[];chunks=[]\n    for first in range(start,start+n,20):\n        count=min(20,start+n-first)\n        sim.gas_stats_reset()\n        batch=sim.run_batch(list(compiled.bytecode),list(vanilla),configs(first,count),8)\n        results=batch.results\n        assert sorted(r.seed for r in results)==list(range(first,first+count))\n        for r in results:\n            arb,retail=decomposition(r)\n            rows.append({'seed':r.seed,'edge':r.edges['submission'],'arb':arb,'retail':retail})\n        chunks.append({'start':first,'raw':sim.gas_stats()})\n        del results,batch\n    return {'sha256':hashlib.sha256(source.encode()).hexdigest(),'rows':rows,\n            'raw_counters':aggregate(chunks),'chunks':chunks}\n\n\ndef stats(d):\n    d=np.asarray(d,dtype=float)\n    return {'mean':float(d.mean()),'se':float(d.std(ddof=1)/np.sqrt(len(d)))}\n\n\ndef compare(candidate,stack):\n    a={r['seed']:r for r in candidate['rows']};b={r['seed']:r for r in stack['rows']}\n    assert a.keys()==b.keys()\n    seeds=sorted(a)\n    d=np.array([a[s]['edge']-b[s]['edge'] for s in seeds])\n    arb=np.array([a[s]['arb']-b[s]['arb'] for s in seeds])\n    retail=np.array([a[s]['retail']-b[s]['retail'] for s in seeds])\n    assert np.max(np.abs(d-arb-retail))<1e-8\n    summary=stats(d)\n    return {'paired':{'n':len(d),'mean_diff':summary['mean'],'se':summary['se'],\n                'worst':[{'seed':seeds[i],'d':float(d[i])} for i in np.argsort(d)[:5]]},\n            'retail_edge_delta':stats(retail),'arb_edge_delta':stats(arb),\n            'reconciliation_max_abs':float(np.max(np.abs(d-arb-retail)))}\n\n\n"
    },
    "additional_paired_comparisons": {
      "A3_minus_A2": {
        "mean": 0.30196758909243493,
        "se": 0.02419376713480152
      },
      "A0_minus_A3": {
        "mean": -0.06424037146262562,
        "se": 0.013257733530239846
      },
      "A0_minus_A5": {
        "mean": 0.028366500850022902,
        "se": 0.012388594357998666
      },
      "A0_minus_A6": {
        "mean": 0.014833643097142302,
        "se": 0.01344597549374796
      },
      "A0_minus_A7": {
        "mean": -0.042199411253371344,
        "se": 0.015640690010357346
      }
    },
    "arm_mean_edges": {
      "V10": 528.8653917559639,
      "A0": 528.9480003112345,
      "A1": 528.8653917559639,
      "A2": 528.7102730936047,
      "A3": 529.0122406826971,
      "A4": 529.0126299571043,
      "A5": 528.9196338103845,
      "A6": 528.9331666681373,
      "A7": 528.9901997224879
    },
    "reconciliation_max_abs": {
      "V10": 0.0,
      "A0": 1.0658141036401503e-13,
      "A1": 0.0,
      "A2": 1.1368683772161603e-13,
      "A3": 1.0658141036401503e-13,
      "A4": 1.1368683772161603e-13,
      "A5": 1.1368683772161603e-13,
      "A6": 1.1013412404281553e-13,
      "A7": 1.1368683772161603e-13
    },
    "all_callback_errors": {
      "V10": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A0": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A1": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A2": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A3": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A4": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A5": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A6": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      },
      "A7": {
        "oog": 0,
        "revert": 0,
        "other_halt": 0,
        "tx_error": 0,
        "bad_return": 0
      }
    }
  }
}
