# Taylor's solved AMM policy in Solidity: Gaussian filter + qm tables, confirmed on the real engine Goal: port Taylor's (gtmcknight) solved policy from `github.com/gtmcknight/amm-sim` at commit `4812a6382311624e1506aca131ca35c378f930d9`, folder `research/solved`, into a `contract Strategy is AMMStrategyBase` for paradigm.xyz/puzzles/amm that beats our file t03 on the real engine, within 24,576 runtime bytes, an afterSwap peak of at most 245,000 gas and zero OutOfGas, with the tables compressed and gates P, Q and F passed. All policy credit is Taylor's (gtmcknight): the dynamic program, the Gaussian filter (`real.py`), the plain and qm tables and the replica. Every contract below says so in its header. No trunk repository was created for this goal (`goal.json` reports `trunk: null`): every piece of code lives inside the result artifacts, which are public at `https://api.imd.fun/artifacts/`. The artifact ids used below are listed in section 9. ## 1. The best contract: qt1 (`TaylorGaussianQMSpline`) qt1 is Taylor's Gaussian filter (port-3's filter, in trim-2's three-slot shell) quoting from Taylor's qm tables, compressed by qm-spline into 10,167 bytes of cubic B-spline coefficients and decoded at runtime. It is the contract the requester submitted after this goal's round 5: it sits on the board at 524.9403, 8th place (requester note 8), up from trim-1's 524.1189 and port-3's 523.3369, with IB at 522.00. The board gain over trim-1 (+0.82) matches the local measurement. | Property | Value | Source | |---|---|---| | Source SHA-256 | `c68887cff61180e12ba2b1ceb333edf76a830f91f63b5d775a8806fb9ec08aca` (42,990 bytes, the Solidity block in section 1.2, recomputed here) | r5-qm-t2/qt1 | | Deployed runtime | 20,605 bytes (limit 24,576); solc 0.8.24, optimizer 200, viaIR, Paris | qt1 | | `amm-match validate` | pass, `Strategy 'TaylorGaussianQMSpline' validated successfully!` | qt1 | | Engine afterSwap peak | 208,775 gas (chunk peaks 201,777 / 206,279 / 208,161 / 208,775) | qt1, seeds 9535000..9535127 | | Engine OutOfGas | 0 in 1,402,238 afterSwap calls; 0 reverts, other halts, tx errors, bad returns | qt1 | | afterInitialize | 90,858 gas, 128 calls, 0 failures | qt1 | | pyrevm replay peak / mean (gate F replay, 245,000 gas per call) | 194,051 / 124,777 | qt1 | | Gate F | max 5.826e-06 bps, mean 1.689e-07 bps on 50 x 2,000 callbacks; init diff 0 | qt1 | | Gate Q | tables shipped unchanged from qm-spline: loss 0.0632, se 0.0072, n=2,048 (full qm minus decoded, report seeds) | qm-spline, rerun by qm-1 | | Gate P | gates.py reproduced before any change (qm column 443.522608 / 571.623551 / 525.865859) | qt1 | ### 1.1 Paired gain on fresh engine seeds Every engine figure in this report comes from the pinned protocol: amm-challenge at `6b6921f8d463314aa7c96234e1be25a25245f704`, each strategy alone against the 30 bps VanillaStrategy through `amm_sim_rs.run_batch(X, VanillaStrategy, configs, 8)`, configs per `MatchRunner._build_configs` with `default_rng(seed)` drawing size, rate and sigma, score = `edges["submission"]`, differences paired by seed, se = sample sd / sqrt(n). Seeds were taken fresh from 9500000 upward and never reused (registry in section 8). qt1's own run (seeds 9535000..9535127, n=128): | Pair | n | mean_diff | se | wins | worst5 (seed, diff) | |---|---:|---:|---:|---:|---| | qt1 minus t03 | 128 | **+2.160** | 0.110 | 125/128 | (9535096, -0.879), (9535060, -0.291), (9535073, -0.160), (9535100, +0.004), (9535078, +0.239) | | qt1 minus trim-2 | 128 | **+0.819** | 0.055 | 117/128 | (9535096, -0.683), (9535125, -0.500), (9535054, -0.366), (9535055, -0.289), (9535052, -0.202) | | trim-2 minus t03 (same seeds) | 128 | +1.341 | 0.117 | 111/128 | (9535060, -1.637), (9535064, -1.478), (9535016, -1.331), (9535057, -0.886), (9535100, -0.777) | IB was not run on qt1's block. By offset through t03 (t03 minus IB is +0.78 se 0.02 on the 1,792 qm confirmation seeds and +0.745 se 0.084 on the r1-baseline block), qt1 is about +2.9 over IB. The policy qt1 implements (Gaussian filter + qm-spline tables, fees within 5.83e-6 bps of the same Python reference) was confirmed on 1,792 fresh seeds through qm-2, a sibling contract with the same tables and the same reference (section 2). Pooled over its seven handed blocks (seeds 9613312..9613823 and 9614080..9615359, every seed once per arm, recomputed here from the per-seed CSVs): | qm policy (qm-2) minus | n | mean_diff | se | wins | worst5 (seed, diff) | best5 (seed, diff) | |---|---:|---:|---:|---:|---|---| | trim-1 (board 524.1189) | 1,792 | **+0.8755** | 0.0158 | 1,625 | (9613816, -1.250), (9614759, -1.108), (9613349, -1.024), (9615035, -1.009), (9614347, -0.923) | (9613711, +4.221), (9613335, +3.260), (9614302, +2.784), (9614411, +2.766), (9614490, +2.703) | | t03 | 1,792 | **+2.2724** | 0.0304 | 1,751 | (9613399, -2.487), (9613493, -2.407), (9613540, -2.042), (9614831, -1.594), (9614809, -1.330) | (9614955, +7.098), (9613468, +7.091), (9614327, +6.752), (9614199, +6.542), (9615278, +6.302) | | IB | 1,792 | **+3.0539** | 0.0340 | 1,785 | (9613493, -1.605), (9613399, -0.795), (9614598, -0.197), (9613672, -0.187), (9613540, -0.125) | (9614349, +14.934), (9614140, +13.979), (9614199, +9.013), (9614203, +8.353), (9614327, +8.240) | Two things to keep straight about that transfer. First, qm-2 and qt1 were never compared callback by callback: both match the same Python reference (filter + `real.py` qm rule over the decoded qm-spline tables) to a maximum of 5.826e-06 bps, qm-2 in trim-1's shell and qt1 in trim-2's, so the two contracts differ in fixed-point rounding at or below that level, not in policy. Second, qm-2 ran out of gas on 33 of 19.5 million callbacks in those blocks (section 2.2); an OutOfGas callback leaves the previous fees in force for one step, which can only have cost qm-2 score, so the pooled figures are a slight understatement of what a gas-safe contract with the same fees scores. The eighth block (qa3, seeds 9613824..9614079) was still running when this write-up was made, so n is 1,792, not 2,048. Against the requester's successive bars: qt1 clears ">= +0.3 over t03", ">= +0.3 over port-3" and ">= +0.3 over trim-1" on 1,792 seeds with se 0.016. Nothing in this goal clears the last bar set in note 8 (">= +0.3 over qt1"): the only candidates measured after qt1 are the same policy in other shells (section 3), which are its equals by construction. ### 1.2 Complete Strategy.sol of qt1 Extract exactly the block below, including its final newline; its SHA-256 is `c68887cff61180e12ba2b1ceb333edf76a830f91f63b5d775a8806fb9ec08aca`. It imports only the two base files of the pinned challenge and needs no payload, library, assembly or external call at runtime. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {AMMStrategyBase} from "./AMMStrategyBase.sol"; import {TradeInfo} from "./IAMMStrategy.sol"; // Solved AMM policy by Taylor (gtmcknight), amm-sim 4812a638 research/solved: Gaussian filter + qm tables (qm_k1e-5.json), // fee rule of real.py's qm variant (sd level, phase, synced flag). All credit for the policy, filter and tables: Taylor. // Tables compressed by qm-spline (cubic B-splines, QMS1 blob sha256 3ac7cb88...); filter, 3-slot state, math and fee conversion // from trim-2 (port-3's filter); synced flag stored in bit 255 of slot 2. // Taylor source: https://github.com/gtmcknight/amm-sim/tree/4812a6382311624e1506aca131ca35c378f930d9/research/solved contract Strategy is AMMStrategyBase { int256 constant U=1e18; int256 constant LN2=693147180559945309; uint256 constant M64=0xffffffffffffffff; // slots[0] = m (int128) | v (int128)<<128 ; slots[1] = sp (int128) | r (int128)<<128 ; slots[2] = fb | fa<<64 | t<<128 | cnt<<192 function getName() external pure override returns(string memory) { unchecked {return "TaylorGaussianQMSpline";} } function mul(int256 a,int256 b) internal pure returns(int256){ unchecked {return a*b/U;} } function divi(int256 a,int256 b) internal pure returns(int256){ unchecked {return a*U/b;} } function ab(int256 x) internal pure returns(int256){ unchecked {return x<0?-x:x;} } function clip(int256 x,int256 a,int256 b) internal pure returns(int256){ unchecked {return xb?b:x);} } function ln(int256 x) internal pure returns(int256 z){ unchecked { require(x>0); int256 k; while(x< U){x*=2;k--;} while(x>=2*U){x/=2;k++;} int256 y=divi(x-U,x+U); int256 y2=mul(y,y); int256 q=y; z=y; for(int256 n=3;n<=29;n+=2){q=mul(q,y2);z+=q/n;} return 2*z+k*LN2; } } function exp(int256 x) internal pure returns(int256){ unchecked { if(x< -42*U)return 0; require(x<60*U); int256 k=(x>=0?x+LN2/2:x-LN2/2)/LN2; int256 r=x-k*LN2; int256 r2=mul(r,r); int256 even=665280*U+mul(r2,75600*U+mul(r2,840*U+r2)); int256 odd=mul(r,332640*U+mul(r2,10080*U+mul(r2,42*U))); int256 s=divi(even+odd,even-odd); return k>=0?s*int256(uint256(1)<>128>0){z>>=128;r<<=64;} if(z>>64>0){z>>=64;r<<=32;} if(z>>32>0){z>>=32;r<<=16;} if(z>>16>0){z>>=16;r<<=8;} if(z>>8>0){z>>=8;r<<=4;} if(z>>4>0){z>>=4;r<<=2;} if(z>>2>0){r<<=1;} for(uint256 i=0;i<7;i++)r=(r+n/r)/2; return int256(r10*U)return 0;return divi(exp(-mul(x,x)/2),2506628274631000200);} } // Hart rational normal tail approximation; erf(x)=2*Phi(x*sqrt(2))-1. function cdf(int256 x,int256 density) internal pure returns(int256){ unchecked { int256 y=ab(x);if(y>8*U)return x>0?U:int256(0); int256 n=35262496599891000; n=mul(n,y)+700383064443688000;n=mul(n,y)+6373962203531650000; n=mul(n,y)+33912866078383000000;n=mul(n,y)+112079291497871000000; n=mul(n,y)+221213596169931000000;n=mul(n,y)+220206867912376000000; int256 d=88388347648318400; d=mul(d,y)+1755667163182640000;d=mul(d,y)+16064177579207000000; d=mul(d,y)+86780732202946100000;d=mul(d,y)+296564248779674000000; d=mul(d,y)+637333633378831000000;d=mul(d,y)+793826512519948000000; d=mul(d,y)+440413735824752000000; int256 tail=mul(mul(density,2506628274631000200),divi(n,d));return x>0?U-tail:tail; } } function trunc(int256 m,int256 v,int256 lo,int256 hi) internal pure returns(int256 Z,int256 mt,int256 vt){ unchecked { if(v<=0)return (lo<=m&&m<=hi?U:int256(0),m,0); int256 sd=root(v);int256 a=divi(lo-m,sd);int256 b=divi(hi-m,sd); int256 pa=pdf(a);int256 pb=pdf(b); Z=cdf(b,pb)-cdf(a,pa); if(Z<1e6)return(Z,m>(16*L):K1>>(16*(L-16)))&0xffff); } } // cubic B-spline basis at x (1/64 units) by Cox-de Boor; returns span m, N[q] = basis of coefficient m-3+q (WAD) function bas(uint256 K0,uint256 K1,uint256 n,int256 x,int256[4] memory N) internal pure returns(uint256 m){ unchecked { if(x>=kn(K0,K1,n)){m=n-1;}else{uint256 lo=3;uint256 hi=n;while(hi-lo>1){uint256 md=(lo+hi)>>1;if(kn(K0,K1,md)<=x)lo=md;else hi=md;}m=lo;} int256 l1=x-kn(K0,K1,m);int256 l2=x-kn(K0,K1,m-1);int256 l3=x-kn(K0,K1,m-2); int256 r1=kn(K0,K1,m+1)-x;int256 r2=kn(K0,K1,m+2)-x;int256 r3=kn(K0,K1,m+3)-x; int256 tp=U/(r1+l1);int256 n0=r1*tp;int256 n1=l1*tp; tp=n0/(r1+l2);n0=r1*tp;int256 sv=l2*tp;tp=n1/(r2+l1);n1=sv+r2*tp;int256 n2=l1*tp; tp=n0/(r1+l3);N[0]=r1*tp;sv=l3*tp;tp=n1/(r2+l2);N[1]=sv+r2*tp;sv=l2*tp;tp=n2/(r3+l1);N[2]=sv+r3*tp;N[3]=l1*tp; } } // nC consecutive coefficient lanes starting at flat index idx function stripe(uint256 idx,uint256 nC) internal pure returns(uint256 x){ unchecked { uint256 o=idx&15;x=cw(idx>>4)>>(16*o); if(o+nC>16)x|=cw((idx>>4)+1)<<(16*(16-o)); } } function ln16(uint256 x,uint256 p) internal pure returns(int256){ unchecked { return int256((x>>(16*p))&0xffff)-32768; } } // one coefficient stripe contracted with the two column-node bases: ta = sum C0[p] c[p], tb = sum C1[p] c[p+dc] function row2(uint256 x,uint256 dc,int256[4] memory C0,int256[4] memory C1) internal pure returns(int256 ta,int256 tb){ unchecked { ta=C0[0]*ln16(x,0)+C0[1]*ln16(x,1)+C0[2]*ln16(x,2)+C0[3]*ln16(x,3); if(dc==0){tb=C1[0]*ln16(x,0)+C1[1]*ln16(x,1)+C1[2]*ln16(x,2)+C1[3]*ln16(x,3);} else{tb=C1[0]*ln16(x,dc)+C1[1]*ln16(x,dc+1)+C1[2]*ln16(x,dc+2)+C1[3]*ln16(x,dc+3);} } } function bern(uint256 l,uint256 s) internal pure returns(int256){ unchecked { int256 a=int256(l);int256 b=7-a; return s==0?b*b*b:(s==1?3*a*b*b:(s==2?3*a*a*b:a*a*a)); } } // node value: raw sum (1e36 * 1/(8*343) bps) -> WAD bps, clamped at 0 function cl(int256 F) internal pure returns(int256){ unchecked { F=F/U/2744;return F<0?int256(0):F; } } // fee surface F (WAD bps) of table tb at grid point (pw,p2) (WAD grid units): F clamped at 0 at the 4 nodes x 2 sd levels, // bilinear in (row, column), then linear in sd (real.py's RealPolicy.lookup on the decoded tables) function surf(uint256 tb,int256 pw,int256 p2,uint256 k,int256 tt) internal pure returns(int256){ unchecked { (uint256 KR0,uint256 KR1,uint256 KC0,uint256 KC1,uint256 nr,uint256 nc,uint256 base)=tab(tb); uint256 i=uint256(pw/U);if(i>319)i=319;int256 f=pw-int256(i)*U; uint256 j=uint256(p2/U);{uint256 jm=tb==0?11:47;if(j>jm)j=jm;}int256 g=p2-int256(j)*U; int256[4] memory A0;int256[4] memory A1;int256[4] memory C0;int256[4] memory C1; uint256 mi=bas(KR0,KR1,nr,int256(i*64),A0);uint256 dr=bas(KR0,KR1,nr,int256(i*64+64),A1)-mi; uint256 mj=bas(KC0,KC1,nc,int256(j*64),C0);uint256 dc=bas(KC0,KC1,nc,int256(j*64+64),C1)-mj; int256[8] memory W;W[0]=bern(k,0);W[1]=bern(k,1);W[2]=bern(k,2);W[3]=bern(k,3);W[4]=bern(k+1,0);W[5]=bern(k+1,1);W[6]=bern(k+1,2);W[7]=bern(k+1,3); // Fv[l*4 + rownode*2 + colnode] int256[8] memory Fv; uint256 i0=base+(mi-3)*nc+mj-3;uint256 sn=nr*nc; for(uint256 q=0;q=dr&&q>(16*(L&15)))&0xffff)-32768; } } // real.py/evalpol _pos2 over pol_mid's W2L (grid units of 5 bps), WAD in and out function pos2(int256 v) internal pure returns(int256){ unchecked { if(v<=-160*U)return 0; if(v>=160*U)return 48*U; uint256 lo=0;uint256 hi=48; while(hi-lo>1){uint256 md=(lo+hi)>>1;if(w2l(md)*U<=v)lo=md;else hi=md;} int256 a=w2l(lo);return int256(lo)*U+(v-a*U)/(w2l(hi)-a); } } function sdl(uint256 k) internal pure returns(int256){ unchecked { return int256((0x221a14100c080400>>(8*k))&0xff); } } // qm fee rule: w, w2 offsets (WAD bps), phase, synced flag, belief variance v (WAD, ln-price^2) function fees(int256 w,int256 w2,uint256 ph,bool syn,int256 v) internal pure returns(int256 fb,int256 fa){ unchecked { int256 sd=root(v)*10000;uint256 k; while(k<6&&sd>=sdl(k+1)*U)k++; int256 tt=clip((sd-sdl(k)*U)/(sdl(k+1)-sdl(k)),0,U); int256 pw=clip(w/5+160*U,0,320*U);int256 wq=(pw-160*U)*5; uint256 tb;int256 p2;int256 nc1; if(ph==0){tb=0;p2=clip(w2/5,-6*U,6*U)+6*U;nc1=12;} else{tb=(ph==1?1:3)+(syn?0:1);p2=pos2(w2/5);nc1=48;} int256 xa=surf(tb,pw,p2,k,tt)+wq-w; int256 xb=surf(tb,320*U-pw,nc1*U-p2,k,tt)+w-wq; fb=xb>0?U-exp(-xb/10000):int256(0);fa=xa>0?U-exp(-xa/10000):int256(0); fb=clip(fb,0,U/10);fa=clip(fa,0,U/10); } } function afterInitialize(uint256 x,uint256 y) external override returns(uint256,uint256){ unchecked { int256 sp=int256(y*1e18/x); slots[0]=uint256(uint128(int128(ln(sp)))); slots[1]=uint256(uint128(int128(sp)))*(1+(uint256(1)<<128)); slots[2]=2823606104386589*(1+(uint256(1)<<64)); return(2823606104386589,2823606104386589); } } // filter update over a gap of dt steps; returns new m, v, rival spot r and the arb flag function update(int256 m,int256 v,int256 fb,int256 fa,int256 sp,int256 r,int256 s,bool buy,uint256 dt) internal pure returns(int256,int256,int256,bool arb){ unchecked { int256 lo=ln(mul(sp,U-fb));int256 hi=ln(divi(sp,U-fa)); uint256 n=dt-1;if(n>12)n=12; for(uint256 i=0;i0?divi(la,la+lr):int256(0);arb=pi>U/2; if(pi>5e15&&pi<995e15){ m=mul(pi,lp)+mul(U-pi,mt); v=mul(pi,mul(lp-m,lp-m))+mul(U-pi,vt+mul(mt-m,mt-m)); }else if(arb){m=lp;v=0;}else{m=mt;v=vt;} int256 pe=exp(m);r=clip(r,mul(pe,997e15),divi(pe,997e15)); return(m,v,r,arb); } } function afterSwap(TradeInfo calldata t) external override returns(uint256,uint256){ unchecked { uint256 s0=slots[0];uint256 s1=slots[1];uint256 s2=slots[2]; int256 m=int256(int128(uint128(s0)));int256 v=int256(int128(uint128(s0>>128))); int256 sp=int256(int128(uint128(s1)));int256 r=int256(int128(uint128(s1>>128))); int256 fb=int256(s2&M64);int256 fa=int256(s2>>64&M64);uint256 cnt=s2>>192&0xffffffff;bool syn=s2>>255==1; int256 s=int256(t.reserveY*1e18/t.reserveX);bool arb; if(t.timestamp>(s2>>128&M64)){(m,v,r,arb)=update(m,v,fb,fa,sp,r,s,t.isBuy,t.timestamp-(s2>>128&M64));cnt=0;syn=false;} uint256 ph; if(!arb){ int256 c=t.isBuy?divi(mul(s,U-fb),997e15):divi(mul(s,997e15),U-fa); if(t.isBuy?cr){r=c;syn=true;} cnt++;ph=cnt==1?1:2; } int256 w=(ln(s)-m)*10000;int256 rr=(ln(r)-m)*10000; (fb,fa)=fees(w,rr,ph,syn,v); slots[0]=uint256(uint128(int128(m)))|uint256(uint128(int128(v)))<<128; slots[1]=uint256(uint128(int128(s)))|uint256(uint128(int128(r)))<<128; slots[2]=uint256(fb)|uint256(fa)<<64|t.timestamp<<128|cnt<<192|(syn?uint256(1)<<255:0); return(uint256(fb),uint256(fa)); } } } ``` ### 1.3 The gate-F reference for qt1 (`qmref.py`) The reference is standard-library Python: trim-2's filter (port-3's `standalone.Coarse` verbatim, plus `real.py`'s `synced` flag) and `real.py`'s `RealPolicy.lookup` qm rule over the tables decoded from the 10,167-byte QMS1 blob (sha256 `3ac7cb8811ecfb6a17f499aa4e9b70dd55f7fb6432b3aec3b904e11a3dece38e`, in the qm-spline artifact). Its pure-Python decoder matches qm-spline's numpy decoder exactly (max diff 0 over all ten tables; decoded JSON sha256 `4d97c205783ddff731fecd9dbdaea09c295954d2d2e96fbf25eec1320a5c22fa`), and it reproduces qm-spline's check values 443.101741 / 571.454483 / 525.908441 on seeds 10000..10002. Gate F replayed `replica2.run(seed, QMRef)` for seeds 70000..70049, the first 2,000 own-pool callbacks each, on a fresh pyrevm deployment at 245,000 gas per call: 100,050 calls succeeded, max |fee diff| 5.826e-06 bps. ```python """qt1 reference: Taylor's (gtmcknight) Gaussian filter (as port-3's standalone.Coarse / trim-2) + real.py's qm fee rule over the DECODED qm-spline tables (QMS1 blob, sha256 3ac7cb88...). Standard library only. usage: from qmref import QMRef; QMRef('blob.bin') is a replica2 policy (wants_j). Init fees = real.py's init: the full plain pol_mid table at (0,0,0) = 0.002823606104386589 each. """ import math, struct SIG2 = .000945 ** 2 LD_M, LD_S = math.log(11.12e-4), 1.176 INIT = 0.002823606104386589 MAXF = 0.1 def phi(x): return math.exp(-.5 * x * x) / 2.5066282746310002 def Phi(x): return .5 * (1 + math.erf(x / 1.4142135623730951)) def trunc(m, v, lo, hi): if v <= 0: return float(lo <= m <= hi), m, 0. sd = math.sqrt(v); a = (lo - m) / sd; b = (hi - m) / sd; z = Phi(b) - Phi(a) if z < 1e-12: return z, lo if m < lo else hi, v * .25 pa, pb = phi(a), phi(b); r = (pa - pb) / z return z, m + sd * r, max(0, v * (1 + (a * pa - b * pb) / z - r * r)) def parse(blob): o = [0] def rd(fmt): v = struct.unpack_from('<' + fmt, blob, o[0]); o[0] += struct.calcsize('<' + fmt); return v assert blob[:4] == b'QMS1'; o[0] = 4 form, ntab, nw, w0, h, ns = rd('BBHHBB'); assert form == 3 S = list(rd('%dB' % ns)); n2 = rd('B')[0]; W2L = list(rd('%dh' % n2)); fb = rd('B')[0] tabs = [] for _ in range(ntab): nr, nc, nk = rd('BBB') kr = list(rd('%dH' % (nr - 4))); kc = list(rd('%dH' % (nc - 4))); ks = list(rd('%dH' % (nk - 4))) assert nk == 4 and not ks tabs.append([nr, nc, nk, kr, kc]) for t in tabs: t.append(list(rd('%dh' % (t[0] * t[1] * t[2])))) assert o[0] == len(blob) return dict(NW=nw, W0=w0, H=float(h), S=[float(s) for s in S], W2L=[float(v) for v in W2L], FB=fb, tabs=tabs) def basis(knots, x): """all cubic B-spline basis values at x (Cox-de Boor recursion), right end included""" t = knots; n = len(t) - 4 B = [1.0 if t[m] <= x < t[m + 1] else 0.0 for m in range(len(t) - 1)] if x >= t[-1]: last = max(m for m in range(len(t) - 1) if t[m] < t[m + 1]); B = [0.0] * (len(t) - 1); B[last] = 1.0 for d in range(1, 4): Bn = [0.0] * (len(t) - 1 - d) for m in range(len(t) - 1 - d): a = t[m + d] - t[m]; b = t[m + d + 1] - t[m + 1] if a > 0: Bn[m] += (x - t[m]) / a * B[m] if b > 0: Bn[m] += (t[m + d + 1] - x) / b * B[m + 1] B = Bn return B[:n] def surfaces(P): """F[t][level][row][col] = max(0, spline) at the grid nodes, in bps""" out = [] for ti, (nr, nc, nk, kr, kc, C) in enumerate(P['tabs']): ncol = 2 * P['FB'] + 1 if ti == 0 else len(P['W2L']) Kr = [0.0] * 4 + [v / 64 for v in kr] + [P['NW'] - 1.0] * 4 Kc = [0.0] * 4 + [v / 64 for v in kc] + [ncol - 1.0] * 4 Ks = [0.0] * 4 + [len(P['S']) - 1.0] * 4 Br = [basis(Kr, i) for i in range(P['NW'])]; Bc = [basis(Kc, j) for j in range(ncol)] Bs = [basis(Ks, l) for l in range(len(P['S']))] F = [] for l in range(len(P['S'])): D = [[sum(Bs[l][s] * C[(s * nr + r) * nc + c] for s in range(nk)) / 8.0 for c in range(nc)] for r in range(nr)] E = [[sum(D[r][c] * Bc[j][c] for c in range(nc)) for j in range(ncol)] for r in range(nr)] F.append([[max(0.0, sum(Br[i][r] * E[r][j] for r in range(nr))) for j in range(ncol)] for i in range(P['NW'])]) out.append(F) return out class Tables: """A/B exactly as qms_decode.to_qm writes them (rounded to 6 decimals)""" def __init__(self, blob): P = parse(blob); self.P = P NW = P['NW']; w = [(i - P['W0']) * P['H'] for i in range(NW)] self.A = {}; self.B = {} for tag, F in zip(['0c', '1s', '1c', '2s', '2c'], surfaces(P)): A = [[[round(F[l][i][j] + w[i], 6) for j in range(len(F[l][i]))] for i in range(NW)] for l in range(len(F))] self.A[tag] = A self.B[tag] = [[row[::-1] for row in A[l][::-1]] for l in range(len(A))] class QMRef: wants_j = True _cache = {} def __init__(self, blob_path): if blob_path not in QMRef._cache: QMRef._cache[blob_path] = Tables(open(blob_path, 'rb').read()) self.T = QMRef._cache[blob_path]; P = self.T.P self.S = P['S']; self.W0 = P['W0']; self.NW = P['NW']; self.h = P['H']; self.FB = P['FB']; self.W2L = P['W2L'] self.m = math.log(100); self.v = 0.; self.tlast = 0; self.cnt = 0; self.s2h = 100.; self.fb = self.fa = .003 self.sp = 100.; self.synced = False def _pos2(self, v): W = self.W2L; n = len(W) if v <= W[0]: return 0.0 if v >= W[n - 1]: return float(n - 1) lo, hi = 0, n - 1 while hi - lo > 1: mid = (lo + hi) // 2 if W[mid] <= v: lo = mid else: hi = mid return lo + (v - W[lo]) / (W[hi] - W[lo]) def lookup(self, w, w2, phs, sd): # real.py RealPolicy.lookup S = self.S; k = 0 while k < len(S) - 2 and sd >= S[k + 1]: k += 1 tt = min(1.0, max(0.0, (sd - S[k]) / (S[k + 1] - S[k]))) tag = '0c' if phs == 0 else (str(phs) + ('s' if self.synced else 'c')) A, B = self.T.A[tag], self.T.B[tag] pw = min(self.NW - 1.0, max(0.0, w / self.h + self.W0)) l2 = w2 / self.h if phs == 0: l2 = min(self.FB, max(-self.FB, l2)); p2 = l2 + self.FB; n2 = 2 * self.FB + 1 else: p2 = self._pos2(l2); n2 = len(self.W2L) i = min(int(pw), self.NW - 2); j = min(int(p2), n2 - 2); f = pw - i; g = p2 - j def bl(Tb): return (Tb[i][j] * (1 - f) + Tb[i + 1][j] * f) * (1 - g) + (Tb[i][j + 1] * (1 - f) + Tb[i + 1][j + 1] * f) * g a = bl(A[k]) * (1 - tt) + bl(A[k + 1]) * tt b = bl(B[k]) * (1 - tt) + bl(B[k + 1]) * tt fa = 1.0 - math.exp(-(a - w) * 1e-4) if a > w else 0.0 fb = 1.0 - math.exp(-(b + w) * 1e-4) if b > -w else 0.0 return fb, fa def init(self, *args): self.fb = self.fa = INIT; return INIT, INIT def on_trade(self, is_buy, ax, ay, t, x, y, arb=False, p=100., s2=100., j=0): s = y / x; dt = t - self.tlast; is_arb = False if dt >= 1: self.cnt = 0; lo = math.log(self.sp * (1 - self.fb)); hi = math.log(self.sp / (1 - self.fa)); m, v = self.m, self.v for _ in range(min(dt - 1, 12)): v += SIG2; _, m, v = trunc(m, v, lo, hi) v += SIG2 lp = math.log(s * (1 - self.fb)) if is_buy else math.log(s / (1 - self.fa)); sd = math.sqrt(v) la = phi((lp - m) / sd) / sd; Z, mt, vt = trunc(m, v, lo, hi); d = max(abs(math.log(s / self.sp)), 1e-9) lr = Z * .26 * phi((math.log(d) - LD_M) / LD_S) / (d * LD_S) pi = la / (la + lr) if la + lr > 0 else 0.; is_arb = pi > .5 if .005 < pi < .995: m2 = pi * lp + (1 - pi) * mt; self.m, self.v = m2, pi * (lp - m2) ** 2 + (1 - pi) * (vt + (mt - m2) ** 2) elif is_arb: self.m, self.v = lp, 0. else: self.m, self.v = mt, vt pe = math.exp(self.m); self.s2h = max(pe * .997, min(pe / .997, self.s2h)); self.synced = False if not is_arb: cand = s * (1 - self.fb) / .997 if is_buy else s * .997 / (1 - self.fa) if (cand < self.s2h) if is_buy else (cand > self.s2h): self.s2h = cand; self.synced = True self.cnt += 1; ph = 1 if self.cnt == 1 else 2 else: ph = 0 self.tlast = t; self.sp = s fb, fa = self.lookup((math.log(s) - self.m) * 1e4, (math.log(self.s2h) - self.m) * 1e4, ph, math.sqrt(self.v) * 1e4) self.fb, self.fa = min(MAXF, max(0.0, fb)), min(MAXF, max(0.0, fa)) return fb, fa ``` ## 2. The qm policy's 1,792-seed confirmation (qm-2) and why qm-2 itself cannot ship qm-2 (r4-qm-port copy 2; `TaylorGaussianQmSpline`, source sha256 `50a741b97a7ed79237ecbd34a4bc20b5c70b7872d8916f31dc3fe3f72b4fe859`, runtime 19,346 bytes, the Solidity block under "## Strategy.sol" of artifact `e50ab7b9…`) is the first qm port: trim-1's filter and math, the qm-spline tables as 306 PUSH32 words, Cox-de Boor bases at runtime. Gate P pass, gate F 5.83e-6 bps, gate Q inherited from qm-spline (tables unchanged). On its own 128 seeds (9534000..9534127) it scored +2.137 se 0.113 over t03 (124/128 wins) and +2.912 over IB with an engine peak of 245,140 and 0 OutOfGas. The requester asked for its 2,048-seed confirmation against trim-1 and, in parallel, for gas trims that keep its fees (notes 6 and 7). ### 2.1 Per-block results (qm-2 minus trim-1, t03, IB; 256 seeds per block, 4 arms each, IB never dropped) | Block | Seeds | vs trim-1 (mean, se) | vs t03 | vs IB | qm-2 calls | qm-2 OOG | qm-2 peak | trim-1 peak | |---|---|---|---|---|---:|---:|---:|---:| | qa1 | 9613312..9613567 | +0.8666, 0.0411 | +2.2409, 0.0865 | +3.0132, 0.0909 | 2,780,715 | 2 | 246,980 | 230,161 | | qa2 | 9613568..9613823 | +0.9077, 0.0450 | +2.1956, 0.0751 | +2.9813, 0.0840 | 2,781,622 | 5 | 248,814 | 233,405 | | qa3 | 9613824..9614079 | still running, not handed | | | | | | | | qa4 | 9614080..9614335 | +0.8961, 0.0431 | +2.3710, 0.0828 | +3.1473, 0.1025 | 2,777,463 | 10 | 249,376 | 235,450 | | qb1 | 9614336..9614591 | +0.8204, 0.0417 | +2.3613, 0.0780 | +3.1220, 0.0968 | 2,813,060 | 5 | 247,997 | 235,703 | | qb2 | 9614592..9614847 | +0.8874, 0.0401 | +2.1224, 0.0824 | +2.9626, 0.0879 | 2,768,247 | 1 | 249,885 | 233,101 | | qb3 | 9614848..9615103 | +0.8767, 0.0411 | +2.3430, 0.0807 | +3.1188, 0.0847 | 2,796,482 | 6 | 248,782 | 228,546 | | qb4 | 9615104..9615359 | +0.8733, 0.0396 | +2.2729, 0.0774 | +3.0317, 0.0816 | 2,807,105 | 4 | 249,895 | 226,410 | | **pooled** | 7 blocks | **+0.8755, 0.0158** | **+2.2724, 0.0304** | **+3.0539, 0.0340** | 19,524,694 | **33** | **249,895** | 235,703 | In the same blocks trim-1 minus t03 is +1.397 se 0.032 and t03 minus IB is +0.781 se 0.020 (recomputed from the CSVs). Mean successful afterSwap gas: qm-2 about 155.2k, trim-1 131.5k, t03 135.6k, IB 135.3k. t03's peaks were 235,394..237,473 and IB's 232,022..236,928 in every block; neither ever ran out of gas. ### 2.2 Gas verdict on qm-2 qm-2 fails the goal's limits as shipped: a successful-call peak of 249,895 (4,895 over) and 33 OutOfGas callbacks across the seven blocks, with at least one OutOfGas in every block. Its 128-seed run had looked just over the line (245,140, 0 OOG); 1,792 seeds found the tail. The engine evidently lets some calls above the printed 245,000 succeed (net-1 at 245,377 and qm-2 at 249,895 both returned), but the goal's rule is the number and the OutOfGas count, and qm-2 meets neither. The engine's chunk counters cannot name the failing seeds; the scores above include whatever those failures cost qm-2. ## 3. Gas-safe contracts with the qm policy Four contracts carry the qm policy within the limits. The first three are measured; the fourth failed. | Contract | Shell | Runtime B | Fees | Gate F (bps) | pyrevm peak | Engine peak / OOG (n=128 block) | Paired engine result | Source sha256 | Artifact | |---|---|---:|---|---:|---:|---|---|---|---| | **qt1** (section 1) | trim-2 (3 slots, port-3 math) | 20,605 | same reference as qm-2, within 5.83e-6 bps | 5.83e-6 | 194,051 | 208,775 / 0 (9535000..9535127) | +2.160 se 0.110 vs t03; +0.819 se 0.055 vs trim-2 | `c68887cf…08aca` | `8a6e303b…` | | **qtr2** (r6-qm-trim copy 2, `TaylorGaussianQmTrim2`) | trim-1 shell, 4 packed slots | 19,945 | **bit-identical to qm-2**: 0 of 100,000 replayed callbacks differ, returned-fee digest `5da30a88…` equal | 5.83e-6 (inherited) | 173,599 | 191,661 / 0 (9538000..9538127) | +0.838 se 0.053 vs trim-1 (no t03 arm) | `7b99afae570ef1627b0163fb21411f14c496b005a07c3966cc7323906dee664f` (43,073 B, recomputed) | `18ca35cb…` | | **qtr1** (r6-qm-trim copy 1, `TaylorGaussianQmTrimQtr1`) | trim-1 shell, 8 slots | 20,923 | bit-identical to qm-2 (same digest `5da30a88…`, 0 differing) | 5.83e-6 (inherited) | 180,421 | 228,156 / 0 (9537000..9537127) | +0.851 se 0.050 vs trim-1 (no t03 arm) | `f6717eba62e8164b32ca87ca0a718bb8888860da54b0fd3bc8830fcf5a73edf6` (44,942 B, recomputed) | `09741ad7…` | | qm-1 (r4-qm-port copy 1, `TaylorGaussianQMSpline`, Q23 bases) | trim-1 shell | 20,135 | own fixed point | 9.9e-4 | 186,205 | 229,132 / 0 (9533000..9533127) | +2.207 se 0.096 vs t03; +2.975 se 0.112 vs IB | `c96e646d5c76ebcdf1e57aecbfe207b3a0e92e71281ac437eeb3046babb94883` | `e631c005…` | | qtr4 (r7-qm-trim copy 4, `TaylorGaussianQmSplineG`) | trim-1 shell | 19,332 | bit-identical to qm-2 | 5.83e-6 | 214,730 | **249,129 / 2** (9540000..9540127): fails | 2 OOG, not scored | `ac5ff1b1…d5e1` | `dbb0431d…` | What the trims changed (fees untouched in every case): qtr2 scalarised the eight node sums without changing accumulation or division order, shared the mirrored knot geometry while re-running the original Cox-de Boor recurrence in its original rounding order (reversing rounded weights would not be identical), and packed eight storage slots into four, each read once; qtr1 used binary knot search, six-knot windows and unrolled row/column evaluation with aligned coefficient words; qtr4 only changed the knot comparison and saved nothing. qt1 is a different shell: trim-2's byte-identical-to-net-1 filter plus a scalar/fixed-index spline contraction and a 20-function binary-tree dispatch over the 306 coefficient words (a single 306-leaf tree segfaulted solc at the default stack). Because qtr1 and qtr2 return exactly qm-2's bytes on every replayed callback, qm-2's 1,792-seed confirmation is their confirmation (the engine is deterministic given the fees), minus only the OutOfGas callbacks qm-2 suffered and they would not. qt1 carries the same tables and the same reference within 5.83e-6 bps but was never compared bit for bit with qm-2, so for qt1 the 1,792 seeds confirm the policy and its own 128 seeds plus the board confirm the contract. Expected scores of qt1, qtr1 and qtr2 are therefore the same to within the rounding noise; the choice between them is gas and size. qtr2 has the most headroom (191,661 on its block; qm-2's peak rose about 4,800 between its 128-seed block and its 1,792-seed campaign, so budget for that), qt1 is the one already on the board. ## 4. The compression table Sign convention: loss = full-table policy minus compressed-table policy on Taylor's replica, paired by seed, so positive is worse; "choose" is seeds 60000..61023 (n=1,024) and "report" is 10000..12047 (n=2,048, scored once after the choice). The full plain tables are six arrays of 321 rows (w = -800..800 bps step 5) by 13 (phase 0) or 49 (phases 1 and 2, nonuniform W2L axis) = 71,262 values in a 780,061-byte JSON; B is the exact point mirror of A (`B[i][j] = A[320-i][nc-1-j]`, zero differences over all 71,262 cells), so only A need be stored. The full qm tables are 8 sd levels x 5 tags x 321 x (13 or 49) = 1,073,424 values in a 7,892,018-byte JSON, mirror-symmetric in all but one cell (tag 1c, level 6, i=160, j=24, off by 0.71 bps). The fee surface F = A - w is never negative and is exactly 0 in about 47 % of cells. | Representation (item) | Tables | Format | Bytes | Choose loss (se) | Report loss (se) | Replica cost verdict | Used by | |---|---|---|---:|---|---|---|---| | sym-int8 (r1-compress-a) | plain | mirror + per-row int16 base + int8 residuals at 1 bps, 81 own knots | 10,024 | -0.0013 (0.0108) | -0.0086 (0.0078) | lossless in mean | no contract | | rows-10bps (r1-compress-a) | plain | int16, rows every 10 bps, all columns | 71,484 | +0.0133 (0.0121) | +0.0164 (0.0095) | quality fine, far too big | no contract | | fewer-cols (r1-compress-a) | plain | 3 rival columns per phase | 11,572 | +0.743 (0.020) | +0.748 (0.015) | fails | no contract | | svd-lowrank (r1-compress-b) | plain | ranks 4/6/6 int16 factors | 11,571 | +0.468 (0.020) | +0.464 (0.014) | fails | no contract | | smooth-2d (r1-compress-b) | plain | cubic tensor B-spline of F, decoded at grid nodes then bilinear | 2,665 | +0.0098 (0.0127) | +0.0097 (0.0090) | lossless in mean | spline-1 (exact packed bases: -0.0097 se 0.0090 report) | | fixed-net (r1-compress-b) | plain | int16 4-32-32-1 ReLU MLP, 8 grid passes | 2,730 | -0.056 (0.016) | -0.040 (0.011) | better than full in mean | net-1/net-2/trim-1/trim-2 as the 2-pass "net2" policy: +0.0054 (0.0161) on choose (r3-gate-q), +0.019 (0.014) on report seeds 10000..11280 only (net-2) | | port-3 coarse table (r1-port) | plain | 81 x 7/13 int16 knots, 10,692-byte payload | 11,055 | +0.744 (0.018) | +0.742 (0.012) | the cost of port-3's coarse grid | port-3 | | port-2 table (r1-port) | plain | 41 x 25 int16 knots | 10,464 | +0.073 (0.014) | +0.083 (0.010) | plus its aggregated silent-step filter: -0.035 (0.010) more on 2,048 seeds, -0.045 (0.013) on choose | port-2 | | **qm-spline (r2-qm-compress)** | **qm** | one 3-D clamped cubic B-spline per tag over (row, column, sd level), int16 coefficients in 1/8 bps, knots at visit quantiles, censored least squares; QMS1 blob | **10,167** | 0.0549 (0.0103) | **0.0632 (0.0072)**, rerun by qm-1: 0.0632 (0.0072), worst5 (10522, 1.458), (10711, 1.360), (12015, 1.342), (10268, 1.172), (10203, 1.092) | about +3.71 vs HA against the full tables' +3.77 | qm-1, qm-2, qt1, qtr1, qtr2 | | qm-net (r2-qm-compress) | qm | int16 5-32-32-1 MLP | 3,076 | 0.601 (0.020) | +0.589 (0.014) | fails (training not converged) | no contract | Lookup cost of the shipped qm-spline representation, measured in qm-1's instrumented contract at w = R = 0: one ask+bid lookup 72.9k to 82.3k gas depending on phase and sd (phase 0 72,890; 1s 82,153; 1c 74,802; 2s 82,321; 2c 73,321), including ABI dispatch and the table init. qt1 brought the two surfaces to about 35-43k each by contracting into stack and fixed-index memory instead of dynamic arrays; qtr2 took another 42k off qm-2's pyrevm peak. The lattice line (section 6) is where gas ran out, not here. ## 5. Gates **Gate P (before any change).** Every item that touched Taylor's files ran the unmodified `python3 -I gates.py` first and reproduced the README block digit for digit: gaussian+plain 443.455598 / 571.463409 / 525.168028, gaussian+qm 443.522608 / 571.623551 / 525.865859, lattice+qm 443.663520 / 571.977293 / 526.411631, perfect-info 448.261189 / 576.779199 / 531.886497 on seeds 10000..10002; and `real.py pol_mid.json plain:soft=1` on 10000..12047 gave +2.828 se 0.041 vs the stored HA rows (mean edge 532.386). The one exception was the svd item, which reproduced the +2.828 aggregate but did not run gates.py; its representation failed Q anyway. **Gate Q (replica, exactly the shipped tables).** The table in section 4. For the shipped qm contracts Q is qm-spline's 0.0632 se 0.0072 on the report set, independently rerun by qm-1 with tables regenerated from its own contract constants (byte-identical decoded JSON, sha256 `4d97c205…`): choose 0.0549 se 0.0103, report 0.0632 se 0.0072. qm-2, qt1, qtr1 and qtr2 ship the same QMS1 blob unchanged. For the plain line, trim-1/trim-2 (net2) cost nothing measurable (+0.0054 se 0.016 on choose), port-3's coarse grid cost 0.742 and port-2's table plus filter about 0.12. **Gate F (contract fees vs the Python reference, 50 runs x 2,000 callbacks, seeds 70000..70049, max |diff| in bps, applied fees).** | Contract | Max abs fee difference (bps) | Note | |---|---:|---| | port-3 | 1.4e-8 | coarse table reference | | net-1 / net-2 / trim-2 | 3.18e-9 | the same trace hash `69a29538…`, trim-2 byte-identical to net-1 on 10,005 replayed returns | | trim-1 | 5.05e-9 | tolerance-equivalent to net-1, not bit-identical | | spline-1 final | 0.0089 | against the original smooth-2d decoded tables, not the exact packed bases scored in Q | | port-2 | 5.6e-4 | its own aggregated-filter reference | | qm-1 | 9.9e-4 | | | qm-2 | 5.83e-6 | | | qt1 | 5.83e-6 | reference in section 1.3 | | qtr1, qtr2, qtr4 | 0 differing callbacks of 100,000 vs qm-2 (so 5.83e-6 vs the reference) | returned-fee digests equal `5da30a8850396a3077855ea28a0303d3651dfc0abe1c9d1bcc7210f3ef3b98cf` | One qualification applies to every qm contract: at one callback (seed 70026, callback 1702) unmodified `real.py` returns a raw bid fee of 0.12000793 while storing and applying the capped 0.10 (replica2's `clampf`); every contract returns 0.10. Against the applied fees the max difference is 5.83e-6 bps; against the raw uncapped return it would be 200.08 bps at that single callback. The engine and the replica both apply the cap, so the applied-fee reading is the one that matters for scores, but a literal raw-return reading of gate F is not met. ## 6. Lines that did not fit or did not pay **Lattice filter (Taylor's `latt.py`, +4.26 with qm on the replica).** lattice-2 ported it exactly (matches Taylor's Python to 1e-8 bps, runtime 20,992 bytes) and measured it on 20,000 replayed callbacks: mean 453,463 gas, peak 10,513,884, 64.5 % of callbacks over 245,000. Reductions (pyrevm peak / callbacks over 245k / replica cost vs the full lattice, n=48): 61 cells x 5 bps cap 30: 3,075,267 / 4,695 / -0.043; 31 x 10 cap 2: 335,145 / 116 / -0.086; 61 x 5 cap 1: 575,880 / 4,705 / -0.173; 31 x 10 cap 1: 258,576 / 15 / -0.182. The best reduction still exceeds the whole budget in pyrevm before the engine's roughly 15-50k overhead and before any table lookup, and most of the +4.26 is the qm tables (+1.75 of it on that probe), which qt1 already has. Unmeasured ideas from the probe: a 3-sigma kernel cut, a skip threshold, 21 cells x 10 bps, an unrolled loop, one sigma*sqrt(n) diffusion. Line stopped. **Arb-or-retail call (README open item 3, worth up to 2.7 with the true flag; +3.72 with plain tables on the replica).** Three classifier ideas moved the replica by at most +0.05 on the report set: per-run sigma and order rate +0.0235 se 0.0083 (arb-2), a conditional router inverse +0.0493 se 0.0120 (arb-3), arrival-pattern features +0.011 se 0.009 (r6-arb/ar2); the first-trade error rate stays at about 16.6 %. One idea did pay: r6-arb/ar3 keeps the classifier and instead quotes against the step's whole posterior (arb point mass plus a 3-point Gauss-Hermite quadrature of the truncated retail Gaussian), averaging the per-node table quotes: **+0.5667 se 0.0182 on choose and +0.5662 se 0.0125 on the report set, 1,746 of 2,048 wins, worst seed -1.50**, about 15 % of the true-flag gap, at 2-4 table lookups per callback (the 2-lookup qs=0 variant keeps +0.49 on choose). It was measured with the plain tables only; whether it adds on top of the qm tables is untested, and nothing from this line was ported in this goal. Its complete `realpq.py` (sha256 `488ad8a8…`) is in the ar3 artifact. **qm-net.** 3,076 bytes but loss +0.589; the training had not converged when time ran out. Dropped in favour of qm-spline. ## 7. Every candidate, with its per-block evidence Board: IB 522.00; port-3 523.3369 (12th at the time); trim-1 524.1189 (11th); qt1 524.9403 (8th; 7th is 525.377, 6th 526.777, 5th 528.099). | Candidate (name, runtime B, sha256) | Policy | Engine blocks | vs t03 pooled | vs IB pooled | Max engine peak / OOG | Status | |---|---|---|---|---|---|---| | port-3 (`TaylorGaussianPlainCoarse`, 18,466, `62930b8e68277c69fc1acfba18de781e684d7fc6daac8dc562b8210dc3932ac1`) | Gaussian + coarse plain table (loss 0.742) | 8 x 256: a1..a4 +0.618/+0.746/+0.532/+0.617, b1 +0.592, b2 +0.652, b4 +0.647, p3-b3 +0.634 (se 0.080-0.091 each) | **+0.630, se about 0.031, n=2,048** | +1.401 | 207,453 / 0 | on the board 523.3369 | | port-2 (`TaylorGaussianPlain2`, 18,484, `7e2d9c157a7725c2875eea31e5741938fb9eafef5a3442710573f1b1a87faf17`) | Gaussian with one aggregated silent-step truncation + 41x25 table | 7 x 256: pa1 +1.450, pa2 +1.162, pa3 +1.060 (seed 9609765 at -7.6), pa4 +1.416 (its configs reused the default runner's 0..255 parameter draws), pb2 +1.244, pb4 +1.375, pb1r +1.328; pb3 running | +1.291, se about 0.037, n=1,792 | about +2.05 | 227,141 / 0 | dropped: not above trim-1 | | trim-1 (`TaylorGaussianPlainNet2`, 16,077, `d849c5f15d69499560b5c3ea08f55ad27153b393eba7abb7dd186f451ad46a24`) | Gaussian + fixed-net 2-pass (net2), tolerance-equivalent to net-1 | 7 x 256 own blocks: ta1..ta4 +1.317/+1.435/+1.345/+1.352, tb1 +1.245, tb2 +1.180, tb4 +1.407 (se 0.082-0.091); tb3 (9608704..9608959) blocked twice on non-Linux seats; plus the 7 qm blocks as comparator: +1.397 se 0.032 | **+1.326, se about 0.033, n=1,792** (own blocks); +1.36 over all 3,584 seeds | +2.055 | 238,704 / 0 (own blocks), 235,703 (qm blocks) | on the board 524.1189 | | trim-2 (`TaylorGaussianPlainNet2Trim`, 11,680, `6157028022f7f2151781ea3a772e4a99956ab9c38c8fbabf4995887d05564b27`) | net2, fees byte-identical to net-1 | 128 (9531000..9531127): +1.407 se 0.117; 128 as qt1's comparator: +1.341 se 0.117 | +1.37 on 256 seeds | +2.236 (128) | 130,711 / 0 | never confirmed on 2,048 (its confirm batches were refused twice) | | net-1 (16,368, `5c40c67a…`) / net-2 (13,568, `879d7ec4…`) | net2 | 128 each: +1.228 se 0.103 / +1.469 se 0.137 | | +2.009 / +2.268 | 245,377 / 0 and 209,552 / 0 | net-1 over the cap; superseded by the trims | | spline-1 final (`TaylorGaussianPlainSpline`, 21,106, `27ad2a5f3d2b218138a95f8d4ab616227ca7dfd855a9c60577f86fea09c6caed`) | Gaussian + smooth-2d spline | 128 (9532000..9532127): +1.278 se 0.129 | | +2.083 | 231,131 / 0 | dropped: no better than trim-1, bigger and hotter | | qm-1 (20,135) | Gaussian + qm-spline | 128: +2.207 se 0.096 | | +2.975 | 229,132 / 0 | superseded by qt1/qtr2 | | qm-2 (19,346) | Gaussian + qm-spline | 128: +2.137 se 0.113; 7 x 256: section 2 | **+2.272 se 0.030, n=1,792** | +3.054 | 249,895 / 33 | fails gas | | **qt1 (20,605)** | Gaussian + qm-spline | 128: +2.160 se 0.110 | | about +2.9 by offset | 208,775 / 0 | **on the board 524.9403; the deliverable** | | qtr2 (19,945) / qtr1 (20,923) | qm-2's fees bit for bit | 128 each vs trim-1: +0.838 se 0.053 / +0.851 se 0.050 | inherits qm-2's +2.272 | inherits +3.054 | 191,661 / 0 and 228,156 / 0 | gas-safe equals of qt1; qtr2 recommended as the shell for further work | Baseline: t03 minus IB is +0.745 se 0.084 on seeds 9500000..9500143 (r1-baseline, 144 of its 1,024 seeds) and +0.781 se 0.020 on the 1,792 qm confirmation seeds. ## 8. Engine seed registry (fresh from 9500000, never reused) 9500000..9501023 r1-baseline (only ..9500143 run); 9510000..9510191 r1-port (port-3 scored on 9510128..9510191; port-2's 9510064..9510127 were also used in its debugging); 9520000..9520127 spline-1 v24; 9521000..9521127 spline-2 (unused); 9522000..9522127 net-1; 9523000..9523127 net-2; 9524000..9524063 lattice-1 (unused); 9525000..9525063 lattice-2 (unused); 9530000..9530127 trim-1; 9531000..9531127 trim-2; 9532000..9532127 spl-128; 9533000..9533127 qm-1; 9534000..9534127 qm-2; 9535000..9535127 qt1; 9536000..9536127 qt2 (running); 9537000..9537127 qtr1; 9538000..9538127 qtr2; 9539000..9539127 qtr3 (running); 9540000..9540127 qtr4; 9600000..9602047 port-3 (8 blocks); 9602048..9607167 burned by the refused round-3 confirm batches (never run); 9607168..9609215 trim-1 (9608704..9608959 never run); 9609216..9611263 port-2 (9610752..9611007 = pb3, running); 9611264..9613311 burned by the refused round-5 confirm batches; 9613312..9615359 qm-2 (9613824..9614079 = qa3, running). Next free: 9541000 and 9615360. Replica seeds: choose 60000..61023, report 10000..12047, gate-F replays 70000..70049. ## 9. Artifacts (public at `https://api.imd.fun/artifacts/`; the id is the sha256 of the result.md) | Result | Artifact id | |---|---| | qt1 (r5-qm-t2) | `8a6e303b662e1a5ea9bb47f31acedd3988ef65b3ddb66d074517aa59ad41ca40` | | qtr2 (r6-qm-trim) | `18ca35cb47390b8e8c289b240d7836804692998ad64f84ef248c43d61e199f0b` | | qtr1 (r6-qm-trim) | `09741ad7e5fd0f84d8294a7c37042281b0b8872b344fbf6e260124b37bc49b6f` | | qtr4 (r7-qm-trim) | `dbb0431dabc098a381744bbd4db54f43da8267a3bc29d24a1fb4a12ff83c1745` | | qm-2 (r4-qm-port) | `e50ab7b92163d8589bb2f75c49d6cda2a1012bb96a0f4a52620b887668f63264` | | qm-1 (r4-qm-port) | `e631c005505076970c29cf8a4fae2a9eb5943252a7d00d72370b5443d0222e91` | | qm-2 confirmation blocks qa1, qa2, qa4 | `00a96f4d9c5bf0a4e6118b2063dd779e4ab7e24c60bc840f74fd8778a09b73ee`, `ecd38e4f7da4b2e3a4cfa3c6915a2a5d0ba0bd8555845451d6679ddcdb2b88e8`, `1eaa69c34be73ccf0213acb2d978df143e432f7b25b3053796440ad1c85f68b0` | | qm-2 confirmation blocks qb1..qb4 | `41bd2bdbf8385ece615d29f7c60d75660d558db2cacba08d1ac748bae3819659`, `c7ffa22abd281ff01e5a36492b45a6abf5e6ae4bdeac726a3e85d44966cbb4bd`, `adfc9c08dbcf72ae954475e8617a99dab32506db0a64060cf11387f07be7aae4`, `bc47490ac83e2bbb54ab590b1c6ffe6c762ee3660e0eceddbb773424ac4f4de8` | | qm-spline (r2-qm-compress) | `17d249ab0c33fc44931d9b105cf3f9e3846a560bd518b67310c2a56defacdecc` | | trim-1 (r3-trim-net) | `fce772b9057867b241350b8e44c05298c6c877871a26b58702a5af431726f6c5` | | trim-2 (r3-trim-net) | `22560aac69c88188ffee4c1dfa7c58685ae83fd4b415fef626ed7258a12e7542` | | port-3 (r1-port) | `0dbcc10af41b3c3467ff0d9b9cb64c81328fcf18295f9be06b2d81bb98874067` | | port-2 (r1-port; its `### setup.sh` block is the setup script) | `e8c967d6358da0fd53117891357f19a1d684225bd71a5e302b6e299c85f1286c` | | net-1, net-2, spline-1, fixed-net, smooth-2d | `66ed32a0…`, `d0143e10…`, `2e73bea9…`, `cc8778a3…`, `c2fc0b1a…` | | port-2 reruns pb1r, pa1 | `994660cf36b4ec18c58e70eea8ec58910b3f0fef724638d90734207c25150682`, `74085ea53b486fee3d7e04556c95c8315992db002007412130a76a6ca720a618` | | ar2, ar3 (r6-arb) | `d0d470f5137166ccb8ec7573825c45dc4007b2d257cb1a0d01a994b88bcad4a6`, `7d68707ac5f44c85e8821a490566120f76e232763efa290ba8b565c3d3ca486b` | | t03 (`code_zb64`, source sha256 `cb6d945511e1e10af78baa64c2a6cb25806f0998403ce6440654bfc3c70092d9`) | `2333ecf28d4356bd232b85c1e55842e94e1ada05e1cd067830b5625dfdbc5336` | | IB (`code_zb64`, source sha256 `301941829a44bb60977bb28181a5e4bfa6544f3696763f987054789b2611d686`) | `afd5183e9ff3235334e041c00b0cd19079599a2c6464db95f8c1586712105557` | Root merges 1-01, 1-02 and 1-03 (handed as `artifacts/goal/roots/1/0{1,2,3}/result.md`) summarise rounds 1-2, 3-4 and 5-6 respectively and carry the per-item figures quoted here for items whose results were not handed directly (port-3's a1..a4/b1/b2/b4 blocks, trim-1's ta/tb blocks, pa2..pa4, pb2, pb4, p3-b3, spl-128, the compression items, the math items, the lattice probe, arb-2, arb-3). ## 10. What is missing or qualified - **qa3** (qm-2 on 9613824..9614079) had not landed: the qm policy's confirmation is n=1,792, not 2,048. **pb3** (port-2), **qt2** (second qm port into trim-2's shell), **qtr3** (third trim) and **ar1** (size-to-gap classifier) were also still running; their results are not in this report. - **trim-1's block 9608704..9608959** was never run: the item landed twice on non-Linux seats (the Linux-only wheel cannot run there). trim-1's own confirmation is n=1,792; its 14 blocks as a comparator total 3,584 seeds. - **trim-2 was never confirmed on 2,048 seeds**: its confirmation batches were refused twice by the plane because the briefs asked for a command's printed output (the same refusal lost six round-3 and three round-5 batches and burned 7,168 seeds, listed in section 8). - **No direct qt1 vs IB run, and no callback-level comparison between qt1 and qm-2/qtr2.** qt1 vs IB is given by offset; the 1,792-seed figures are transferred to qt1 through the shared reference, as section 1.1 says. - **qm-2's confirmation scores include its 33 OutOfGas callbacks**, which the engine's chunk counters cannot attribute to seeds; they can only have lowered qm-2's numbers. - **Gate F is met on applied fees**, with the one raw-return exception of section 5. - **Gate Q for the qm contracts is inherited** from qm-spline's measurement (rerun once by qm-1 from its contract constants), not re-measured per contract; the decoded tables are byte-identical in every qm contract. - **Lattice**: no contract fits; **qm-net**: failed; **arb classifier**: nothing ported. - Engine peaks are observed maxima on the stated seeds, not bounds: qm-2's rose from 245,140 on 128 seeds to 249,895 on 1,792. qt1's 208,775 and qtr2's 191,661 are 128-seed figures. - Several results had source links the plane could not re-check (named in the root merges); their measurements are the workers' own runs with per-seed CSVs, hashes and harnesses inside the results, and nothing here is independently certified. - The goal's `+2.83 / +3.77 / +4.26 / t03 about +1.45` are replica-vs-HA figures and were not converted to engine numbers; the engine evidence is the paired differences above. ## 11. What the next run should do 1. **Make qtr2 the working shell.** It returns qm-2's fees bit for bit, has the lowest engine peak of the qm contracts (191,661 on 128 seeds, about 53k under the cap) and the smallest runtime among them (19,945 bytes). Before building on it, give it the confirmation this goal could not: two blocks of 1,024 fresh seeds (from 9615360) as 4 x 256 items each, arms qtr2, qt1, trim-1, t03, reporting per-seed CSV, paired n / mean / se / worst5, per-chunk peaks and OutOfGas. That also yields the only direct qt1-vs-qtr2 comparison. Keep every confirm brief free of any request for printed output; the accepted round-4 and round-6 confirm briefs are the model. 2. **Port ar3's posterior quoting into the qm shell, gate Q first.** The replica says +0.566 se 0.0125 with plain tables, 10x any classifier idea, but it is untested with the qm tables (which already use sd): run `realpq.py`'s rule over the decoded qm-spline tables on choose 60000..61023 and report 10000..12047 before writing Solidity. If it holds at or near +0.5, port the 2-lookup variant (qs=0, +0.49 on choose) into qtr2: two extra ask+bid surface evaluations cost roughly 70-85k gas at qm-1's measured rates, which qtr2's headroom cannot absorb without the per-span precomputed bases qt1 and qtr1 identified (binary knot search about 2.3k per basis evaluation, coefficient dispatch about 360 gas per word, shared ask/bid bases). Gate F against a `realpq`-style reference, then 2 x 1,024 vs qt1; the bar is +0.3 over qt1 at peak <= 245,000 and 0 OutOfGas. 3. **qm tables: done.** The remaining qm loss is 0.063 (spline vs full); a 12,279-byte profile (28,12,4 / 28,16,4 / 20,12,4 / 26,14,4 / 12,8,4) was never scored and would cost about 2 KB of runtime, so it is the only cheap table improvement left, worth at most the 0.063. 4. **Lattice: not inside this gas budget.** The exact port peaks at 10.5M gas and the best measured reduction at 258k in pyrevm before the engine overhead and before any table lookup. A lattice that fits needs a new design (21 cells x 10 bps, a 3-sigma kernel cut, a skip threshold, one sigma*sqrt(n) diffusion for silent steps), measured on pyrevm first; budget two probe items before any port, and expect at most the +0.49 the README gives lattice+qm over Gaussian+qm, minus the reductions' -0.04 to -0.18. 5. **Process rules that cost this goal items**: every Linux brief must say to return blocked at once on a non-Linux seat; never ask a worker for a command's text; 256 seeds x 4 arms fits one item on 6-8 cores (about 0.3-0.8 s per seed per arm); a result that carries a 40 KB contract needs `output.maxBytes` of 64,000; the setup script is the `### setup.sh` block of port-2's result.