{
 "credit": "Taylor (gtmcknight), github.com/gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9 research/solved: the solved policy, replica and tables that QLX5 and every tool checked here are built on. QLX5 source and engine rows: A/1ef80bfb6d6791b877b1f4048a5e63cf2ae54153e6e8763ae3f8ab13132dfb15; integer port qlxcore (qlxcore.py, mktables.py, evmdiff.py): A/60dc237fa0a4d42f3b6e2d2bed61c1a2df08d27c31ccd95cce508ee9c8689de4; kit: identity-md-launches/goal-3178-build-shared-evaluation-kit@45e7563d1a29ffca9d608fdf60c90bf2624d2d01.",
 "compile": {
  "source_chars": 47230,
  "runtime_bytes": 22440,
  "runtime_sha256": "903a0cf860910022916e7c16aa1ffcfb94b0db9e25074665947d786615a44ae8",
  "expected": {
   "source_chars": 47230,
   "runtime_bytes": 22440,
   "runtime_sha256": "903a0cf860910022916e7c16aa1ffcfb94b0db9e25074665947d786615a44ae8"
  },
  "matches_expected": true,
  "creation_bytes": 22469,
  "creation_sha256": "275fd44fa37b567c17e18607436eebae510e2bd157979bf3a2fdb61228d59dab",
  "warnings": 0,
  "settings": "kit SolidityCompiler: pinned solc 0.8.24, optimizer 200 runs, viaIR, evmVersion paris"
 },
 "engine": {
  "n": 128,
  "seeds": [
   9700000,
   9700127
  ],
  "mean_edge": 520.405078624825,
  "peak_gas": 205887,
  "oog": 0,
  "failed": 0,
  "sd": 84.84085643980413,
  "min_edge": 350.503770424938,
  "max_edge": 709.6945613325859,
  "peak_gas_seed": 9700045,
  "after_swap_calls": 1377819,
  "mean_after_swap_gas": 136725.3,
  "failed_definition": "revert + other_halt + tx_error + bad_return + (calls - ok - oog), summed over both pools (Submission and the 30 bps Baseline) and all callbacks (afterInitialize, afterSwap, getName) of the 128 runs; oog likewise",
  "opponent": "VanillaStrategy 30 bps, one singleton amm_sim_rs.run_batch(X, Vanilla, [config], 8) per seed through the kit engine_eval._one",
  "rows_format": "[seed, submission edge to 6 decimals, afterSwap peak gas]; mean_edge above is from the unrounded edges",
  "rows": [
   [
    9700000,
    "509.184206",
    205620
   ],
   [
    9700001,
    "495.144301",
    195837
   ],
   [
    9700002,
    "709.694561",
    191427
   ],
   [
    9700003,
    "530.367411",
    193348
   ],
   [
    9700004,
    "609.111084",
    199261
   ],
   [
    9700005,
    "397.736861",
    200229
   ],
   [
    9700006,
    "573.640630",
    190571
   ],
   [
    9700007,
    "551.077320",
    201855
   ],
   [
    9700008,
    "690.231778",
    198153
   ],
   [
    9700009,
    "546.038452",
    199426
   ],
   [
    9700010,
    "596.502504",
    195489
   ],
   [
    9700011,
    "536.145705",
    202226
   ],
   [
    9700012,
    "484.146659",
    199238
   ],
   [
    9700013,
    "448.934510",
    201427
   ],
   [
    9700014,
    "399.468313",
    192802
   ],
   [
    9700015,
    "629.807456",
    193491
   ],
   [
    9700016,
    "584.076563",
    191018
   ],
   [
    9700017,
    "434.966889",
    193102
   ],
   [
    9700018,
    "566.522589",
    199755
   ],
   [
    9700019,
    "410.564570",
    203823
   ],
   [
    9700020,
    "488.898228",
    189129
   ],
   [
    9700021,
    "409.071721",
    196043
   ],
   [
    9700022,
    "511.600473",
    197340
   ],
   [
    9700023,
    "621.318979",
    196654
   ],
   [
    9700024,
    "505.423068",
    201623
   ],
   [
    9700025,
    "408.381554",
    201443
   ],
   [
    9700026,
    "558.306278",
    197523
   ],
   [
    9700027,
    "560.312480",
    191001
   ],
   [
    9700028,
    "646.899966",
    196386
   ],
   [
    9700029,
    "551.550339",
    193151
   ],
   [
    9700030,
    "542.901768",
    199238
   ],
   [
    9700031,
    "536.345799",
    198192
   ],
   [
    9700032,
    "521.029558",
    200285
   ],
   [
    9700033,
    "590.505865",
    205843
   ],
   [
    9700034,
    "581.565616",
    201583
   ],
   [
    9700035,
    "582.303602",
    197260
   ],
   [
    9700036,
    "436.217226",
    197285
   ],
   [
    9700037,
    "548.826874",
    203663
   ],
   [
    9700038,
    "493.208862",
    200029
   ],
   [
    9700039,
    "511.463286",
    196356
   ],
   [
    9700040,
    "622.108699",
    205526
   ],
   [
    9700041,
    "484.938420",
    204916
   ],
   [
    9700042,
    "434.480365",
    200486
   ],
   [
    9700043,
    "399.153054",
    193532
   ],
   [
    9700044,
    "537.796118",
    196916
   ],
   [
    9700045,
    "548.544679",
    205887
   ],
   [
    9700046,
    "508.414004",
    195318
   ],
   [
    9700047,
    "604.396876",
    193570
   ],
   [
    9700048,
    "376.947822",
    199835
   ],
   [
    9700049,
    "447.543411",
    201942
   ],
   [
    9700050,
    "469.425762",
    201811
   ],
   [
    9700051,
    "439.904855",
    199141
   ],
   [
    9700052,
    "636.252082",
    198122
   ],
   [
    9700053,
    "468.477156",
    198277
   ],
   [
    9700054,
    "360.294163",
    200411
   ],
   [
    9700055,
    "462.865461",
    193722
   ],
   [
    9700056,
    "558.667282",
    191351
   ],
   [
    9700057,
    "446.305380",
    201585
   ],
   [
    9700058,
    "575.392005",
    197705
   ],
   [
    9700059,
    "690.326050",
    193757
   ],
   [
    9700060,
    "570.495818",
    196478
   ],
   [
    9700061,
    "516.003782",
    191658
   ],
   [
    9700062,
    "496.836496",
    203455
   ],
   [
    9700063,
    "516.232706",
    203303
   ],
   [
    9700064,
    "400.683787",
    201788
   ],
   [
    9700065,
    "551.718914",
    192796
   ],
   [
    9700066,
    "487.283627",
    191092
   ],
   [
    9700067,
    "542.008661",
    193988
   ],
   [
    9700068,
    "471.632869",
    197567
   ],
   [
    9700069,
    "458.726467",
    199220
   ],
   [
    9700070,
    "655.275043",
    189309
   ],
   [
    9700071,
    "409.289252",
    199494
   ],
   [
    9700072,
    "516.574169",
    197472
   ],
   [
    9700073,
    "642.256704",
    192809
   ],
   [
    9700074,
    "371.837158",
    200012
   ],
   [
    9700075,
    "368.238906",
    193717
   ],
   [
    9700076,
    "675.548426",
    192982
   ],
   [
    9700077,
    "697.729169",
    203359
   ],
   [
    9700078,
    "538.353079",
    199954
   ],
   [
    9700079,
    "415.023497",
    203867
   ],
   [
    9700080,
    "441.259405",
    189611
   ],
   [
    9700081,
    "637.510951",
    197618
   ],
   [
    9700082,
    "525.037924",
    193753
   ],
   [
    9700083,
    "350.503770",
    191796
   ],
   [
    9700084,
    "505.934012",
    193245
   ],
   [
    9700085,
    "639.037014",
    198368
   ],
   [
    9700086,
    "438.588621",
    200383
   ],
   [
    9700087,
    "483.586688",
    200225
   ],
   [
    9700088,
    "562.827196",
    192411
   ],
   [
    9700089,
    "532.774789",
    203030
   ],
   [
    9700090,
    "471.279506",
    192927
   ],
   [
    9700091,
    "524.455149",
    196215
   ],
   [
    9700092,
    "633.963337",
    202781
   ],
   [
    9700093,
    "685.333920",
    191976
   ],
   [
    9700094,
    "426.204360",
    196450
   ],
   [
    9700095,
    "642.780709",
    195257
   ],
   [
    9700096,
    "560.236066",
    204693
   ],
   [
    9700097,
    "688.781304",
    199334
   ],
   [
    9700098,
    "512.649815",
    191289
   ],
   [
    9700099,
    "528.711669",
    199386
   ],
   [
    9700100,
    "616.150805",
    189611
   ],
   [
    9700101,
    "510.552267",
    199429
   ],
   [
    9700102,
    "599.248556",
    197712
   ],
   [
    9700103,
    "427.821237",
    199286
   ],
   [
    9700104,
    "487.478296",
    204419
   ],
   [
    9700105,
    "451.591571",
    197147
   ],
   [
    9700106,
    "498.525501",
    201486
   ],
   [
    9700107,
    "445.941003",
    199670
   ],
   [
    9700108,
    "532.671256",
    197697
   ],
   [
    9700109,
    "436.563417",
    191768
   ],
   [
    9700110,
    "474.098841",
    200997
   ],
   [
    9700111,
    "557.700574",
    198820
   ],
   [
    9700112,
    "624.639957",
    203629
   ],
   [
    9700113,
    "641.232879",
    189656
   ],
   [
    9700114,
    "366.757644",
    198040
   ],
   [
    9700115,
    "485.888992",
    191511
   ],
   [
    9700116,
    "582.672260",
    193069
   ],
   [
    9700117,
    "370.262027",
    201881
   ],
   [
    9700118,
    "489.996135",
    199105
   ],
   [
    9700119,
    "576.654371",
    194229
   ],
   [
    9700120,
    "538.841137",
    197404
   ],
   [
    9700121,
    "548.058081",
    197322
   ],
   [
    9700122,
    "424.722231",
    193666
   ],
   [
    9700123,
    "421.794243",
    194025
   ],
   [
    9700124,
    "559.066746",
    199996
   ],
   [
    9700125,
    "579.310666",
    200128
   ],
   [
    9700126,
    "453.984182",
    201884
   ],
   [
    9700127,
    "434.692904",
    204276
   ]
  ]
 },
 "replay": [
  {
   "seed": 9700000,
   "callbacks": 11332,
   "fee_mismatches": 0,
   "failed_calls": 0,
   "after_swap_callbacks": 11331,
   "engine_after_swap_calls": 11331,
   "port_edge": 509.18420604524965,
   "engine_edge": 509.18420604524965
  },
  {
   "seed": 9700001,
   "callbacks": 9698,
   "fee_mismatches": 0,
   "failed_calls": 0,
   "after_swap_callbacks": 9697,
   "engine_after_swap_calls": 9697,
   "port_edge": 495.1443011057613,
   "engine_edge": 495.1443011057613
  },
  {
   "seed": 9700002,
   "callbacks": 12859,
   "fee_mismatches": 0,
   "failed_calls": 0,
   "after_swap_callbacks": 12858,
   "engine_after_swap_calls": 12858,
   "port_edge": 709.6945613325859,
   "engine_edge": 709.6945613325859
  },
  {
   "seed": 9700003,
   "callbacks": 9832,
   "fee_mismatches": 0,
   "failed_calls": 0,
   "after_swap_callbacks": 9831,
   "engine_after_swap_calls": 9831,
   "port_edge": 530.3674113842906,
   "engine_edge": 530.3674113842906
  }
 ],
 "replay_note": "callbacks counts every call the port made, afterInitialize included (after_swap_callbacks = callbacks - 1 = the engine Submission afterSwap call count of that seed); a fee mismatch is a callback where either returned fee wad differs between port and contract bytecode; failed_calls are pyrevm calls that raised or returned other than 64 bytes",
 "port_vs_engine_max_abs_diff": 0.0,
 "seconds": {
  "setup": 12.615,
  "compile": 4.114,
  "engine": 17.561,
  "replay": 3.918,
  "detail": {
   "setup": "setup_fast.sh cold, wall: 16 pinned downloads, 135768787 bytes (its own line: fetch 9.528, install 2.268, verify 0.752, total 12.554); cloning the kit and fetching the two artifacts took 2 more",
   "compile": "one SolidityCompiler.compile of QLX5; ev._compile (QLX5 again plus VanillaStrategy) took 4.159",
   "engine": "wall for 128 seeds on 8 forked processes; the single-seed run times sum to 134.552 (mean 1.051, min 0.870, max 1.243 a seed)",
   "replay": "wall for the 4 seeds in 4 processes, port run plus pyrevm replay; a seed: port 2.46 to 2.58 (cold Numba cache), pyrevm replay 0.86 to 1.12",
   "mktables": 0.016,
   "shipped_evmdiff_4_seeds_parallel_wall": 8.778
  }
 },
 "gain_vs_base": 0,
 "se": 0,
 "n": 128,
 "seeds": [
  9700000,
  9700127
 ],
 "peak_gas": 205887,
 "oog": 0,
 "source_sha256": "e183e5bc3fb794b7067703b10a7da9920267aa5f4caa968e16ca101b02338f40",
 "advance": true,
 "recipe": "1. Fetch the kit at 45e7563d1a29ffca9d608fdf60c90bf2624d2d01; bash setup_fast.sh --platform linux-x86_64 --cache test/scratch/cache --scratch test/scratch/rt (no --smoke); then . test/scratch/rt/env.sh and python3 -B. 2. Compile once: import engine_eval as ev; r = ev._compiler().compile(source). Characters from the source, runtime bytes and sha256 from r.deployed_bytecode (ev._compile(path) returns creation code only, which is what the engine and pyrevm deploy). 3. Engine: ev.run_batch refuses any seed outside 9700000..9700511 and raises on the first failed callback. For blocks from 10,400,000 call ev._one(ev._runtime(), codes, seed) yourself: it gives edge, after_swap_peak_gas and gas_stats (oog, revert, other_halt, tx_error, bad_return per role and callback); catch its exception so failures are counted. Compile in the parent, then fork 8 workers (gas counters are per process). 4. Tables: python3 -I mktables.py NEW.sol qlx_tables.json on the corrected source; it decodes only the existing encoding. 5. T/F: T = qlxcore.load_tables(path); qlxcore.run(seed, T, log=log); replay log through pyrevm as evmdiff.py does (837aef47 init, c2babb57 swap, 250,000 gas) and compare both fee wads. The shipped evmdiff.py reads only qlx_tables.json beside qlxcore.py: write the corrected tables there first, and give each worker its own copy of the folder. 6. Take the gas gate from the engine's gas_stats, never from pyrevm.",
 "notes": [
  "QLX5 unchanged, compared with nothing: gain_vs_base 0 and se 0 are by definition, not a measurement. The engine mean over the 128 screening seeds is a level on screening seeds only (sd of the per-seed edges 84.841); it is not a board score.",
  "Source: code_zb64.QLX5 of A/1ef80bfb decoded (base64, zlib) to 47,230 bytes = 47,230 characters, sha256 e183e5bc3fb794b7067703b10a7da9920267aa5f4caa968e16ca101b02338f40 as the brief gives. Compiled size and runtime sha256 equal the expected values and the ones A/1ef80bfb records for its QLX5 arm.",
  "Engine seeds used: 9700000..9700127 once each through engine_eval._one, and 9700000..9700003 once more through amm_sim_rs.run_single inside the shipped evmdiff.py. No other engine seed: setup ran without --smoke, and baselines/engine/validate.py was not run because the kit README says it reruns seeds 9700128, 9700256, 9700383 and 9700511.",
  "Gas: afterSwap peak 205887 on seed 9700045, below the 245,000 limit by 39113; 0 out-of-gas, 0 reverts, halts, transaction errors or bad returns in either pool on 1377819 Submission afterSwap calls.",
  "Tables: mktables.py on the QLX5 source wrote qlx_tables.json with sha256 8c6d33c5c1024bc23593f46123aad1712c0cc8af3f4a118c5875258f9d7b81a6 (equal to the value A/60dc237f lists for the generated file), QPL blob 10,160 bytes, sd levels 0,4,8,12,16,20,26,34. Port bundle files hashed equal to files_sha256 of A/60dc237f (qlxcore.py 701dbfd1..., mktables.py 2b373f0c..., evmdiff.py a7ff69b1..., enginecore_f.py 60af56a7...).",
  "Replay was done twice with the same result: by a driver modelled on evmdiff.py that passes the tables explicitly and counts failed calls (figures in replay), and by the shipped evmdiff.py unchanged on the same four seeds (QLX5 arm): each printed 0 fee mismatches, the same callback counts, 0 of 10,000 step spot prices differing from amm_sim_rs.run_single, and port edge equal to engine edge.",
  "Port against engine: on 9700000..9700003 the port edge equals the unrounded engine edge of engine_eval bit for bit (largest absolute difference 0.0), and the port makes the engine callback count on each seed. Four seeds only; A/60dc237f reports 512 seeds within the 6-decimal rounding of its rows.",
  "What a later item must do differently: (a) engine_eval.run_batch cannot run the after-pipeline blocks from 10,400,000 (it validates seeds against 9700000..9700511) and stops at the first failed callback, so drive engine_eval._one and _config directly and read oog and failures from gas_stats; (b) run_batch is serial, about 1.05 s a seed here, so fork workers after compiling: 8 processes did 128 seeds in 17.6 s; (c) runtime bytes need SolidityCompiler.compile(...).deployed_bytecode, engine_eval._compile keeps only creation code; (d) evmdiff.py takes no table argument and does not catch a failing call (pyrevm raises RuntimeError on a revert or out-of-gas: checked on the compiled QLX5 with an unknown selector and with a 30,000 gas afterInitialize), so regenerate qlx_tables.json from the corrected source beside qlxcore.py, or call qlxcore.run(seed, T, log=...) with tables loaded from an explicit path; (e) mktables.py finds the tables by regular expressions on the existing encoding (bytes constant QPL=hex\"...\", five t=QT(...) lines, the W2L words, the sd-level word), so a corrected contract must keep that text shape or the decode fails; (f) pyrevm result.gas_used peaks over afterSwap were 24,000 to 26,000 below the engine afterSwap peak on the four seeds (afterInitialize agreed at 137,227; cause of the afterSwap gap not established), so gas comes from the engine only; (g) source env.sh first: it points TMPDIR, the Numba cache and SOLCX_BINARY_PATH into the scratch runtime, and the compiler refuses to work without the pinned solc there.",
  "Not done here: no corrected contract, no tuning, no G gate, no engine seed from 10,400,000, nothing submitted. The port run time above includes Numba compilation in a fresh process; A/60dc237f gives 0.946 runs per core-second, so the port is a reference for T and F, not the search tool.",
  "Scripts and raw outputs were kept under test/scratch/ only (a_engine.py, b_replay.py, c_result.py; out/engine.json, out/replay.json, out/evmdiff_<seed>.txt) and are not delivered."
 ]
}
