{
  "approach": "R4 th-killed: one behavioral delta on the specified NP baseline. On the first print after completed silent steps, relax pHat toward the preceding fee band midpoint with retention exp(-c*k*sigmaHat^2/W^2). Select c only on the authorized tuning seeds, freeze the complete source, and evaluate it once on the fresh block.",
  "tried": [
    {
      "variant": "k0375",
      "c": 0.375,
      "code_sha256": "35fb644fb204b971cc1bf75948b838e5a4391a342400df5d4bc12a5987c47beb",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": 0.15326283077149253,
      "se": 0.010229692015249914,
      "worst": [
        {
          "seed": 31017,
          "diff": -2.774991529705744
        },
        {
          "seed": 31764,
          "diff": -2.678130371057364
        },
        {
          "seed": 31872,
          "diff": -1.4797555752408584
        },
        {
          "seed": 31966,
          "diff": -1.4637228280881232
        },
        {
          "seed": 31076,
          "diff": -1.4602026227033775
        }
      ],
      "mean_edge": 524.0340322499634,
      "seconds_per_simulation": 0.10276548543025274
    },
    {
      "variant": "k025",
      "c": 0.25,
      "code_sha256": "229a3960aadc3e6f75353571ba47838f7a89c367b1e333195274208d7e94e069",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": 0.15068206850353116,
      "se": 0.008648995702293221,
      "worst": [
        {
          "seed": 31764,
          "diff": -2.0631593856713835
        },
        {
          "seed": 31966,
          "diff": -1.5631283063825094
        },
        {
          "seed": 31017,
          "diff": -1.3192268396985583
        },
        {
          "seed": 31872,
          "diff": -1.2649792691192943
        },
        {
          "seed": 31106,
          "diff": -1.0966524194049043
        }
      ],
      "mean_edge": 524.0314514876954,
      "seconds_per_simulation": 0.10155153415421955
    },
    {
      "variant": "k05",
      "c": 0.5,
      "code_sha256": "fe5f09ce19681047785e40ca36dcddfad1636722ce3299c987aded2e18caf147",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": 0.13929048697864602,
      "se": 0.011277097437596376,
      "worst": [
        {
          "seed": 31017,
          "diff": -2.872711667048179
        },
        {
          "seed": 31764,
          "diff": -2.8636214308951367
        },
        {
          "seed": 30690,
          "diff": -1.965178667062446
        },
        {
          "seed": 30157,
          "diff": -1.5271526307269596
        },
        {
          "seed": 31872,
          "diff": -1.4729604744825906
        }
      ],
      "mean_edge": 524.0200599061706,
      "seconds_per_simulation": 0.10323440130555536
    },
    {
      "variant": "k0125",
      "c": 0.125,
      "code_sha256": "60a6e91c0a40d58fb135928b35e326524520e2f2e6fd92111d414103c59cece5",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": 0.11597840822388188,
      "se": 0.0067530713504279,
      "worst": [
        {
          "seed": 31396,
          "diff": -1.5269243826813863
        },
        {
          "seed": 31966,
          "diff": -1.315802621321268
        },
        {
          "seed": 30429,
          "diff": -1.2883236382796213
        },
        {
          "seed": 31076,
          "diff": -1.1072468051017381
        },
        {
          "seed": 30265,
          "diff": -1.0495102631666668
        }
      ],
      "mean_edge": 523.9967478274158,
      "seconds_per_simulation": 0.10357817053038161
    },
    {
      "variant": "k00625",
      "c": 0.0625,
      "code_sha256": "120ea4e5d3a048565aee3f50b1f981d68f906653714a7f191ca0d98cb1698635",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": 0.07251059555876924,
      "se": 0.00506251560181631,
      "worst": [
        {
          "seed": 31396,
          "diff": -1.2703125060369302
        },
        {
          "seed": 31966,
          "diff": -1.153027959040287
        },
        {
          "seed": 30264,
          "diff": -0.9574425349374565
        },
        {
          "seed": 30173,
          "diff": -0.8342532525623483
        },
        {
          "seed": 31293,
          "diff": -0.832750275879107
        }
      ],
      "mean_edge": 523.9532800147507,
      "seconds_per_simulation": 0.10255564098630567
    },
    {
      "variant": "k1",
      "c": 1.0,
      "code_sha256": "25b3e6accf395e67365393bd4b5107ca8a94f322e73df3d8d31cc5766bfb60db",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": -0.00527273638443512,
      "se": 0.013754465733546396,
      "worst": [
        {
          "seed": 31017,
          "diff": -4.061589450654765
        },
        {
          "seed": 31764,
          "diff": -3.252769740663325
        },
        {
          "seed": 31703,
          "diff": -2.074163256906445
        },
        {
          "seed": 31966,
          "diff": -2.0112748404571335
        },
        {
          "seed": 30142,
          "diff": -1.8338842822359425
        }
      ],
      "mean_edge": 523.8754966828075,
      "seconds_per_simulation": 0.10984663040481973
    },
    {
      "variant": "k4",
      "c": 4.0,
      "code_sha256": "c066620b7146db78ae0d7283cbe2404b0c03dc401a7ce5c5df633644728c3c43",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": -0.833178711755184,
      "se": 0.01997999875219484,
      "worst": [
        {
          "seed": 30203,
          "diff": -5.105383837576824
        },
        {
          "seed": 31017,
          "diff": -5.065977738639845
        },
        {
          "seed": 30142,
          "diff": -5.01406783968423
        },
        {
          "seed": 31725,
          "diff": -4.650517303863808
        },
        {
          "seed": 31490,
          "diff": -4.283322367135611
        }
      ],
      "mean_edge": 523.0475907074368,
      "seconds_per_simulation": 0.14636894211254547
    },
    {
      "variant": "k148",
      "c": 14.804406601634037,
      "code_sha256": "ec3f555eb149d717e8b923746ad878a8b04bd09b79ea88273bcf1192d5949e35",
      "seeds": [
        30000,
        31999
      ],
      "n": 2000,
      "mean_diff": -1.8576436028306749,
      "se": 0.025730907004947567,
      "worst": [
        {
          "seed": 30103,
          "diff": -7.501315101924206
        },
        {
          "seed": 30203,
          "diff": -7.31633272587851
        },
        {
          "seed": 31017,
          "diff": -7.116387463323122
        },
        {
          "seed": 30449,
          "diff": -6.783445510650608
        },
        {
          "seed": 31725,
          "diff": -6.316110368866248
        }
      ],
      "mean_edge": 522.0231258163612,
      "seconds_per_simulation": 0.14251193958648947
    }
  ],
  "next": [
    "Promote this frozen candidate: its one fresh paired gain over NP exceeds twice its standard error.",
    "Independently replicate the frozen source on another explicitly authorized fresh seed block before combining it with other deltas.",
    "The reserved seeds 900000..909999 were never used."
  ],
  "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 KILLED_C = 375000000000000000;\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 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[2] = 0; slots[3] = WAD; slots[4] = 0;\n        slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n        slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n        slots[9] = 0; slots[10] = 0; slots[11] = 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 = 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        bool isNewStep = trade.timestamp > lastTs;\n        if (isNewStep) {\n            uint256 elapsedRaw = trade.timestamp - lastTs;\n            // Only the completed silent steps condition the old posterior.\n            if (elapsedRaw > 1 && stepTradeCount > 0) {\n                pHat = _relaxKilled(pHat, sigmaHat, prevBidFee, prevAskFee, elapsedRaw - 1);\n            }\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            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        {\n            uint256 ret = pHat > 0 ? wdiv(absDiff(pImplied, pHat), pHat) : 0;\n            uint256 alpha = firstInStep ? PHAT_ALPHA : PHAT_ALPHA_RETAIL;\n            uint256 adaptiveGate = wmul(sigmaHat, GATE_SIGMA_MULT);\n            if (adaptiveGate < MIN_GATE) adaptiveGate = MIN_GATE;\n            if (ret <= adaptiveGate) { pHat = wmul(pHat, WAD - alpha) + wmul(pImplied, alpha); }\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        if(!firstInStep&&feeUsed>30*BPS&&gamma>0){uint256 nS=trade.isBuy?wdiv(wmul(spot,gamma),WAD-30*BPS):wdiv(wmul(spot,WAD-30*BPS),gamma);pHat=wmul(pHat,9*WAD/10)+wmul(nS,WAD/10);}\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 staleShift = wmul(STALE_DIR_COEF, toxSignal);\n            uint256 attractShift = wmul(staleShift, STALE_ATTRACT_FRAC);\n            if (spot >= pHat) {\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 (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        slots[0] = bidFee; slots[1] = askFee; slots[2] = 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; slots[11] = spot;\n\n        return (bidFee, askFee);\n    }\n\n    // Relative arithmetic band width: (upper - lower) / centre.\n    // The previous spot and previous fees define this band, before this print.\n    function _relaxKilled(uint256 p, uint256 sigma, uint256 bid, uint256 ask, uint256 k)\n        internal view returns (uint256)\n    {\n        uint256 oldSpot = slots[11];\n        if (oldSpot == 0 || ask >= WAD || bid >= WAD) return p;\n        uint256 lower = wmul(oldSpot, WAD - bid);\n        uint256 upper = wdiv(oldSpot, WAD - ask);\n        uint256 centre = (lower + upper) / 2;\n        if (centre == 0 || upper <= lower) return p;\n        uint256 width = wdiv(upper - lower, centre);\n        uint256 width2 = wmul(width, width);\n        if (width2 == 0) return p;\n        // A simulation has 10,000 steps; bound arithmetic for arbitrary timestamps.\n        if (k > 10000) k = 10000;\n        uint256 x = wmul(KILLED_C, wdiv(wmul(sigma, sigma), width2)) * k;\n        uint256 retain = _expNegative(x);\n        return wmul(p, retain) + wmul(centre, WAD - retain);\n    }\n\n    // exp(-x) via a [3/3] Pade approximant of exp(-x/16), squared four times.\n    // Fixed operation count, nonnegative, with saturation beyond x = 32.\n    function _expNegative(uint256 x) internal pure returns (uint256 r) {\n        if (x >= 32 * WAD) return 0;\n        uint256 t = x / 16;\n        uint256 t2 = wmul(t, t);\n        uint256 t3 = wmul(t2, t);\n        r = wdiv(120 * WAD + 12 * t2 - 60 * t - t3,\n                 120 * WAD + 12 * t2 + 60 * t + t3);\n        r = wmul(r, r);\n        r = wmul(r, r);\n        r = wmul(r, r);\n        r = wmul(r, r);\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        // Every caller caps exp at ELAPSED_CAP = 8. Unroll exactly.\n        if (exp & 1 == 1) result = wmul(result, factor);\n        factor = wmul(factor, factor);\n        if (exp & 2 == 2) result = wmul(result, factor);\n        factor = wmul(factor, factor);\n        if (exp & 4 == 4) result = wmul(result, factor);\n        factor = wmul(factor, factor);\n        if (exp & 8 == 8) result = wmul(result, factor);\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    function getName() external pure override returns (string memory) { return \"NP_killed_kernel\"; }\n}\n",
  "code_sha256": "35fb644fb204b971cc1bf75948b838e5a4391a342400df5d4bc12a5987c47beb",
  "delta": {
    "from": "NP",
    "reference_sha256": "95d21646a5b6d293c86c36a184769477be7b1ff39ab2adde7668ed79fb22dd38",
    "behavioral_change": "Killed-kernel relaxation only; c = 0.375.",
    "mechanical_changes": "Save last spot in slot 11; add bounded exponential helper; unroll the inherited decay power for capped exponents 0..8 without changing its arithmetic; change display name.",
    "unified_diff": "--- NP.sol\n+++ Strategy.sol\n@@ -5,6 +5,7 @@\n import {TradeInfo} from \"./IAMMStrategy.sol\";\n \n contract Strategy is AMMStrategyBase {\n+    uint256 constant KILLED_C = 375000000000000000;\n     uint256 constant ELAPSED_CAP = 8;\n     uint256 constant SIGNAL_THRESHOLD = WAD / 650;\n     uint256 constant DIR_DECAY = 750000000000000000;\n@@ -47,7 +48,7 @@\n         slots[0] = BASE_FEE; slots[1] = BASE_FEE; slots[2] = 0; slots[3] = WAD; slots[4] = 0;\n         slots[5] = initialX > 0 ? wdiv(initialY, initialX) : 100 * WAD;\n         slots[6] = 950000000000000; slots[7] = 800000000000000000; slots[8] = 2000000000000000;\n-        slots[9] = 0; slots[10] = 0;\n+        slots[9] = 0; slots[10] = 0; slots[11] = slots[5];\n         return (BASE_FEE, BASE_FEE);\n     }\n \n@@ -60,6 +61,10 @@\n         bool isNewStep = trade.timestamp > lastTs;\n         if (isNewStep) {\n             uint256 elapsedRaw = trade.timestamp - lastTs;\n+            // Only the completed silent steps condition the old posterior.\n+            if (elapsedRaw > 1 && stepTradeCount > 0) {\n+                pHat = _relaxKilled(pHat, sigmaHat, prevBidFee, prevAskFee, elapsedRaw - 1);\n+            }\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@@ -172,9 +177,45 @@\n         slots[0] = bidFee; slots[1] = askFee; slots[2] = 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+        slots[9] = toxEma; slots[10] = stepTradeCount; slots[11] = spot;\n \n         return (bidFee, askFee);\n+    }\n+\n+    // Relative arithmetic band width: (upper - lower) / centre.\n+    // The previous spot and previous fees define this band, before this print.\n+    function _relaxKilled(uint256 p, uint256 sigma, uint256 bid, uint256 ask, uint256 k)\n+        internal view returns (uint256)\n+    {\n+        uint256 oldSpot = slots[11];\n+        if (oldSpot == 0 || ask >= WAD || bid >= WAD) return p;\n+        uint256 lower = wmul(oldSpot, WAD - bid);\n+        uint256 upper = wdiv(oldSpot, WAD - ask);\n+        uint256 centre = (lower + upper) / 2;\n+        if (centre == 0 || upper <= lower) return p;\n+        uint256 width = wdiv(upper - lower, centre);\n+        uint256 width2 = wmul(width, width);\n+        if (width2 == 0) return p;\n+        // A simulation has 10,000 steps; bound arithmetic for arbitrary timestamps.\n+        if (k > 10000) k = 10000;\n+        uint256 x = wmul(KILLED_C, wdiv(wmul(sigma, sigma), width2)) * k;\n+        uint256 retain = _expNegative(x);\n+        return wmul(p, retain) + wmul(centre, WAD - retain);\n+    }\n+\n+    // exp(-x) via a [3/3] Pade approximant of exp(-x/16), squared four times.\n+    // Fixed operation count, nonnegative, with saturation beyond x = 32.\n+    function _expNegative(uint256 x) internal pure returns (uint256 r) {\n+        if (x >= 32 * WAD) return 0;\n+        uint256 t = x / 16;\n+        uint256 t2 = wmul(t, t);\n+        uint256 t3 = wmul(t2, t);\n+        r = wdiv(120 * WAD + 12 * t2 - 60 * t - t3,\n+                 120 * WAD + 12 * t2 + 60 * t + t3);\n+        r = wmul(r, r);\n+        r = wmul(r, r);\n+        r = wmul(r, r);\n+        r = wmul(r, r);\n     }\n \n     function _compressTailWithSlope(uint256 fee, uint256 slope) internal pure returns (uint256) {\n@@ -184,11 +225,14 @@\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+        // Every caller caps exp at ELAPSED_CAP = 8. Unroll exactly.\n+        if (exp & 1 == 1) result = wmul(result, factor);\n+        factor = wmul(factor, factor);\n+        if (exp & 2 == 2) result = wmul(result, factor);\n+        factor = wmul(factor, factor);\n+        if (exp & 4 == 4) result = wmul(result, factor);\n+        factor = wmul(factor, factor);\n+        if (exp & 8 == 8) result = wmul(result, factor);\n     }\n \n     function _decayCentered(uint256 centered, uint256 decayFactor, uint256 elapsed) internal pure returns (uint256) {\n@@ -198,5 +242,5 @@\n         return below < WAD ? WAD - below : 0;\n     }\n \n-    function getName() external pure override returns (string memory) { return \"no_cubic\"; }\n+    function getName() external pure override returns (string memory) { return \"NP_killed_kernel\"; }\n }\n"
  },
  "score": {
    "seed_start": 0,
    "n": 1000,
    "mean_edge": 526.1991083554738,
    "se": 2.790516186060696
  },
  "paired": {
    "reference": "NP",
    "reference_sha256": "95d21646a5b6d293c86c36a184769477be7b1ff39ab2adde7668ed79fb22dd38",
    "seed_start": 800000,
    "n": 2000,
    "mean_diff": 0.15131209979002405,
    "se": 0.013195411696962658,
    "worst": [
      {
        "seed": 800366,
        "diff": -11.539108508032541
      },
      {
        "seed": 801611,
        "diff": -2.9435418187950972
      },
      {
        "seed": 801283,
        "diff": -2.4486690242089253
      },
      {
        "seed": 801200,
        "diff": -2.036438103633486
      },
      {
        "seed": 801153,
        "diff": -1.7683303092414917
      }
    ],
    "n_covered": 2000,
    "seed_end": 801999,
    "chunks": [
      {
        "seed_start": 800000,
        "seed_end": 800499,
        "n": 500,
        "cumulative_n": 500,
        "mean_diff": 0.14278888908802015,
        "se": 0.03578467878525248,
        "worst": [
          {
            "seed": 800366,
            "diff": -11.539108508032541
          },
          {
            "seed": 800070,
            "diff": -1.5409712239261353
          },
          {
            "seed": 800207,
            "diff": -1.361277733485963
          },
          {
            "seed": 800160,
            "diff": -1.1670520936747835
          },
          {
            "seed": 800388,
            "diff": -1.129116116779187
          }
        ]
      },
      {
        "seed_start": 800500,
        "seed_end": 800999,
        "n": 500,
        "cumulative_n": 1000,
        "mean_diff": 0.20247193848865083,
        "se": 0.021547073345700114,
        "worst": [
          {
            "seed": 800873,
            "diff": -1.2484136020832466
          },
          {
            "seed": 800797,
            "diff": -1.1668709541983162
          },
          {
            "seed": 800896,
            "diff": -0.9973600641296798
          },
          {
            "seed": 800921,
            "diff": -0.9369338765783368
          },
          {
            "seed": 800618,
            "diff": -0.8054691861506171
          }
        ]
      },
      {
        "seed_start": 801000,
        "seed_end": 801499,
        "n": 500,
        "cumulative_n": 1500,
        "mean_diff": 0.1468890431773126,
        "se": 0.025370285406659396,
        "worst": [
          {
            "seed": 801283,
            "diff": -2.4486690242089253
          },
          {
            "seed": 801200,
            "diff": -2.036438103633486
          },
          {
            "seed": 801153,
            "diff": -1.7683303092414917
          },
          {
            "seed": 801227,
            "diff": -1.5911918706839288
          },
          {
            "seed": 801443,
            "diff": -1.4526248218297724
          }
        ]
      },
      {
        "seed_start": 801500,
        "seed_end": 801999,
        "n": 500,
        "cumulative_n": 2000,
        "mean_diff": 0.11309852840611267,
        "se": 0.0198308380118758,
        "worst": [
          {
            "seed": 801611,
            "diff": -2.9435418187950972
          },
          {
            "seed": 801898,
            "diff": -1.6352695359951213
          },
          {
            "seed": 801860,
            "diff": -1.5309737857547816
          },
          {
            "seed": 801686,
            "diff": -1.0514653498113375
          },
          {
            "seed": 801621,
            "diff": -0.9859005078667451
          }
        ]
      }
    ]
  },
  "seconds_per_simulation": 0.10471400568482932,
  "validate_ok": true,
  "blocked": null,
  "citations": [
    {
      "url": "https://raw.githubusercontent.com/ChengHua926/amm-challenge/d34a5199c59a4c44d5336a25f1436b4ae1f21104/contracts/src/Strategy.sol",
      "supports": "Pinned CH source, the starting implementation. NP is the exact requester-supplied insertion into this source."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py",
      "supports": "Official per-seed randomized draws, ordered mean size, arrival rate, sigma."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/config.py",
      "supports": "Canonical settings: 10000 steps, initial reserves, parameter ranges, and retail process settings."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/simulation/engine.rs",
      "supports": "Separate price seed and retail seed+1, arbitrage-before-retail ordering, and submission edge accounting."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/market/arbitrageur.rs",
      "supports": "Fee-on-input arbitrage solution; used to derive the no-arbitrage band [spot*(1-bid), spot/(1-ask)]."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/evm/strategy.rs",
      "supports": "Pinned Rust execution gas limit."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/compiler.py",
      "supports": "Official compiler, optimization/viaIR settings, opcode scan, and storage layout checks."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_sim_rs/src/amm/cfmm.rs",
      "supports": "Fees are collected separately from reserves; failed strategy updates retain prior fees. Direct gas-limited swap checks supplement CLI validation."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/contracts/src/AMMStrategyBase.sol",
      "supports": "Allowed storage, WAD arithmetic helpers and maximum fee."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/contracts/src/VanillaStrategy.sol",
      "supports": "Both candidate and NP are simulated separately against this 30 bps normalizer."
    },
    {
      "url": "https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/contracts/src/StarterStrategy.sol",
      "supports": "The pinned fixed-50-bps starter used for the additional paired comparison."
    },
    {
      "url": "https://raw.githubusercontent.com/jiayaoqijia/amm-challenge-yq/3e9dc7d5a6192c88b562a0f8d9c172ca566ec94d/README.md",
      "supports": "Public YQ write-up: adaptive fair-price gating, toxicity, and asymmetric stale-price fees. Context only, not a benchmark for this item."
    },
    {
      "url": "https://raw.githubusercontent.com/dipankar/amm-challenge/main/README.md",
      "supports": "Public SigmaAdaptive write-up discusses state estimation and asymmetric fees; warns that local and leaderboard levels differ."
    },
    {
      "url": "https://www.linkedin.com/pulse/amm-fee-challenge-notes-from-our-run-optimization-arena-qe3ff",
      "supports": "Algebra first-party write-up describes environmental estimates, immediate pool signals, asymmetric fees and first-trade arbitrage ordering."
    }
  ],
  "decision": {
    "promote": true,
    "criterion": "Fresh paired mean_diff > 2*SE with n=2000.",
    "selected_variant": "k0375",
    "selected_c": 0.375,
    "frozen_at_utc": "2026-11-07T05:57:10.375759+00:00",
    "tuning_runner_up": "k025",
    "tuning_top_two_paired_gap": {
      "n": 2000,
      "mean_diff": 0.0025807622679613756,
      "se": 0.005074688094850822,
      "worst": [
        {
          "seed": 31017,
          "diff": -1.455764690007186
        },
        {
          "seed": 30539,
          "diff": -1.1330591945750257
        },
        {
          "seed": 31794,
          "diff": -1.0828563978426473
        },
        {
          "seed": 31263,
          "diff": -1.0504117297109588
        },
        {
          "seed": 30654,
          "diff": -0.7104290607807116
        }
      ]
    },
    "selection_note": "The highest complete tuning mean was selected. A small gap between the top two does not establish that one coefficient is optimal.",
    "code_role": "Frozen experimental candidate; submit as the new best only if promote is true.",
    "fresh_evaluations_of_selected_candidate": 1
  },
  "scoreboard": {
    "previous_best": {
      "name": "NP",
      "code_sha256": "95d21646a5b6d293c86c36a184769477be7b1ff39ab2adde7668ed79fb22dd38",
      "score": {
        "seed_start": 0,
        "n": 1000,
        "mean_edge": 526.0337302497852,
        "se": 2.7912248204542776
      }
    },
    "best_after_this_item": {
      "name": "k0375",
      "code_sha256": "35fb644fb204b971cc1bf75948b838e5a4391a342400df5d4bc12a5987c47beb",
      "score": {
        "seed_start": 0,
        "n": 1000,
        "mean_edge": 526.1991083554738,
        "se": 2.790516186060696
      }
    },
    "ranked_promotions": [
      {
        "rank": 1,
        "name": "k0375",
        "code_sha256": "35fb644fb204b971cc1bf75948b838e5a4391a342400df5d4bc12a5987c47beb",
        "score": {
          "seed_start": 0,
          "n": 1000,
          "mean_edge": 526.1991083554738,
          "se": 2.790516186060696
        },
        "previous_best": "NP",
        "fresh_seed_start": 800000,
        "n": 2000,
        "mean_diff": 0.15131209979002405,
        "se": 0.013195411696962658
      }
    ],
    "scope": "Only this bounded item is ranked; prior network promotions were not measured here."
  },
  "paired_vs_starter": {
    "reference": "Pinned StarterStrategy, fixed 50 bps",
    "reference_sha256": "8f2cea337f6736105f58c6758da6c3ebf002951d34492bcd5b7101bef2d1e7f3",
    "seed_start": 800000,
    "n": 2000,
    "mean_diff": 155.46695729621368,
    "se": 0.8950451936720156,
    "worst": [
      {
        "seed": 801401,
        "diff": 76.83584869095606
      },
      {
        "seed": 800923,
        "diff": 76.9289219082404
      },
      {
        "seed": 800045,
        "diff": 80.40365678070307
      },
      {
        "seed": 801990,
        "diff": 81.16250934429212
      },
      {
        "seed": 800619,
        "diff": 82.03287306200366
      }
    ]
  },
  "reproduction": {
    "CH": {
      "code_sha256": "6dd68f77a70900319460215374143dbd5d924198450a46d9f5f91f6b1e3d35c3",
      "seed_start": 0,
      "n": 1000,
      "mean_edge": 525.5258821780834,
      "se": 2.7894264590251843
    },
    "NP": {
      "code_sha256": "95d21646a5b6d293c86c36a184769477be7b1ff39ab2adde7668ed79fb22dd38",
      "seed_start": 0,
      "n": 1000,
      "mean_edge": 526.0337302497852,
      "se": 2.7912248204542776,
      "paired": {
        "n": 1000,
        "mean_diff": 0.5078480717017371,
        "se": 0.02478168812598005,
        "worst": [
          {
            "seed": 754,
            "diff": -1.9479466686417481
          },
          {
            "seed": 344,
            "diff": -1.5834779003872654
          },
          {
            "seed": 66,
            "diff": -1.5239725930305212
          },
          {
            "seed": 97,
            "diff": -1.4939658617350915
          },
          {
            "seed": 549,
            "diff": -1.428398895904138
          }
        ]
      }
    },
    "CH_expected": 525.525882178,
    "NP_expected": 526.0337302497852,
    "CH_absolute_error": 8.344613888766617e-11,
    "NP_absolute_error": 0.0,
    "note": "These n=1000 measurements reproduce supplied anchors; they are not fresh promotion tests."
  },
  "mechanism": {
    "mechanism": "Killed-kernel mean relaxation is the only behavioral delta on NP.",
    "formula": {
      "lo": "lastSpot * (1 - lastBidFee)",
      "hi": "lastSpot / (1 - lastAskFee)",
      "centre": "(lo + hi)/2",
      "W": "(hi - lo)/centre",
      "k": "current timestamp - last trade timestamp - 1",
      "retention": "exp(-c * k * sigmaHat^2/W^2)",
      "pHat": "retention*pHat + (1-retention)*centre"
    },
    "timing": "Apply before the new first-in-step implied-price update, using previous sigmaHat and fees; save post-swap spot for the next silence interval.",
    "theory": "For driftless Brownian motion killed at an interval of full width W, the first two Dirichlet eigenvalues differ by 3*pi^2*sigma^2/(2*W^2). The leading odd mode of the conditional density decays at this gap. This motivates c=3*pi^2/2; it does not prove optimality for this simulator or the noisy sigmaHat.",
    "theory_c": 14.804406601634037,
    "approximations": [
      "Arithmetic price midpoint and normalized price width approximate log-price coordinates.",
      "No-trade silence also reflects retail routing, so the killed-process posterior is a heuristic.",
      "CH sigmaHat is an observation-based EMA, not the latent fixed GBM sigma.",
      "The continuous killed-Brownian survival model approximates a simulator that checks arbitrage only at discrete steps."
    ],
    "selection_rule": "Rank only completed >=2000-seed tuning comparisons by mean candidate-minus-NP; freeze one source/hash before any seeds 800000..801999. Promote only if its one fresh paired mean is >2*SE.",
    "tuning_seed_range": [
      30000,
      31999
    ],
    "reserved_never_used": [
      900000,
      909999
    ],
    "mechanical_delta": "Unroll NP binary exponentiation for exponents 0..8; zero-coefficient equivalence test preserves all fee outputs. getName changes only display text.",
    "source_verification": "14 public source URLs were fetched and their exact quotes verified locally."
  },
  "measurement": {
    "provenance": "All numerical results are local measurements, not public leaderboard scores.",
    "leaderboard_verification": "The Paradigm puzzle page was inaccessible through the web tool. The live leaderboard was not independently reverified; no placement is claimed.",
    "engine_commit": "6b6921f8d463314aa7c96234e1be25a25245f704",
    "engine_modified": false,
    "backend": "amm_sim_rs.run_batch",
    "compiler": "Official SolidityCompiler: solc 0.8.24, viaIR, optimizer runs 200, EVM paris.",
    "pairing": "Candidate and NP are each run against VanillaStrategy (30 bps) with identical per-seed configs; diff_i = candidate submission edge_i - NP submission edge_i. They are not placed against one another in the same AMM market.",
    "draws": "For each seed s: rng=np.random.default_rng(s); mean_size=rng.uniform(19,21); arrival_rate=rng.uniform(0.6,1.0); sigma=rng.uniform(0.000882,0.001008), in that order. Price RNG seed=s; retail RNG seed=s+1.",
    "settings": {
      "n_steps": 10000,
      "initial_price": 100,
      "initial_x": 100,
      "initial_y": 10000,
      "gbm_mu": 0,
      "gbm_dt": 1,
      "retail_size_sigma": 1.2,
      "retail_buy_prob": 0.5
    },
    "statistics": "Arithmetic sample means; SE=sample standard deviation (ddof=1)/sqrt(n). Worst rows are the five smallest per-seed candidate-reference differences.",
    "tuning_seed_range": [
      30000,
      31999
    ],
    "tuning_reference": {
      "code_sha256": "95d21646a5b6d293c86c36a184769477be7b1ff39ab2adde7668ed79fb22dd38",
      "seed_start": 30000,
      "n": 2000,
      "mean_edge": 523.8807694191919,
      "se": 2.001172789992937
    },
    "tuning_reference_reused": true,
    "report_chunk_size": 500,
    "internal_run_batch_size": 16,
    "chunk_note": "Each 500-seed reporting block is partitioned into consecutive run_batch calls of at most 16 (last call 4). This limits retained per-step chart data without altering the pinned engine, seeds, or trades.",
    "fresh_candidate_mean_edge": 522.2361509902819,
    "fresh_reference_mean_edge": 522.0848388904918,
    "fresh_candidate_edge_se": 2.0097522291054677,
    "fresh_reference_edge_se": 2.010056916780179,
    "score_set_paired_diagnostic": {
      "n": 1000,
      "mean_diff": 0.1653781056884596,
      "se": 0.014671248035316109,
      "worst": [
        {
          "seed": 715,
          "diff": -2.4393122254215314
        },
        {
          "seed": 472,
          "diff": -2.203515602231846
        },
        {
          "seed": 972,
          "diff": -1.5887992500473729
        },
        {
          "seed": 638,
          "diff": -1.556630408493561
        },
        {
          "seed": 219,
          "diff": -1.0698909043417189
        }
      ]
    },
    "score_set_used_for_selection": false,
    "fresh_pair_seconds_per_seed": 0.2029809917039238,
    "timing_definition": "Wall time inside simulation calls plus extracting edges and releasing returned objects, divided by simulations; excludes setup and compilation.",
    "ordered_fresh_edges_sha256": "74955d03feba314b579e485312de2aa7ead3a7be81a4d16f31c3683676ed00b3",
    "ordered_reference_edges_sha256": "cade847f6e4e6b4237f4d0073bb528a75274e7cb0ce77c31100ba0bbaa183141"
  },
  "checks": {
    "ok": true,
    "pade_grid_points": 32001,
    "max_absolute_exp_error": 4.4738394412713323e-10,
    "tested_source": "scratch/FrozenStrategy.sol",
    "official_config_matches": 1000,
    "zero_coefficient_exact_equivalence_trades": 400,
    "active_kernel_changes_quotes": 398,
    "gas_check": "Every init and synthetic swap executed with a 250000 gas limit; no gas estimate is asserted.",
    "slot_indices": [
      0,
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11
    ],
    "final_cli_validate": "Validating strategy...\nCompiling strategy...\nStrategy 'NP_killed_kernel' validated successfully!",
    "fresh_source_hash_matches_frozen_source": true,
    "loop_count": 0,
    "import_count": 2,
    "limits": "The pinned engine uses a 250000 gas limit; 400 direct synthetic swaps also passed that limit. No measured exact gas maximum is claimed."
  }
}
