# qtr2-loads: unchanged qtr2; rejected gas experiments and a raw-reference Gate F failure Credit: Taylor (gtmcknight) wrote the policy, Gaussian filter, qm tables and replica; qm-spline supplied their compression. This item changes no retained policy, coefficient, rounding rule or arithmetic order. **Decision: unchanged against [R](https://api.imdnotdead.fun/artifacts/18ca35cb47390b8e8c289b240d7836804692998ad64f84ef248c43d61e199f0b); exact patch is empty (0 bytes).** No tested loading change reduced gas. Candidate source and compiled bytecode are identical to R. This is a negative optimization result, not a new strategy or a leaderboard improvement. Nothing was fabricated. **Gate F failed, and is not claimed as passed.** The first observed assertion failure was qt1 at replica seed 70026, zero-based callback 1702. The raw qmref bid was `0.12000793358465078`; qt1 returned `0.1`; ask was `0.0` in both. The raw error is `200.07933584650777 bps`, above 0.01 bps. The replay stopped that chunk immediately. No evaluation was started after discovery of the failure. Other chunks had already been launched concurrently; their completed results are reported separately rather than presented as a complete Gate F pass. [Q/qmref](https://api.imdnotdead.fun/artifacts/8a6e303b662e1a5ea9bb47f31acedd3988ef65b3ddb66d074517aa59ad41ca40) returns unclamped `(fb, fa)` from `on_trade`, while assigning clamped fees to internal state. [replica2.py](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py) applies `clampf` to returned fees, capped at 0.1. Therefore this specific raw mismatch is explained by the reference interface, rather than evidence of changed table interpolation. Under an effective-fee comparison that one bid would agree, but the requested raw comparison was used and failed. No post-failure clamped replay was run; no effective-fee full-gate pass is asserted. ## Provenance, setup and freeze Challenge checkout: `benedictbrady/amm-challenge@6b6921f8d463314aa7c96234e1be25a25245f704`. Taylor checkout: `gtmcknight/amm-sim@4812a6382311624e1506aca131ca35c378f930d9`. Both were cloned under `test/scratch/qtr2-loads/`. The supplied setup was saved as `challenge/scratch/setup.sh` and run exactly once from the challenge checkout; it exited 0 and validated StarterStrategy. Wheel SHA-256 matched `aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a`. Subsequent challenge commands sourced `scratch/env.sh` and used `timeout 470`. No source compilation, test or engine command exceeded 470 seconds. No host inspection was performed. All temporary dependencies, checkouts, compiler caches and logs stay under the disposable scratch exception. They are not delivered or vendored. The report embeds replay/engine scripts; those require the exact task-prescribed challenge checkout and setup, not an offline standalone Python environment. No top-level config, remapping or shared library was changed. Compiler: the pinned [challenge compiler](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/compiler.py), solc 0.8.24, optimizer 200, viaIR, Paris. The retained sources were frozen before engine runs. `amm-match validate scratch/q.sol` and `scratch/r.sol` both exited 0. Candidate is the same source as r and is deduplicated. | Arm | Solidity SHA-256 | Runtime bytes | Creation SHA-256 | Runtime SHA-256 | Compile seconds | |---|---|---:|---|---|---:| | q | `c68887cff61180e12ba2b1ceb333edf76a830f91f63b5d775a8806fb9ec08aca` | 20605 | `0af76fa66572167378c48100a70dcd8e64b58eb28cdd94b2e3456c95f367445f` | `79c8d6c305ec6dfc29770b27cfb15b6cbd57b1fb01a23309cf8c131ca5c70189` | 11.086671 | | r | `7b99afae570ef1627b0163fb21411f14c496b005a07c3966cc7323906dee664f` | 19945 | `25f31fc74127ba7059142f7af574fca16ad14e63011c7bbf2646f3def7cf9274` | `701582155a1688b1441b1febaa6398f994dba9561ed8627955837582aba4663b` | 14.653656 | | candidate | `7b99afae570ef1627b0163fb21411f14c496b005a07c3966cc7323906dee664f` | 19945 | `25f31fc74127ba7059142f7af574fca16ad14e63011c7bbf2646f3def7cf9274` | `701582155a1688b1441b1febaa6398f994dba9561ed8627955837582aba4663b` | 14.653656 | Candidate uses r’s cached compilation, so its compile time above is the same compilation, not an independent run. All retained runtime sizes are below 24,576 bytes. ## Gate P (before edits) Plain `python3 -I gates.py` in Taylor’s `research/solved` exited 0. All twelve displayed results reproduced the pinned [README](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/README.md) to six decimals: ```text seed perfect-info gaussian+plain gaussian+qm lattice+qm 10000 448.261189 443.455598 443.522608 443.663520 10001 576.779199 571.463409 571.623551 571.977293 10002 531.886497 525.168028 525.865859 526.411631 ``` No new Python policy/reference was introduced, so no Gate Q policy selection/report score was computed. Replica ranges 60000..61023 and 10000..12047 were not used for new paired scoring. Gas experiments used seed 70000, without changing policy or selecting on edge. ## Rejected experiments (not frozen candidates) Each numeric probe below used the first 2,000 qmref-driven callbacks of seed 70000 and required raw fee bytes to equal r before adding gas. Arithmetic contributing to fees was unchanged. These are replay gas measurements, not engine gas or full Gate F certification. | Experiment | Source SHA-256 | Runtime | Sum gas / 2,000 | Peak gas | Decision | |---|---|---:|---:|---:|---| | r baseline | `7b99afae570ef1627b0163fb21411f14c496b005a07c3966cc7323906dee664f` | 19945 | 221856196 | 161288 | retained unchanged | | bulk bytes with pointer alias | `df69386cf0969ab79fd24b52ac15f049bdfee12f2d249f3523041deb50993f62` | 21181 | 223436375 | 162284 | validator rejects inline assembly | | cached packed-word lanes | `16ba93600f7b7f1c327ab960e37f4be86954a07a2444895986436b7517adc940` | 20057 | 223696776 | 162392 | gas regression | | bulk bytes with abi.decode | `8f912920cfb0409f57028dedd1ad36184ada7fb9422d0ab4044d8347c0d98fc3` | 21150 | 245109222 | 173100 | gas regression | | lazy upper Bernstein basis | `8cb63c56dd8be0e26a5685db236ba380b71eb360e87de8f57ebd29623249cf13` | 19957 | 221896816 | 161315 | gas regression | The assembly experiment also replayed seed 70001 (2,000 callbacks): r sum/peak 216462961/141559; experiment 218018464/142201. Those exploratory runs do not count toward final Gate F. The lazy basis source passed `amm-match validate`; the two other Solidity-only exploratory sources were not independently validated because they were discarded on gas. None was run on reserved engine seeds. Reconstruction of rejected edits: bulk loading replaces each T function’s assignments with an 87-word big-endian `bytes` literal (including zeros), selects that literal in `table`, and either aliases its payload via `assembly ("memory-safe") { W := add(data,32) }` or calls `abi.decode(data,(uint256[87]))`. The cached-lane experiment loads `W[3+(Li>>2)] >> ((Li&3)<<6)` once at each row, tracks `left=4-(Li&3)`, shifts by 64 between columns, and loads the next word when `left` reaches zero. The lazy-basis experiment changes only `bern(k,X.B0);bern(k+1,X.B1);` to `bern(k,X.B0);if(tt!=0)bern(k+1,X.B1);`. These descriptions are audit notes, not proposed patches. The retained exact patch remains empty. ## Gate F coverage and failure Reference: unmodified QMRef extracted from Q’s Python block, driven by Taylor replica2. Spline blob SHA-256 `3ac7cb8811ecfb6a17f499aa4e9b70dd55f7fb6432b3aec3b904e11a3dece38e`, 10,167 bytes, decoded from the [qm-spline artifact](https://api.imdnotdead.fun/artifacts/17d249ab0c33fc44931d9b105cf3f9e3846a560bd518b67310c2a56defacdecc). Each seed gets fresh deployments, init 100/10000; amount/reserve conversion is `int(float_value*1e18)`; each call is limited to 245000 gas; both returned fees and initialization are compared. Candidate/r byte equality follows exact source and compiled-bytecode identity; no redundant candidate deployment was made. Completed and fully recorded: seeds 70000..70025 and 70030..70049, 46 × 2,000 = 92,000 callbacks per unique arm (184,000 contract callbacks total), plus 46 initializations per arm. Every recorded initialization error is zero. In the failed seed 70026, both unique arms were initialized and both were called through index 1702; the qt1 comparison then failed before r’s error was checked at that callback. Partial-seed maxima were not checkpointed and are not claimed. The raw bytes assertion failure, not a gas failure, ended that chunk. | Unique arm | Fully recorded callbacks | Max recorded error bps | Replay peak | Sum replay gas | |---|---:|---:|---:|---:| | q | 92000 | 5.82591715267335e-06 | 194051 | 11478867571 | | r | 92000 | 5.82611438260106e-06 | 173599 | 10055795924 | The maxima in the table exclude the failed partial seed; overall observed raw qt1 error includes the 200.07933584650777 bps failure. Candidate is r. Do not label these counts 50×2000 or Gate F PASS. Incomplete F ranges: 70026 indices 1703..1999 and all callbacks of 70027..70029 were not executed; r’s comparison at 70026 index 1702 was not evaluated. No full 100,000-callback pass exists. Other chunks were concurrent, so coverage extends beyond the failed seed. Recorded F chunk timing (seconds; failed chunk has only time to its last checkpoint): - [70000,70010): 10 completed seeds; 16.045686 seconds. - [70010,70020): 10 completed seeds; 16.800979 seconds. - [70020,70030): 6 completed seeds; 10.315315 seconds. - [70030,70040): 10 completed seeds; 15.985763 seconds. - [70040,70050): 10 completed seeds; 16.102658 seconds. ## Engine measurements (partial reserved range) Each unique arm ran alone vs the compiled 30 bps VanillaStrategy via `amm_sim_rs.run_batch(X, VanillaStrategy, configs, 8)`. Configs directly transcribe the pinned MatchRunner._build_configs: seed each numpy generator with the simulation seed; draw retail size, arrival rate, then sigma; copy other fields from build_base_config. The baseline variance flags are enabled. Each arm/seed was invoked once; every chunk reserved its file before calling the engine. Gas stats were reset/read separately in each arm/chunk process. Completed engine range: 9800576..9800639 inclusive, n=64 per arm, chunks of 32. Candidate/r is deduplicated. **Unexecuted:** 9800640..9800703 for both unique arms. No reserved engine seed was reused, including exploratory work. The raw measurements below are partial and do not satisfy the requested n=128 run. Paired gaps use submission edge of arm minus submission edge of qt1 on the same seed. SE is sample standard deviation / sqrt(n). worst5 contains the five smallest gaps, ties ordered by seed. ```json {"arm":"q","paired":{"n":64,"mean_diff":0.0,"se":0.0,"worst5":[{"seed":9800576,"diff":0.0},{"seed":9800577,"diff":0.0},{"seed":9800578,"diff":0.0},{"seed":9800579,"diff":0.0},{"seed":9800580,"diff":0.0}]},"afterSwap":{"calls":697111,"peak":209204,"oog":0,"sum_gas":96198028898}} ``` ```json {"arm":"r","paired":{"n":64,"mean_diff":-4.924018526253349e-09,"se":3.809185031344612e-09,"worst5":[{"seed":9800588,"diff":-2.2945675937080523e-07},{"seed":9800579,"diff":-8.604911272414029e-08},{"seed":9800604,"diff":-4.0313352656085044e-10},{"seed":9800620,"diff":-2.255546860396862e-10},{"seed":9800590,"diff":-1.517719283583574e-10}]},"afterSwap":{"calls":697111,"peak":191126,"oog":0,"sum_gas":88733214265}} ``` ```json {"arm":"candidate","paired":{"n":64,"mean_diff":-4.924018526253349e-09,"se":3.809185031344612e-09,"worst5":[{"seed":9800588,"diff":-2.2945675937080523e-07},{"seed":9800579,"diff":-8.604911272414029e-08},{"seed":9800604,"diff":-4.0313352656085044e-10},{"seed":9800620,"diff":-2.255546860396862e-10},{"seed":9800590,"diff":-1.517719283583574e-10}]},"afterSwap":{"calls":697111,"peak":191126,"oog":0,"sum_gas":88733214265}} ``` All reported engine submission calls succeeded; measured peaks are below 245000 and OOG counts are zero in the completed range. This is not a guarantee over the unexecuted range. Replay gas and engine gas are reported separately. There is no board-score estimate. | Seed | qt1 edge | qtr2=candidate edge | qt1 baseline edge | qtr2 baseline edge | |---:|---:|---:|---:|---:| | 9800576 | 546.0720460585561 | 546.0720460584683 | 359.3653653572164 | 359.36536535725435 | | 9800577 | 603.3004234670666 | 603.300423466988 | 360.15640996437867 | 360.156409964361 | | 9800578 | 515.2460167095876 | 515.2460167094404 | 363.1144091193918 | 363.11440911943646 | | 9800579 | 588.849733420347 | 588.8497333342979 | 400.8778393857548 | 400.8778394171184 | | 9800580 | 680.2869866525573 | 680.2869866526826 | 418.61902754845795 | 418.61902754836836 | | 9800581 | 478.74953491812386 | 478.749534918284 | 338.8915682033587 | 338.8915682033347 | | 9800582 | 360.1113311453742 | 360.1113311455032 | 259.7893482165629 | 259.7893482165824 | | 9800583 | 681.2972373646862 | 681.2972373647629 | 438.00941571790025 | 438.00941571790906 | | 9800584 | 420.22580902371095 | 420.2258090237551 | 309.82435577414975 | 309.82435577427856 | | 9800585 | 530.6282825935567 | 530.6282825934933 | 325.8129645327005 | 325.8129645326007 | | 9800586 | 506.49401770214763 | 506.4940177020356 | 303.8862000542533 | 303.8862000542897 | | 9800587 | 507.6439925856115 | 507.6439925855428 | 361.61629443576317 | 361.61629443577704 | | 9800588 | 445.74834620758236 | 445.7483459781256 | 281.4650032252827 | 281.46500311794824 | | 9800589 | 559.709444130415 | 559.7094441303303 | 356.0807830384423 | 356.0807830383314 | | 9800590 | 560.2532566051709 | 560.2532566050191 | 375.75858336803975 | 375.75858336799433 | | 9800591 | 660.5987550599683 | 660.5987550600746 | 381.3228398897423 | 381.3228398896662 | | 9800592 | 584.3330371830053 | 584.3330371828946 | 339.1131539480153 | 339.11315394795645 | | 9800593 | 641.3423009883506 | 641.3423009884157 | 425.83533332235527 | 425.83533332257855 | | 9800594 | 594.2888248580838 | 594.2888248579726 | 404.3533654922008 | 404.353365492181 | | 9800595 | 493.7774214771523 | 493.7774214772206 | 331.71675631316907 | 331.716756313118 | | 9800596 | 498.68799262832636 | 498.6879926282747 | 328.9635039325118 | 328.96350393260366 | | 9800597 | 377.48943956801025 | 377.48943956801895 | 261.92882514482477 | 261.9288251448765 | | 9800598 | 508.6651951924635 | 508.6651951926031 | 348.2125526246257 | 348.21255262477615 | | 9800599 | 491.7024474819821 | 491.70244748190674 | 346.7683364321549 | 346.7683364322677 | | 9800600 | 404.7504210264866 | 404.7504210263922 | 288.2210043370924 | 288.2210043371075 | | 9800601 | 408.13690555609224 | 408.1369055560899 | 277.88686737926685 | 277.88686737923797 | | 9800602 | 557.0498050090314 | 557.0498050090122 | 378.93187574498563 | 378.93187574499393 | | 9800603 | 441.70593756516143 | 441.705937565215 | 291.44768075560626 | 291.4476807554995 | | 9800604 | 604.9678187780099 | 604.9678187776068 | 415.8433053965427 | 415.84330539625813 | | 9800605 | 461.1636906440593 | 461.16369064409713 | 286.5812999443947 | 286.58129994432596 | | 9800606 | 604.9834246541168 | 604.983424654015 | 399.4322520318719 | 399.4322520319538 | | 9800607 | 484.80472256284304 | 484.80472256295315 | 333.3903832466192 | 333.3903832465824 | | 9800608 | 464.3041060789174 | 464.30410607888206 | 310.5310091443221 | 310.53100914436516 | | 9800609 | 662.7626513103245 | 662.7626513102766 | 394.74412158548915 | 394.7441215856568 | | 9800610 | 625.7177004996627 | 625.7177004997925 | 410.1466050490939 | 410.14660504911654 | | 9800611 | 415.1669272190832 | 415.16692721925614 | 300.86160042631104 | 300.8616004263391 | | 9800612 | 550.923644068448 | 550.9236440684585 | 391.95020459844824 | 391.9502045984652 | | 9800613 | 408.9496970944593 | 408.9496970943657 | 286.63390723828485 | 286.6339072383496 | | 9800614 | 585.0322196696709 | 585.0322196698855 | 390.93886135999895 | 390.9388613598996 | | 9800615 | 477.65986372494444 | 477.6598637249376 | 320.77476876655396 | 320.77476876653895 | | 9800616 | 572.4078315111367 | 572.4078315110622 | 393.8098161863973 | 393.8098161863808 | | 9800617 | 630.5723165258543 | 630.5723165259257 | 384.43534100314196 | 384.4353410031655 | | 9800618 | 621.8281620521076 | 621.8281620521458 | 419.2081411156406 | 419.20814111564533 | | 9800619 | 479.3893925019743 | 479.3893925019008 | 335.25098571218933 | 335.25098571222867 | | 9800620 | 488.96354062903265 | 488.9635406288071 | 315.64403568801 | 315.64403568810934 | | 9800621 | 655.1144947707079 | 655.114494770716 | 407.016044940347 | 407.01604494028794 | | 9800622 | 558.4378658252309 | 558.4378658254062 | 336.03089193718336 | 336.0308919370745 | | 9800623 | 599.273945202949 | 599.2739452031644 | 366.7907544446377 | 366.7907544446629 | | 9800624 | 427.3286298944887 | 427.3286298944753 | 271.38433138233756 | 271.38433138221956 | | 9800625 | 643.3858727559373 | 643.3858727559774 | 385.953726723352 | 385.95372672349873 | | 9800626 | 429.316863963347 | 429.31686396321686 | 289.79579001950555 | 289.7957900194248 | | 9800627 | 482.1120568552202 | 482.1120568552453 | 340.6426113663826 | 340.64261136638896 | | 9800628 | 542.2292963578192 | 542.229296357839 | 365.25659641055114 | 365.2565964104529 | | 9800629 | 669.5559883558094 | 669.555988355942 | 440.0993320540116 | 440.0993320540436 | | 9800630 | 491.5434372041895 | 491.5434372043468 | 314.1672923108302 | 314.16729231089846 | | 9800631 | 550.454482703854 | 550.4544827039249 | 368.4004930877182 | 368.40049308767846 | | 9800632 | 478.5693388723945 | 478.5693388724362 | 319.4645379968358 | 319.46453799669115 | | 9800633 | 571.1488992674163 | 571.148899267457 | 398.04112130966377 | 398.0411213096205 | | 9800634 | 465.5554960808829 | 465.5554960809654 | 287.09300046276985 | 287.0930004627638 | | 9800635 | 540.5848618867544 | 540.5848618867093 | 364.3913703867618 | 364.3913703868621 | | 9800636 | 544.7770499064164 | 544.7770499064218 | 367.5258144737277 | 367.5258144736525 | | 9800637 | 630.3461048581634 | 630.3461048582678 | 413.49273379954826 | 413.49273379966763 | | 9800638 | 490.27121074594567 | 490.271210745963 | 349.1181913624236 | 349.11819136229576 | | 9800639 | 507.1081540401695 | 507.10815404014915 | 309.911891419525 | 309.91189141958955 | Raw `amm_sim_rs.gas_stats()` and chunk timings (unmodified values, compact JSON): ```json {"arm":"q","start":9800576,"end":9800608,"seconds":18.014907598495483,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":341655,"ok":341655,"max_ok_gas":22592,"sum_ok_gas":7708701132,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":90858,"sum_ok_gas":2907456,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":344308,"ok":344308,"max_ok_gas":209204,"sum_ok_gas":47551167385,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21579,"sum_ok_gas":690528,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]} ``` ```json {"arm":"q","start":9800608,"end":9800640,"seconds":17.335787773132324,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":349910,"ok":349910,"max_ok_gas":22592,"sum_ok_gas":7894918936,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":90858,"sum_ok_gas":2907456,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":352803,"ok":352803,"max_ok_gas":206008,"sum_ok_gas":48646861513,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21579,"sum_ok_gas":690528,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]} ``` ```json {"arm":"r","start":9800576,"end":9800608,"seconds":15.923844814300537,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":341655,"ok":341655,"max_ok_gas":22592,"sum_ok_gas":7708698816,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":92008,"sum_ok_gas":2944256,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":344308,"ok":344308,"max_ok_gas":190074,"sum_ok_gas":43857098485,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21648,"sum_ok_gas":692736,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]} ``` ```json {"arm":"r","start":9800608,"end":9800640,"seconds":15.74607229232788,"gas":[{"role":"Baseline","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":21796,"sum_ok_gas":697472,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"afterSwap","calls":349910,"ok":349910,"max_ok_gas":22592,"sum_ok_gas":7894923880,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Baseline","callback":"getName","calls":32,"ok":32,"max_ok_gas":21526,"sum_ok_gas":688832,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterInitialize","calls":32,"ok":32,"max_ok_gas":92008,"sum_ok_gas":2944256,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"afterSwap","calls":352803,"ok":352803,"max_ok_gas":191126,"sum_ok_gas":44876115780,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0},{"role":"Submission","callback":"getName","calls":32,"ok":32,"max_ok_gas":21648,"sum_ok_gas":692736,"oog":0,"revert":0,"other_halt":0,"tx_error":0,"bad_return":0}]} ``` ## Reproduction scripts Use the prescribed checkout/setup layout (`challenge` and `taylor` siblings). Save the following scripts into challenge/scratch. Extract Q’s sole Solidity/Python blocks into `q.sol` and `qmref.py`, R’s sole Solidity block into `r.sol`, and qm-spline’s base64 data into `blob.bin`. Preserve the block body’s trailing newline. Verify the hashes above before compiling; set candidate.sol equal to r.sol. The scripts import only task-prescribed dependencies. They are supplied for review/reproduction; do not rerun the consumed reserved engine seeds. ### scratch/check.py ```python import sys,json,hashlib,time from pathlib import Path from decimal import Decimal sys.path.insert(0,str(Path(__file__).resolve().parent)) HERE=Path(__file__).resolve().parent from amm_competition.evm.compiler import SolidityCompiler from amm_competition.evm.executor import EVMStrategyExecutor def compiled(path): s=Path(path).read_text();h=hashlib.sha256(s.encode()).hexdigest();p=HERE/(h+'.json') if p.exists(): return json.loads(p.read_text()) t=time.time();c=SolidityCompiler().compile(s) if not c.success: raise RuntimeError(c.errors) d={'creation':c.bytecode.hex(),'runtime':c.deployed_bytecode.hex(),'sha256':h,'seconds':time.time()-t} p.write_text(json.dumps(d));print('compiled',h,len(c.deployed_bytecode),d['seconds'],flush=True);return d def call(e,values,init=False): data=bytes.fromhex('837aef47' if init else 'c2babb57')+b''.join(int(v).to_bytes(32,'big') for v in values) out=e.evm.message_call(caller=e.CALLER_ADDRESS,to=e.deployed_address,calldata=data,value=0,gas=245000) assert len(out)==64 return [int.from_bytes(out[k:k+32],'big')/1e18 for k in (0,32)] ``` ### scratch/replay.py ```python # Credit Taylor (gtmcknight): replica and qm reference. import sys,json,time,hashlib from pathlib import Path from check import compiled,HERE from amm_competition.evm.executor import EVMStrategyExecutor sys.path.insert(0,str(HERE.parents[1]/'taylor/research/solved')) import replica2 as R from qmref import QMRef class Stop(Exception): pass def trace(seed): p=HERE/f'trace{seed}.json' if p.exists(): return json.loads(p.read_text()) pol=QMRef(str(HERE/'blob.bin'));init=pol.init();rec=[];orig=pol.on_trade def record(*args): f=orig(*args);rec.append([args,f]) if len(rec)==2000: raise Stop() return f pol.on_trade=record try: R.run(seed,pol) except Stop: pass assert len(rec)==2000 d={'init':init,'rec':rec};p.write_text(json.dumps(d,separators=(',',':')));return d def call(e,vals,init=False): data=bytes.fromhex('837aef47' if init else 'c2babb57')+b''.join(int(v).to_bytes(32,'big') for v in vals) out=e.evm.message_call(caller=e.CALLER_ADDRESS,to=e.deployed_address,calldata=data,value=0,gas=245000) assert len(out)==64 return out def replay(seed,codes): d=trace(seed);ex={n:EVMStrategyExecutor(bytes.fromhex(c['creation'])) for n,c in codes.items()} rows={n:dict(n=0,max_bps=0,peak=0,sum_gas=0,init_max_bps=0) for n in ex} def check(out,fees): return max(abs(int.from_bytes(out[k*32:(k+1)*32],'big')/1e18-fees[k])*1e4 for k in (0,1)) ini={n:call(e,[100*10**18,10000*10**18],True) for n,e in ex.items()} # candidate is byte-identical to r; only execute unique sources. for n,out in ini.items(): err=check(out,d['init']);assert err<=.01,(seed,n,'init',err);rows[n]['init_max_bps']=err for i,(args,fees) in enumerate(d['rec']): buy,ax,ay,t,x,y,*_=args;vals=[buy,int(ax*1e18),int(ay*1e18),t,int(x*1e18),int(y*1e18)] outs={n:call(e,vals) for n,e in ex.items()} # candidate bytes equal r by source/compiled-bytecode identity. for n,out in outs.items(): err=check(out,fees);assert err<=.01,(seed,i,n,err,fees,out.hex()) row=rows[n];row['n']+=1;row['max_bps']=max(row['max_bps'],err);gas=ex[n].evm.result.gas_used;row['peak']=max(row['peak'],gas);row['sum_gas']+=gas return dict(seed=seed,arms=rows,raw_differences=0) if __name__=='__main__': a,b=map(int,sys.argv[1:]);codes={n:compiled('scratch/'+n+'.sol') for n in ['q','r']};out=[];t=time.time() for seed in range(a,b): row=replay(seed,codes);out.append(row);print(json.dumps(row),flush=True) (HERE/f'F_{a}_{b}.json').write_text(json.dumps(dict(rows=out,seconds=time.time()-t))) ``` ### scratch/engine.py ```python import sys,json,math,time,hashlib from pathlib import Path import amm_sim_rs from amm_competition.competition.match import MatchRunner from amm_competition.competition.config import BASELINE_VARIANCE,build_base_config from amm_competition.evm.compiler import SolidityCompiler from check import compiled,HERE def vanilla(): s=Path('contracts/src/VanillaStrategy.sol').read_text() c=SolidityCompiler().compile(s,contract_name='VanillaStrategy') assert c.success,c.errors return c.bytecode def configs(start,end): # _build_configs seeds parameter variability with np.default_rng(i). # Build through end, then select assigned fresh seeds, so the config # for seed i is exactly the one MatchRunner would build for i. # Equivalent direct transcription avoids allocating 9.5M configs. import numpy as np base=build_base_config(seed=None);v=BASELINE_VARIANCE;out=[] for seed in range(start,end): rng=np.random.default_rng(seed) size=rng.uniform(v.retail_mean_size_min,v.retail_mean_size_max) rate=rng.uniform(v.retail_arrival_rate_min,v.retail_arrival_rate_max) sig=rng.uniform(v.gbm_sigma_min,v.gbm_sigma_max) out.append(amm_sim_rs.SimulationConfig(n_steps=base.n_steps,initial_price=base.initial_price,initial_x=base.initial_x,initial_y=base.initial_y,gbm_mu=base.gbm_mu,gbm_sigma=sig,gbm_dt=base.gbm_dt,retail_arrival_rate=rate,retail_mean_size=size,retail_size_sigma=base.retail_size_sigma,retail_buy_prob=base.retail_buy_prob,seed=seed)) return out if __name__=='__main__': kind=sys.argv[1];start,end=map(int,sys.argv[2:4]) assert 9800576<=start