# trim-1: net-1 gas trim, policy unchanged The trimmed contract passes the requested checks: **engine afterSwap peak 232,889 gas, zero OOG; Gate F peak 183,373 gas; deployed 16,077 bytes**. Fees implement net-1’s unchanged Net2 policy. The 12 individual silent-step truncations remain. No aggregate-silent-step fallback, network retraining, weight repacking, clipping change, or Python-reference change was used. Starting source: [net-1](https://api.imd.fun/artifacts/66ed32a0fd17a43295542d22510b004a5323688a74b4321629ae875bb4592e55), SHA-256 `5c40c67a9c5c3c2cb3f1aea95d6f605ef110a87b7674759b65836b5c9ec1609f`. Its published engine peak was 245,377 gas. Taylor (**gtmcknight**) is credited in the contract header for the solved Gaussian policy; see the [pinned README](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/README.md). Filter/reference ancestry: [port-3](https://api.imd.fun/artifacts/0dbcc10af41b3c3467ff0d9b9cb64c81328fcf18295f9be06b2d81bb98874067); network payload: [fixed-net](https://api.imd.fun/artifacts/cc8778a3d8f1f86ffbfc77e971b5ed598b27fee68d61c338e8f3cb2057a363d0). New figures below are local measurements from the supplied setup, not upstream claims or independent certification. ## Changes measured on one fixed trace Every row replays the same first 2,000 reference-driven callbacks from replica seed 70012 on a fresh deployment. Each version’s peak occurs at zero-based callback 242. Savings are incremental, including compiler effects, under the pinned compiler settings. | Version / cumulative change | pyrevm peak | Gas saved from preceding row | |---|---:|---:| | Original net-1 | 197,653 | — | | v1: centered log range and unrolled 19th-order series | 186,425 | 11,228 | | v2: replace update’s memory Work struct with local variables | 185,218 | 1,207 | | v3: simplify CDF tail’s fixed-point product/division | 184,602 | 616 | | v4 (shipped): share the current-step square root | 183,373 | 1,229 | Total saving on this trace: **14,280 gas**. The exact model/fee/rnd source region (from `OFF` through `fees`) is byte-for-byte unchanged from net-1. The log reduction first brings x into [1,2), then divides by two above sqrt(2), so y=(x−1)/(x+1) has |y|≤0.171573. Terms through y^19 replace the old terms through y^29 on the wider interval. The omitted real-arithmetic log tail is bounded by 8.23×10⁻¹⁸; fixed-point rounding is separately covered by Gate F. The series is unrolled to remove loop overhead. The CDF keeps Hart’s same coefficients and density. It evaluates `floor(floor(density*C/U)*n/d)` instead of `floor(floor(density*C/U)*floor(n*U/d)/U)`, eliminating a multiplication/division and changing only fixed-point rounding. On its |x|≤8 branch, n≤84,828,131,075,305,897,088,000, so the new intermediate is below 8.49×10⁴⁰, far below int256’s limit. The current-step likelihood and truncation now share sqrt(v); silent steps still compute their individual roots and truncations. Numerical fees are tolerance-equivalent, not claimed bit-identical. ## Setup and gates Cloned amm-challenge at `6b6921f8d463314aa7c96234e1be25a25245f704` under test/scratch; copied port-3’s Setup script verbatim to checkout scratch/setup.sh and ran it once. It exited 0, wheel SHA-256 matched `aedb68280aca34c110968f00148387c95885207913fb2cf19a1ab4c5cfd6887a`, and StarterStrategy validated. Later runtime commands sourced scratch/env.sh. No setup failure occurred. Solc 0.8.24, optimizer enabled/runs=200, viaIR=true, Paris EVM: [pinned compiler](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/evm/compiler.py). Before modifying the contract, unmodified [gates.py](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/gates.py) under plain `python3 -I` reproduced: ```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 ``` **Gate F: pass.** Reference = unchanged netref.Net2 from [net-1](https://api.imd.fun/artifacts/66ed32a0fd17a43295542d22510b004a5323688a74b4321629ae875bb4592e55), over unchanged standalone.Coarse from [port-3](https://api.imd.fun/artifacts/0dbcc10af41b3c3467ff0d9b9cb64c81328fcf18295f9be06b2d81bb98874067), with the 2,730-byte [fixed-net payload](https://api.imd.fun/artifacts/cc8778a3d8f1f86ffbfc77e971b5ed598b27fee68d61c338e8f3cb2057a363d0), SHA-256 `9727ecc8acf6d31732793d1836c60cd637133b800bbe61b19098bfee7d17e0f6`. Only netref’s filesystem import path was adjusted. No formulas changed in Python. For each seed 70000..70049, Net2 drives the pinned [replica2.py](https://raw.githubusercontent.com/gtmcknight/amm-sim/4812a6382311624e1506aca131ca35c378f930d9/research/solved/replica2.py). Record the first 2,000 own-pool callbacks, then stop the replica. Replay each run on a fresh pyrevm deployment; initialize with 100/10,000, encode amounts/reserves with int(float×10¹⁸), and give **245,000 gas to every call**. All 100,000 callbacks succeeded; compare both returned fees (200,000 comparisons), excluding initialization from callback means. | Gate F metric | Measured | |---|---:| | Runs / callbacks | 50 / 100,000 | | Maximum absolute fee difference, bps | 5.05300228743e-09 | | Mean absolute fee difference, bps | 1.89480689392e-10 | | Initialization maximum difference, bps | 1.56125112838e-13 | | pyrevm afterSwap peak | 183,373 | | pyrevm afterSwap mean | 95691.13779 | Trace-set digest: SHA-256 of concatenated, seed-ordered per-run SHA-256 hex strings = `593d45dfe80600789f119df1cfd3041abdc00708a5f5cd79ab39b88816f79031`. Per-run hash input is JSON `{"init": fees, "rec": [[args, fees], ...]}` with compact separators; the replay harness below specifies encoding. **Gate Q was not rerun:** tables/weights and Python policy are unchanged. [Net-1](https://api.imd.fun/artifacts/66ed32a0fd17a43295542d22510b004a5323688a74b4321629ae875bb4592e55) explicitly reports its 2-pass Q comparison against full tables as incomplete. This trim does not close that inherited quality-evaluation gap, and makes no claim to have met the parent port’s Q gate. Runtime size **16,077 / 24,576 bytes**. No assembly in Strategy.sol. `amm-match validate scratch/v4.sol` returned exit 0 and: ```text Strategy 'TaylorGaussianPlainNet2' validated successfully! ``` ## Engine: assigned seeds only Each contract ran alone against the 30 bps VanillaStrategy via `amm_sim_rs.run_batch(X, VanillaStrategy, configs, 8)`. Each used seeds **9530000..9530127 exactly once**, four chunks of 32; no engine reruns. v4 was fixed before the first engine chunk. Each process called gas_stats_reset() immediately before and gas_stats() immediately after its chunk. Configs reproduce [MatchRunner._build_configs](https://raw.githubusercontent.com/benedictbrady/amm-challenge/6b6921f8d463314aa7c96234e1be25a25245f704/amm_competition/competition/match.py): seed-i NumPy RNG, draws in size/rate/sigma order, base-config fields otherwise. Comparators decoded as zlib(base64(code_zb64)) from [t03](https://api.imd.fun/artifacts/2333ecf28d4356bd232b85c1e55842e94e1ada05e1cd067830b5625dfdbc5336), SHA-256 `cb6d945511e1e10af78baa64c2a6cb25806f0998403ce6440654bfc3c70092d9`, and [IB](https://api.imd.fun/artifacts/afd5183e9ff3235334e041c00b0cd19079599a2c6464db95f8c1586712105557), SHA-256 `301941829a44bb60977bb28181a5e4bfa6544f3696763f987054789b2611d686`. Both hashes matched. Paired differences use submission edge, trim minus comparator. SE = sample SD of differences / sqrt(n). `worst5` lists the five smallest differences, not their average. | Pair | n | mean_diff | se | worst5 (seed, diff) | |---|---:|---:|---:|---| | trim − t03 | 128 | +1.156616422222 | 0.120982583893 | (9530101, -2.647106693789), (9530114, -1.731658559698), (9530048, -1.662802043379), (9530123, -1.617353685042), (9530008, -1.015214939730) | | trim − IB | 128 | +1.876940413066 | 0.132231865497 | (9530101, -3.025809391999), (9530048, -1.303114241437), (9530123, -1.193574863427), (9530114, -0.921806224300), (9530111, -0.860892904208) | Mean submission edges: port 531.056096124521, t03 529.899479702299, IB 529.179155711455. ### gas_stats: Submission afterSwap Means are sum_ok_gas / ok across all four chunks; peaks are maxima, not averages. All listed calls succeeded. Revert, other_halt, tx_error and bad_return are all zero. | Strategy | Calls | OOG | Peak | Mean | sum_ok_gas | |---|---:|---:|---:|---:|---:| | port | 1,376,738 | 0 | 232,889 | 131551.73645530 | 181112274544 | | t03 | 1,381,095 | 0 | 235,394 | 135636.27057806 | 187326575114 | | IB | 1,370,724 | 0 | 234,837 | 135309.90622839 | 185472535905 | Trim afterInitialize: 128 calls, peak/mean 140,363; getName: 128 calls, peak/mean 21,515; both have zero failures. Engine and pyrevm gas are reported separately because their call-accounting overhead differs. Chunk accounting (each range has 32 seeds): | Strategy | First seed | Calls | Peak | OOG | |---|---:|---:|---:|---:| | port | 9530000 | 343466 | 232889 | 0 | | port | 9530032 | 347976 | 224798 | 0 | | port | 9530064 | 335251 | 231730 | 0 | | port | 9530096 | 350045 | 220782 | 0 | | t03 | 9530000 | 344491 | 232517 | 0 | | t03 | 9530032 | 348680 | 235394 | 0 | | t03 | 9530064 | 337289 | 232506 | 0 | | t03 | 9530096 | 350635 | 232494 | 0 | | IB | 9530000 | 342267 | 231894 | 0 | | IB | 9530032 | 345706 | 234837 | 0 | | IB | 9530064 | 334992 | 231781 | 0 | | IB | 9530096 | 347759 | 211541 | 0 | ### Per-seed engine edges Rounded here to 9 decimals; statistics above use unrounded values. ```csv seed,trim,t03,IB 9530000,569.282427154,567.571752814,566.120515173 9530001,594.196145621,590.778708763,590.427373132 9530002,480.990755620,480.926536186,480.406167503 9530003,467.174686758,467.011028070,466.241389533 9530004,532.371865170,531.767956670,530.491576727 9530005,517.310442054,515.753251882,516.324653845 9530006,519.634526897,519.931882041,520.169697842 9530007,769.763133955,765.286646440,762.685319705 9530008,591.205949483,592.221164423,591.665187095 9530009,435.934146018,435.706420100,435.191050616 9530010,496.689842740,495.668138245,494.968796032 9530011,449.501019609,448.371826654,447.586991295 9530012,581.498826278,579.460752737,578.990863991 9530013,515.067981528,514.534255952,513.603218027 9530014,721.678640004,718.706266522,717.974214275 9530015,573.178383422,570.703601723,570.283767358 9530016,405.978018335,404.619511485,404.535926664 9530017,418.408604152,418.273781007,417.375634695 9530018,614.600759166,614.550353493,613.228690464 9530019,462.764672691,463.618730037,462.796601988 9530020,513.117426758,511.795424070,510.683305624 9530021,506.455553023,503.000521809,502.638256538 9530022,383.963501264,383.386216013,383.651060752 9530023,522.858151900,521.603746108,520.238182620 9530024,574.305872791,572.892607584,572.238688942 9530025,662.936358147,660.927537793,660.081178322 9530026,484.583071828,483.259914292,482.821835967 9530027,534.155624830,531.636820439,530.694994057 9530028,489.886005790,490.066298622,489.197987359 9530029,388.832630812,388.724173731,387.705508924 9530030,473.210177127,474.054398644,473.287713306 9530031,364.724684502,365.430521404,364.063117471 9530032,433.629843046,433.549807827,433.269216487 9530033,451.776700251,451.888836596,451.636996559 9530034,578.096942591,575.942923192,575.080766609 9530035,633.889699986,631.867829268,631.405043826 9530036,570.476917357,569.964176804,568.566021269 9530037,626.079529113,622.177027517,620.234755381 9530038,649.417328422,648.407575471,646.864509037 9530039,398.164460954,398.418008798,397.836750736 9530040,599.345808903,596.446649550,595.925228719 9530041,416.222319536,415.300833595,415.823553395 9530042,421.532435055,419.714703534,418.728699253 9530043,490.980822599,489.775870916,488.481044537 9530044,364.524192216,364.525977385,364.395691174 9530045,449.058183672,449.639652468,448.392907897 9530046,639.343826026,634.984762207,635.756313215 9530047,607.479227593,605.528900169,604.571369054 9530048,747.615668528,749.278470571,748.918782770 9530049,411.030427802,411.621454603,410.493527148 9530050,636.946808002,635.473379115,635.340199224 9530051,483.164896750,483.002609981,482.630376897 9530052,605.170221038,605.927941957,604.714681546 9530053,442.691935587,441.587397003,441.970863198 9530054,469.362152163,468.524873472,466.992766054 9530055,509.287445502,507.015239437,506.861276495 9530056,780.325874901,776.596061370,775.487288644 9530057,556.066991709,554.074131113,553.059517201 9530058,404.872802924,404.816472731,403.419287011 9530059,586.351218568,585.163033184,583.795460057 9530060,422.675460374,422.077274812,421.141580588 9530061,507.976176927,507.017815147,506.404348786 9530062,637.789471820,634.087434811,632.952717516 9530063,707.911110572,707.237235554,706.197800942 9530064,498.409837338,499.045541760,497.520406945 9530065,472.204164382,471.432311238,469.811181970 9530066,509.738763277,506.428837903,507.054535269 9530067,519.230193579,518.964616459,517.093503687 9530068,445.985360729,445.579672513,444.623642269 9530069,490.455327611,490.365108756,488.259889336 9530070,561.774813785,560.477731277,559.562278156 9530071,466.776435154,465.837198147,464.541250850 9530072,407.525999897,407.810290537,407.027986698 9530073,383.002709526,382.228918732,382.547963838 9530074,487.352014668,487.178131676,486.665032163 9530075,429.469511807,428.058557639,427.641483649 9530076,530.676868980,529.627989210,528.799510035 9530077,400.788512124,401.005168553,400.259665885 9530078,494.049760283,492.504210124,491.670047284 9530079,488.316179085,487.997548325,486.961774869 9530080,655.872420694,653.743711382,653.555610990 9530081,545.198847638,542.882435727,541.686993664 9530082,631.743084974,632.625888391,631.052981157 9530083,495.970428963,493.784555033,493.008973126 9530084,473.766603744,472.594176651,472.296822125 9530085,682.489299614,680.331745616,679.226431984 9530086,597.875557133,592.479416009,592.210675880 9530087,543.012093033,539.924204906,538.884175995 9530088,406.254175372,405.094933252,403.973187791 9530089,720.669940635,718.244961825,717.036539981 9530090,723.502178671,723.316610135,721.526048706 9530091,632.973754432,631.948810435,630.399557328 9530092,539.834605238,537.145238025,537.603248526 9530093,490.493151565,490.014341252,489.850490528 9530094,704.739253022,702.995155256,702.114256899 9530095,487.155794544,485.080149784,484.761231219 9530096,669.474377065,666.340772091,665.720996845 9530097,472.234006451,470.778240040,470.042874416 9530098,533.311326099,532.001361652,530.281386313 9530099,592.176026046,590.482675021,590.309418966 9530100,385.077634700,384.827374873,384.617213878 9530101,535.072007354,537.719114047,538.097816746 9530102,661.427754878,659.208149539,658.816782098 9530103,534.517352432,533.671270562,532.835137469 9530104,435.529735163,434.867563256,434.046534235 9530105,528.747055692,528.020169033,527.251863459 9530106,638.458488999,635.708689248,635.822159202 9530107,523.064981482,520.361080452,520.158624944 9530108,573.305226619,572.613783926,571.662696249 9530109,450.128028403,450.122956906,448.647903702 9530110,574.299608701,571.235566460,571.132298522 9530111,615.802980093,615.580098360,616.663872997 9530112,547.930020499,546.983290612,547.486703920 9530113,547.934635015,546.077502702,545.479550767 9530114,535.065283851,536.796942410,535.987090075 9530115,558.944746329,557.734050838,557.890845419 9530116,589.873103401,588.052427738,587.855847098 9530117,491.037163647,490.473191712,489.957954277 9530118,664.206428247,662.489472950,662.261385785 9530119,442.190437489,442.791812284,442.740106541 9530120,364.809495710,364.561408583,364.635267277 9530121,512.796113333,510.748991864,510.565290603 9530122,633.718628547,631.786188039,629.433928329 9530123,358.947454788,360.564808473,360.141029651 9530124,496.776174148,494.874077735,493.411584341 9530125,489.293607050,488.089259952,487.015245309 9530126,553.397071998,551.252160188,549.153087896 9530127,692.808922295,689.695677911,689.863247867 ``` ## Strategy.sol — complete, verbatim UTF-8 source SHA-256: `d849c5f15d69499560b5c3ea08f55ad27153b393eba7abb7dd186f451ad46a24`. The code block includes the final newline; source length 34,507 bytes. Import the unchanged base contracts from the pinned challenge. No external runtime library or table installation is needed. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {AMMStrategyBase} from "./AMMStrategyBase.sol"; import {TradeInfo} from "./IAMMStrategy.sol"; // Gaussian solved policy by Taylor (gtmcknight), amm-sim 4812a638; filter ported from port-3. // Offsets: fixed-net 4-32-32-1 int16 MLP (payload sha256 9727ecc8...), integer forward pass, // shifts 12,10,12, Q14 activations, arithmetic-shift floor. 2 passes: ask net(w,R,phase), bid net(-w,-R,phase), inputs clamped to the grid. // Model data: PUSH32 immediates (33-byte blocks); hidden layers as 4x64-bit lanes per word, // lane = bias + 2^63 + sum(w*x), exact mod 2^256. // Taylor source: https://github.com/gtmcknight/amm-sim/tree/4812a6382311624e1506aca131ca35c378f930d9/research/solved contract Strategy is AMMStrategyBase { int256 constant U=1e18; int256 constant LN2=693147180559945309; struct Belief { int256 m; int256 v; int256 fb; int256 fa; int256 sp; int256 r; uint256 t; uint256 cnt; } function getName() external pure override returns(string memory) { unchecked {return "TaylorGaussianPlainNet2";} } 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++;} // Reduce to [1/sqrt(2),sqrt(2)]; |y| <= 0.171573. if(x>1414213562373095048){x/=2;k++;} int256 y=divi(x-U,x+U); int256 y2=mul(y,y); int256 q=y; z=y; q=mul(q,y2);z+=q/3; q=mul(q,y2);z+=q/5; q=mul(q,y2);z+=q/7; q=mul(q,y2);z+=q/9; q=mul(q,y2);z+=q/11; q=mul(q,y2);z+=q/13; q=mul(q,y2);z+=q/15; q=mul(q,y2);z+=q/17; q=mul(q,y2);z+=q/19; 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=(density*2506628274631000200/U)*n/d;return x>0?U-tail:tail; } } function trunc(int256 m,int256 v,int256 lo,int256 hi) internal pure returns(int256,int256,int256){ return truncSD(m,v,lo,hi,root(v)); } function truncSD(int256 m,int256 v,int256 lo,int256 hi,int256 sd) internal pure returns(int256 Z,int256 mt,int256 vt){ unchecked { if(v<=0)return (lo<=m&&m<=hi?U:int256(0),m,0); 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>2]>>((j&3)*64)&M64)-int256(OFF))>>sh;if(v>0)h[j]=uint256(v);} } } function l1a(uint256[32] memory h,uint256[8] memory Z) internal pure { unchecked { uint256 z0=0x800000000006123180000000003472d880000000005317db8000000000000000;uint256 z1=0x80000000001757687fffffffffe760cc7fffffffffd9ca8e800000000021ed28;uint256 v; v=h[0];if(v!=0){z0+=0x0000000000000016fffffffffffffe3800000000000001000000000000000400*v;z1+=0x0000000000000015fffffffffffff1a80000000000000099ffffffffffffffeb*v;} v=h[1];if(v!=0){z0+=0x000000000000009d00000000000000cbffffffffffffffd20000000000000000*v;z1+=0xffffffffffffffd7ffffffffffffff8a000000000000000effffffffffffffc9*v;} v=h[2];if(v!=0){z0+=0x0000000000000091ffffffffffffff7600000000000000790000000000000000*v;z1+=0x000000000000000000000000000000ab00000000000000edffffffffffffffb7*v;} v=h[3];if(v!=0){z0+=0xffffffffffffff99ffffffffffffff3800000000000000d40000000000000000*v;z1+=0xffffffffffffff5100000000000000e7ffffffffffffff3efffffffffffffd71*v;} v=h[4];if(v!=0){z0+=0x00000000000000a9000000000000013500000000000001370000000000000000*v;z1+=0xffffffffffffff86fffffffffffffffa000000000000004dffffffffffffffac*v;} v=h[5];if(v!=0){z0+=0xffffffffffffff6effffffffffffff49fffffffffffffe520000000000000000*v;z1+=0x00000000000000ac00000000000000dfffffffffffffff8effffffffffffffcd*v;} v=h[6];if(v!=0){z0+=0x000000000000004affffffffffffff1800000000000000320000000000000000*v;z1+=0xffffffffffffff79000000000000007f00000000000000a9ffffffffffffffdd*v;} v=h[7];if(v!=0){z0+=0xffffffffffffff95ffffffffffffff1efffffffffffffab80000000000000000*v;z1+=0x0000000000000004fffffffffffffe8d000000000000014f0000000000000127*v;} v=h[8];if(v!=0){z0+=0xffffffffffffffcb000000000000006cfffffffffffffcef0000000000000000*v;z1+=0xffffffffffffffecffffffffffffffe200000000000000eeffffffffffffffe4*v;} v=h[9];if(v!=0){z0+=0x0000000000000067000000000000005600000000000001420000000000000000*v;z1+=0xffffffffffffffc900000000000000cb00000000000000180000000000000042*v;} v=h[10];if(v!=0){z0+=0x0000000000000048ffffffffffffff2600000000000000f70000000000000000*v;z1+=0xffffffffffffffe6ffffffffffffff6dffffffffffffff6000000000000000a8*v;} v=h[11];if(v!=0){z0+=0x000000000000005fffffffffffffffd300000000000000d20000000000000000*v;z1+=0xfffffffffffffffc00000000000000bcffffffffffffff6affffffffffffff5d*v;} v=h[12];if(v!=0){z0+=0x000000000000005b00000000000000b000000000000000830000000000000000*v;z1+=0x0000000000000003000000000000002cffffffffffffff13000000000000007e*v;} v=h[13];if(v!=0){z0+=0xfffffffffffffff3fffffffffffffe99ffffffffffffeb070000000000000000*v;z1+=0xfffffffffffffff3ffffffffffffff0e00000000000002caffffffffffffffcf*v;} v=h[14];if(v!=0){z0+=0xffffffffffffffedffffffffffffffde000000000000018e0000000000000000*v;z1+=0xffffffffffffff6ffffffffffffffff20000000000000010ffffffffffffffd0*v;} v=h[15];if(v!=0){z0+=0x000000000000007cffffffffffffff59ffffffffffffff820000000000000000*v;z1+=0xffffffffffffffdcffffffffffffff4b000000000000009e0000000000000047*v;} v=h[16];if(v!=0){z0+=0x000000000000001300000000000001a100000000000002e50000000000000000*v;z1+=0xffffffffffffff6f0000000000000077ffffffffffffff57fffffffffffffc1a*v;} v=h[17];if(v!=0){z0+=0xffffffffffffff2e000000000000004dfffffffffffffce40000000000000000*v;z1+=0xffffffffffffff5d0000000000000012000000000000012c0000000000000126*v;} v=h[18];if(v!=0){z0+=0xffffffffffffff90ffffffffffffff6e00000000000000680000000000000000*v;z1+=0x0000000000000012ffffffffffffff4effffffffffffffe20000000000000214*v;} v=h[19];if(v!=0){z0+=0xffffffffffffffa4000000000000005900000000000003ce0000000000000000*v;z1+=0xffffffffffffff92ffffffffffffff97fffffffffffffffb0000000000000097*v;} v=h[20];if(v!=0){z0+=0xffffffffffffff7b00000000000000b8ffffffffffffff200000000000000000*v;z1+=0x000000000000000ffffffffffffff5e10000000000000054000000000000007b*v;} v=h[21];if(v!=0){z0+=0x000000000000016e0000000000000085ffffffffffffff050000000000000000*v;z1+=0x0000000000000055fffffffffffffed1ffffffffffffffb3ffffffffffffffc5*v;} v=h[22];if(v!=0){z0+=0xffffffffffffff86000000000000007700000000000000070000000000000000*v;z1+=0xffffffffffffff9d0000000000000119ffffffffffffff89ffffffffffffffe6*v;} v=h[23];if(v!=0){z0+=0x00000000000000ef0000000000000134fffffffffffffeaa0000000000000000*v;z1+=0xffffffffffffff6dffffffffffffffb7ffffffffffffff62ffffffffffffff82*v;} v=h[24];if(v!=0){z0+=0xffffffffffffff5cffffffffffffff32fffffffffffffbcf0000000000000000*v;z1+=0x0000000000000099ffffffffffffffeb00000000000000cf0000000000000138*v;} v=h[25];if(v!=0){z0+=0xfffffffffffffff2000000000000000d000000000000010b0000000000000000*v;z1+=0x0000000000000024fffffffffffffe2affffffffffffff690000000000000001*v;} v=h[26];if(v!=0){z0+=0x0000000000000026ffffffffffffffe000000000000000e30000000000000000*v;z1+=0xffffffffffffff8affffffffffffffbb00000000000000130000000000000051*v;} v=h[27];if(v!=0){z0+=0xfffffffffffffebbfffffffffffffebffffffffffffffff50000000000000000*v;z1+=0xffffffffffffff66000000000000015400000000000001410000000000000052*v;} v=h[28];if(v!=0){z0+=0x000000000000002dffffffffffffff8800000000000000920000000000000000*v;z1+=0xffffffffffffffa5ffffffffffffff63000000000000005b0000000000000013*v;} v=h[29];if(v!=0){z0+=0xffffffffffffff610000000000000126000000000000008c0000000000000000*v;z1+=0xffffffffffffffb4000000000000005500000000000000140000000000000007*v;} v=h[30];if(v!=0){z0+=0x00000000000000b100000000000000d200000000000001370000000000000000*v;z1+=0x000000000000002300000000000000d3ffffffffffffff3d00000000000000bb*v;} v=h[31];if(v!=0){z0+=0xffffffffffffffe0000000000000008700000000000000cb0000000000000000*v;z1+=0x0000000000000059ffffffffffffffddfffffffffffffff1ffffffffffffff61*v;} Z[0]=z0;Z[1]=z1; } } function l1b(uint256[32] memory h,uint256[8] memory Z) internal pure { unchecked { uint256 z2=0x80000000000a369e8000000000213d6f7fffffffffcc127d7ffffffffff6c278;uint256 z3=0x800000000004039f8000000000058c4480000000001f872880000000001b4632;uint256 v; v=h[0];if(v!=0){z2+=0x000000000000008afffffffffffffe71ffffffffffffff81000000000000005f*v;z3+=0x00000000000001060000000000000087ffffffffffffff39000000000000000e*v;} v=h[1];if(v!=0){z2+=0xfffffffffffffcefffffffffffffffe900000000000000a1fffffffffffffe6b*v;z3+=0x0000000000000002fffffffffffffe65ffffffffffffff85000000000000008b*v;} v=h[2];if(v!=0){z2+=0xffffffffffffffba0000000000000080ffffffffffffffb8ffffffffffffff2a*v;z3+=0x00000000000000a2fffffffffffffdd300000000000000030000000000000193*v;} v=h[3];if(v!=0){z2+=0xffffffffffffff0f0000000000000042fffffffffffffffeffffffffffffff8d*v;z3+=0xfffffffffffffffc00000000000000db000000000000007bfffffffffffffeaf*v;} v=h[4];if(v!=0){z2+=0xfffffffffffffff6ffffffffffffff6fffffffffffffff26fffffffffffffdc5*v;z3+=0xffffffffffffffd8fffffffffffffb63fffffffffffffd03ffffffffffffffef*v;} v=h[5];if(v!=0){z2+=0x0000000000000123000000000000001700000000000000640000000000000110*v;z3+=0x000000000000003a00000000000000b6ffffffffffffff340000000000000016*v;} v=h[6];if(v!=0){z2+=0xfffffffffffffdacfffffffffffffef0000000000000002ffffffffffffffe8c*v;z3+=0x000000000000007ffffffffffffffee3000000000000000dffffffffffffffb0*v;} v=h[7];if(v!=0){z2+=0xffffffffffffe7a2ffffffffffffff4b0000000000000147ffffffffffffe6f3*v;z3+=0x0000000000000026fffffffffffffe71fffffffffffffc2100000000000000ae*v;} v=h[8];if(v!=0){z2+=0x000000000000007afffffffffffffff4000000000000013a00000000000000bc*v;z3+=0x000000000000003800000000000000affffffffffffffcf9ffffffffffffff6b*v;} v=h[9];if(v!=0){z2+=0x000000000000000c0000000000000031000000000000004300000000000000b5*v;z3+=0xffffffffffffff8a000000000000004f00000000000000c6000000000000008a*v;} v=h[10];if(v!=0){z2+=0xffffffffffffff0c000000000000008b0000000000000048fffffffffffffe8d*v;z3+=0x000000000000001d000000000000011affffffffffffff9400000000000000ce*v;} v=h[11];if(v!=0){z2+=0xffffffffffffffbc00000000000000c8ffffffffffffffca000000000000005c*v;z3+=0xffffffffffffffd6ffffffffffffffc2000000000000018affffffffffffff77*v;} v=h[12];if(v!=0){z2+=0x000000000000004000000000000000c4ffffffffffffff50ffffffffffffff11*v;z3+=0x00000000000000dbffffffffffffff9b0000000000000026000000000000000e*v;} v=h[13];if(v!=0){z2+=0xffffffffffffffc4fffffffffffff7ed0000000000000170000000000000007f*v;z3+=0xffffffffffffff6b00000000000000e1fffffffffffff95f000000000000000f*v;} v=h[14];if(v!=0){z2+=0x000000000000013c0000000000000067fffffffffffffd7700000000000000cf*v;z3+=0x000000000000001b000000000000010400000000000000b90000000000000026*v;} v=h[15];if(v!=0){z2+=0xffffffffffffff4affffffffffffff09fffffffffffffffdffffffffffffff39*v;z3+=0x0000000000000049ffffffffffffffe600000000000000650000000000000091*v;} v=h[16];if(v!=0){z2+=0xfffffffffffffc560000000000000033fffffffffffffdf7fffffffffffffd38*v;z3+=0x000000000000001efffffffffffffeb8000000000000009e00000000000000b9*v;} v=h[17];if(v!=0){z2+=0xffffffffffffffe0fffffffffffffeaa00000000000001e3000000000000014d*v;z3+=0xffffffffffffff55fffffffffffffdb4ffffffffffffff2a0000000000000090*v;} v=h[18];if(v!=0){z2+=0xfffffffffffffe330000000000000165ffffffffffffffdc000000000000038d*v;z3+=0xffffffffffffffaf000000000000012d000000000000032dffffffffffffff68*v;} v=h[19];if(v!=0){z2+=0xffffffffffffff44ffffffffffffffd7000000000000007ffffffffffffffed5*v;z3+=0x0000000000000013fffffffffffffd38000000000000003f0000000000000029*v;} v=h[20];if(v!=0){z2+=0x0000000000000064ffffffffffffff20000000000000013900000000000000b1*v;z3+=0xffffffffffffff56000000000000001100000000000000d000000000000000e8*v;} v=h[21];if(v!=0){z2+=0x000000000000012effffffffffffff9200000000000000bc00000000000000e5*v;z3+=0x00000000000000a20000000000000067ffffffffffffff97ffffffffffffffa8*v;} v=h[22];if(v!=0){z2+=0x0000000000000118ffffffffffffff9f00000000000000930000000000000088*v;z3+=0xffffffffffffff140000000000000086ffffffffffffff79fffffffffffffffe*v;} v=h[23];if(v!=0){z2+=0x00000000000000d40000000000000090ffffffffffffff2900000000000001a4*v;z3+=0xffffffffffffffe900000000000000a8ffffffffffffffabffffffffffffffb9*v;} v=h[24];if(v!=0){z2+=0xfffffffffffffde2fffffffffffffe26000000000000011e00000000000000f0*v;z3+=0xffffffffffffff0a0000000000000128fffffffffffffe0c000000000000010a*v;} v=h[25];if(v!=0){z2+=0x00000000000001520000000000000124fffffffffffffcd6000000000000000f*v;z3+=0x0000000000000034000000000000006800000000000000c1ffffffffffffff6b*v;} v=h[26];if(v!=0){z2+=0xffffffffffffffe90000000000000052ffffffffffffff660000000000000031*v;z3+=0xffffffffffffffb400000000000000e30000000000000086ffffffffffffffe2*v;} v=h[27];if(v!=0){z2+=0x00000000000000cbfffffffffffffde700000000000003a1000000000000002d*v;z3+=0x0000000000000006000000000000004d00000000000000c9000000000000007e*v;} v=h[28];if(v!=0){z2+=0xfffffffffffffe7500000000000000020000000000000068fffffffffffffecb*v;z3+=0x0000000000000077ffffffffffffff9600000000000000830000000000000080*v;} v=h[29];if(v!=0){z2+=0xffffffffffffff11000000000000023affffffffffffff68ffffffffffffffc6*v;z3+=0x0000000000000077000000000000008f0000000000000097ffffffffffffff6d*v;} v=h[30];if(v!=0){z2+=0x000000000000008f00000000000000cbfffffffffffffeafffffffffffffffd6*v;z3+=0xffffffffffffffc5ffffffffffffffdd00000000000000feffffffffffffffac*v;} v=h[31];if(v!=0){z2+=0x000000000000006c000000000000001cffffffffffffff96ffffffffffffffc4*v;z3+=0x0000000000000055ffffffffffffffd9000000000000012affffffffffffffc6*v;} Z[2]=z2;Z[3]=z3; } } function l1c(uint256[32] memory h,uint256[8] memory Z) internal pure { unchecked { uint256 z4=0x7fffffffffe6afa780000000000cae11800000000027162480000000000e880c;uint256 z5=0x8000000000230d037ffffffffff492f080000000001b1520800000000016278a;uint256 v; v=h[0];if(v!=0){z4+=0x000000000000010cfffffffffffffed7000000000000021bffffffffffffffac*v;z5+=0xfffffffffffffecc0000000000000056fffffffffffffc380000000000000126*v;} v=h[1];if(v!=0){z4+=0xfffffffffffffffa000000000000003e000000000000002d0000000000000069*v;z5+=0x00000000000000090000000000000053000000000000008d0000000000000015*v;} v=h[2];if(v!=0){z4+=0x000000000000009200000000000000b9000000000000008800000000000000bf*v;z5+=0xffffffffffffff44000000000000002100000000000000f5ffffffffffffff6b*v;} v=h[3];if(v!=0){z4+=0x000000000000007cffffffffffffff8e0000000000000073000000000000003f*v;z5+=0x00000000000000ab00000000000000260000000000000134ffffffffffffff28*v;} v=h[4];if(v!=0){z4+=0xfffffffffffffff1fffffffffffffd65ffffffffffffff5dffffffffffffffbe*v;z5+=0xffffffffffffb61affffffffffffff6bffffffffffffffc8ffffffffffffff8d*v;} v=h[5];if(v!=0){z4+=0x00000000000000280000000000000014ffffffffffffff9700000000000000f6*v;z5+=0x0000000000000109ffffffffffffff2bfffffffffffffffe0000000000000139*v;} v=h[6];if(v!=0){z4+=0x000000000000006900000000000000590000000000000072ffffffffffffffba*v;z5+=0xffffffffffffff20000000000000002600000000000000c3ffffffffffffffe9*v;} v=h[7];if(v!=0){z4+=0xffffffffffffffafffffffffffffffe4ffffffffffffff4e00000000000000f3*v;z5+=0xfffffffffffffe5a00000000000000090000000000000006fffffffffffffeea*v;} v=h[8];if(v!=0){z4+=0xfffffffffffffff7000000000000012e000000000000005bffffffffffffff8c*v;z5+=0xfffffffffffffec7000000000000000efffffffffffffecb0000000000000046*v;} v=h[9];if(v!=0){z4+=0x00000000000000dbfffffffffffffe540000000000000011ffffffffffffff46*v;z5+=0x0000000000000072fffffffffffffefa00000000000000ceffffffffffffff3c*v;} v=h[10];if(v!=0){z4+=0x00000000000000e6ffffffffffffffe0000000000000010a0000000000000090*v;z5+=0x000000000000002600000000000000cbffffffffffffff97000000000000001a*v;} v=h[11];if(v!=0){z4+=0x000000000000005f00000000000000b30000000000000061ffffffffffffff92*v;z5+=0x000000000000005f00000000000000b7ffffffffffffffc4fffffffffffffffa*v;} v=h[12];if(v!=0){z4+=0xffffffffffffffb300000000000000aeffffffffffffffbaffffffffffffff9e*v;z5+=0x000000000000005e000000000000002d00000000000000e9ffffffffffffffe8*v;} v=h[13];if(v!=0){z4+=0xffffffffffffff370000000000000093ffffffffffffff8e000000000000002f*v;z5+=0xffffffffffffffb7000000000000007100000000000000b1000000000000007a*v;} v=h[14];if(v!=0){z4+=0xffffffffffffffc30000000000000134000000000000000500000000000000b4*v;z5+=0x000000000000006e00000000000000daffffffffffffffcdfffffffffffffee9*v;} v=h[15];if(v!=0){z4+=0x0000000000000099000000000000004fffffffffffffffd4000000000000001a*v;z5+=0xffffffffffffff2d00000000000000cc00000000000000000000000000000080*v;} v=h[16];if(v!=0){z4+=0x000000000000002affffffffffffffc3ffffffffffffffed00000000000000fd*v;z5+=0x000000000000016bfffffffffffffff400000000000000a600000000000000f9*v;} v=h[17];if(v!=0){z4+=0x0000000000000013000000000000000a00000000000000410000000000000098*v;z5+=0xfffffffffffffefa000000000000009500000000000001590000000000000049*v;} v=h[18];if(v!=0){z4+=0x0000000000000125ffffffffffffff72ffffffffffffff74000000000000003d*v;z5+=0x000000000000001900000000000000020000000000000045ffffffffffffff7a*v;} v=h[19];if(v!=0){z4+=0x00000000000000baffffffffffffff1100000000000000150000000000000028*v;z5+=0x00000000000000b5ffffffffffffffef0000000000000100ffffffffffffffab*v;} v=h[20];if(v!=0){z4+=0xffffffffffffffd600000000000001b5ffffffffffffff730000000000000072*v;z5+=0x00000000000001320000000000000123fffffffffffffedb00000000000000fc*v;} v=h[21];if(v!=0){z4+=0xffffffffffffffa7ffffffffffffff3fffffffffffffff5fffffffffffffff8d*v;z5+=0xffffffffffffffc2ffffffffffffffca00000000000001800000000000000036*v;} v=h[22];if(v!=0){z4+=0xffffffffffffff4cffffffffffffffc300000000000000c30000000000000012*v;z5+=0x000000000000011f00000000000000530000000000000104ffffffffffffff4f*v;} v=h[23];if(v!=0){z4+=0xffffffffffffffeb000000000000003bfffffffffffffdf10000000000000053*v;z5+=0xfffffffffffffff7ffffffffffffff50fffffffffffffbc3000000000000009f*v;} v=h[24];if(v!=0){z4+=0xffffffffffffffc2000000000000000f0000000000000023000000000000008e*v;z5+=0xffffffffffffffb10000000000000048ffffffffffffff9d00000000000000e5*v;} v=h[25];if(v!=0){z4+=0xffffffffffffff46fffffffffffffedbfffffffffffffebc0000000000000042*v;z5+=0x0000000000000012ffffffffffffff3efffffffffffffe9500000000000000ec*v;} v=h[26];if(v!=0){z4+=0x00000000000000370000000000000012ffffffffffffff7effffffffffffff3e*v;z5+=0xffffffffffffffd0ffffffffffffff70000000000000001bffffffffffffffd1*v;} v=h[27];if(v!=0){z4+=0xffffffffffffff65ffffffffffffff72ffffffffffffff830000000000000083*v;z5+=0xfffffffffffffe7fffffffffffffffadfffffffffffffecffffffffffffffebe*v;} v=h[28];if(v!=0){z4+=0xffffffffffffff2700000000000000bc00000000000000baffffffffffffffef*v;z5+=0x000000000000003e000000000000002e0000000000000137000000000000004d*v;} v=h[29];if(v!=0){z4+=0x000000000000003cfffffffffffffe2dffffffffffffff1800000000000000d5*v;z5+=0xfffffffffffffde3fffffffffffffffb00000000000000300000000000000072*v;} v=h[30];if(v!=0){z4+=0x00000000000000640000000000000056ffffffffffffffb2fffffffffffffff4*v;z5+=0xffffffffffffffdeffffffffffffff0e000000000000009fffffffffffffff27*v;} v=h[31];if(v!=0){z4+=0x00000000000000caffffffffffffff380000000000000059000000000000000f*v;z5+=0x00000000000000b40000000000000073000000000000009b0000000000000067*v;} Z[4]=z4;Z[5]=z5; } } function l1d(uint256[32] memory h,uint256[8] memory Z) internal pure { unchecked { uint256 z6=0x80000000002f0d478000000000135811800000000022e38a7fffffffffdbe00a;uint256 z7=0x7ffffffffffc7e3c7fffffffffc394bf7fffffffffd9daa280000000003b67bb;uint256 v; v=h[0];if(v!=0){z6+=0x000000000000007c00000000000000abfffffffffffffff4ffffffffffffff75*v;z7+=0xfffffffffffffffbffffffffffffffabfffffffffffffeacfffffffffffffdd9*v;} v=h[1];if(v!=0){z6+=0xffffffffffffffe4000000000000006fffffffffffffff06ffffffffffffff5a*v;z7+=0xffffffffffffffdafffffffffffffd8900000000000000850000000000000059*v;} v=h[2];if(v!=0){z6+=0x000000000000006300000000000001010000000000000014ffffffffffffff7e*v;z7+=0xffffffffffffffd3000000000000002a0000000000000080000000000000007e*v;} v=h[3];if(v!=0){z6+=0xfffffffffffffe6dffffffffffffffea000000000000004effffffffffffffd0*v;z7+=0xffffffffffffffb5000000000000007d0000000000000028000000000000009c*v;} v=h[4];if(v!=0){z6+=0x0000000000000119000000000000002500000000000000fa0000000000000049*v;z7+=0x0000000000000093ffffffffffffff85000000000000008dffffffffffffffd9*v;} v=h[5];if(v!=0){z6+=0x0000000000000071ffffffffffffff83ffffffffffffffbfffffffffffffff99*v;z7+=0xffffffffffffff8e00000000000000280000000000000102ffffffffffffff0c*v;} v=h[6];if(v!=0){z6+=0x000000000000001800000000000000080000000000000156ffffffffffffff8e*v;z7+=0xffffffffffffff78fffffffffffffc960000000000000067ffffffffffffff25*v;} v=h[7];if(v!=0){z6+=0x0000000000000045fffffffffffffee3ffffffffffffff92ffffffffffffff97*v;z7+=0xffffffffffffff77fffffffffffffd74ffffffffffffff88ffffffffffffff47*v;} v=h[8];if(v!=0){z6+=0xfffffffffffffe29fffffffffffffff50000000000000043ffffffffffffff50*v;z7+=0xffffffffffffff8dffffffffffffff24ffffffffffffff970000000000000032*v;} v=h[9];if(v!=0){z6+=0xffffffffffffffa7ffffffffffffff6dfffffffffffffeb50000000000000000*v;z7+=0xffffffffffffffac00000000000000b3000000000000014a0000000000000058*v;} v=h[10];if(v!=0){z6+=0xfffffffffffffe5500000000000000c3000000000000008bffffffffffffff6f*v;z7+=0xffffffffffffff81ffffffffffffff7affffffffffffffdbffffffffffffffe8*v;} v=h[11];if(v!=0){z6+=0x000000000000004bffffffffffffff9b000000000000005a0000000000000021*v;z7+=0xffffffffffffff6e000000000000008100000000000000c70000000000000034*v;} v=h[12];if(v!=0){z6+=0x0000000000000040000000000000004100000000000000c6ffffffffffffffa5*v;z7+=0x000000000000000a0000000000000091ffffffffffffff990000000000000057*v;} v=h[13];if(v!=0){z6+=0xffffffffffffff92ffffffffffffffa1ffffffffffffff1cffffffffffffff7e*v;z7+=0x0000000000000004fffffffffffffff400000000000000a5fffffffffffffaee*v;} v=h[14];if(v!=0){z6+=0x000000000000000fffffffffffffff5400000000000000a30000000000000012*v;z7+=0xffffffffffffff62ffffffffffffffee000000000000004f0000000000000082*v;} v=h[15];if(v!=0){z6+=0x00000000000000f0ffffffffffffffd6fffffffffffff9f20000000000000042*v;z7+=0xffffffffffffff7efffffffffffffced0000000000000001ffffffffffffff49*v;} v=h[16];if(v!=0){z6+=0x0000000000000151000000000000007200000000000000eeffffffffffffffda*v;z7+=0xffffffffffffff9a000000000000005effffffffffffff6e000000000000007b*v;} v=h[17];if(v!=0){z6+=0x000000000000000cffffffffffffff64ffffffffffffff81ffffffffffffffea*v;z7+=0xffffffffffffff5600000000000001950000000000000107fffffffffffffeb1*v;} v=h[18];if(v!=0){z6+=0x000000000000018cffffffffffffff44fffffffffffffb1cffffffffffffffac*v;z7+=0xffffffffffffffd0000000000000053effffffffffffffa70000000000000026*v;} v=h[19];if(v!=0){z6+=0x000000000000004a0000000000000018ffffffffffffffaf0000000000000039*v;z7+=0x0000000000000096ffffffffffffff8e0000000000000001fffffffffffffff3*v;} v=h[20];if(v!=0){z6+=0x0000000000000060ffffffffffffffec0000000000000209ffffffffffffff51*v;z7+=0x000000000000004ffffffffffffffdf7ffffffffffffff77fffffffffffffff0*v;} v=h[21];if(v!=0){z6+=0xffffffffffffffdeffffffffffffffaeffffffffffffff2b000000000000000d*v;z7+=0xffffffffffffff7fffffffffffffffb9fffffffffffffef6fffffffffffffff1*v;} v=h[22];if(v!=0){z6+=0xffffffffffffff45000000000000003600000000000000d60000000000000091*v;z7+=0xffffffffffffffe5ffffffffffffff5f000000000000005b0000000000000070*v;} v=h[23];if(v!=0){z6+=0x000000000000009100000000000000d5ffffffffffffff2f00000000000000a0*v;z7+=0x0000000000000091000000000000018c0000000000000046000000000000004b*v;} v=h[24];if(v!=0){z6+=0xffffffffffffffc6ffffffffffffff76000000000000002500000000000000ab*v;z7+=0xfffffffffffffff6ffffffffffffff91000000000000001bffffffffffffff01*v;} v=h[25];if(v!=0){z6+=0x0000000000000055ffffffffffffff7bffffffffffffff4effffffffffffff59*v;z7+=0xffffffffffffffda00000000000000a7ffffffffffffff6d0000000000000138*v;} v=h[26];if(v!=0){z6+=0x000000000000010300000000000000c5ffffffffffffff46000000000000002a*v;z7+=0x0000000000000016fffffffffffffe78ffffffffffffffe4000000000000004a*v;} v=h[27];if(v!=0){z6+=0xffffffffffffffc3ffffffffffffffc40000000000000035ffffffffffffff6e*v;z7+=0xffffffffffffffdf0000000000000042fffffffffffffefcfffffffffffffe33*v;} v=h[28];if(v!=0){z6+=0xffffffffffffff760000000000000055fffffffffffffdd7000000000000009a*v;z7+=0xffffffffffffff9cffffffffffffff6b000000000000002effffffffffffff92*v;} v=h[29];if(v!=0){z6+=0xfffffffffffffff600000000000000c7ffffffffffffffc2ffffffffffffffe9*v;z7+=0x000000000000001c0000000000000176fffffffffffffe410000000000000123*v;} v=h[30];if(v!=0){z6+=0x000000000000009a00000000000000840000000000000019000000000000001f*v;z7+=0xffffffffffffff97000000000000004e00000000000000200000000000000019*v;} v=h[31];if(v!=0){z6+=0xfffffffffffffffe0000000000000039ffffffffffffff4c000000000000009b*v;z7+=0xffffffffffffffc500000000000000c300000000000000f7000000000000007a*v;} Z[6]=z6;Z[7]=z7; } } function net(int256 x0,int256 x1,int256 x2) internal pure returns(int256 o){ unchecked { uint256[32] memory h=unpack(l0(uint256(x0),uint256(x1),uint256(x2)),12); uint256[8] memory Z;l1a(h,Z);l1b(h,Z);l1c(h,Z);l1d(h,Z);h=unpack(Z,10); uint256 c=0x000000000000000000000000000000000000000000000000000000000049a2b5;o=int256(int32(uint32(c)));uint256 A=0xfdd5faa709440342061e0ff1f459fa920068e66d07d30259fbcb056cf36f1000;uint256 B=0x029ef90a04790e09046902a8084e00ce0d12032bfb1efa96fd5802b803200293; for(uint256 j=0;j<16;j++){o+=int256(int16(uint16(A>>(16*j))))*int256(h[j])+int256(int16(uint16(B>>(16*j))))*int256(h[j+16]);} o=(o>>12)*6103515625000000; } } function fee(int256 a,int256 w,int256 b) internal pure returns(int256 fb,int256 fa){ unchecked { fb=b> -w?U-exp(-(b+w)/10000):int256(0);fa=a>w?U-exp(-(a-w)/10000):int256(0); fb=clip(fb,0,U/10);fa=clip(fa,0,U/10); } } function rnd(int256 v) internal pure returns(int256){ unchecked {return (v*16384/100+U/2+(int256(1)<<30)*U)/U-(int256(1)<<30);} } function fees(int256 w,int256 r,uint256 ph) internal pure returns(int256,int256){ unchecked { int256 lim=ph==0?30*U:800*U;int256 x0=rnd(clip(w,-800*U,800*U));int256 x1=rnd(clip(r,-lim,lim));int256 x2=int256(ph)*16384; return fee(net(x0,x1,x2),w,net(-x0,-x1,x2)); } } function save(Belief memory b) internal { unchecked { slots[0]=uint256(b.m);slots[1]=uint256(b.v);slots[2]=uint256(b.fb);slots[3]=uint256(b.fa); slots[4]=uint256(b.sp);slots[5]=uint256(b.r);slots[6]=b.t;slots[7]=b.cnt; } } function afterInitialize(uint256 x,uint256 y) external override returns(uint256,uint256){ unchecked { Belief memory b; b.sp=int256(y*1e18/x);b.r=b.sp;b.m=ln(b.sp); b.fb=2870627705508484;b.fa=2870627705508484;save(b);return(uint256(b.fb),uint256(b.fa)); } } function update(Belief memory b,int256 s,bool buy,uint256 dt) internal pure returns(bool arb){ unchecked { int256 lo;int256 hi;int256 m;int256 v;int256 lp;int256 la;int256 Z;int256 mt;int256 vt;int256 d;int256 pi; lo=ln(mul(b.sp,U-b.fb));hi=ln(divi(b.sp,U-b.fa));m=b.m;v=b.v; 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){ b.m=mul(pi,lp)+mul(U-pi,mt); b.v=mul(pi,mul(lp-b.m,lp-b.m))+mul(U-pi,vt+mul(mt-b.m,mt-b.m)); }else if(arb){b.m=lp;b.v=0;}else{b.m=mt;b.v=vt;} int256 pe=exp(b.m);b.r=clip(b.r,mul(pe,997e15),divi(pe,997e15));b.cnt=0; } } function afterSwap(TradeInfo calldata t) external override returns(uint256,uint256){ unchecked { Belief memory b=Belief(int256(slots[0]),int256(slots[1]),int256(slots[2]),int256(slots[3]),int256(slots[4]),int256(slots[5]),slots[6],slots[7]); int256 s=int256(t.reserveY*1e18/t.reserveX);bool arb; if(t.timestamp>b.t)arb=update(b,s,t.isBuy,t.timestamp-b.t); uint256 ph; if(!arb){ int256 c=t.isBuy?divi(mul(s,U-b.fb),997e15):divi(mul(s,997e15),U-b.fa); if(t.isBuy?cb.r)b.r=c; b.cnt++;ph=b.cnt==1?1:2; } int256 w=(ln(s)-b.m)*10000;int256 r=(ln(b.r)-b.m)*10000; (b.fb,b.fa)=fees(w,r,ph);b.sp=s;b.t=t.timestamp;save(b); return(uint256(b.fb),uint256(b.fa)); } } } ``` ## Measurement harnesses These reproduce the measurement logic; they depend on the pinned challenge setup and supplied upstream measurement inputs. They are not contract runtime dependencies. Reference extraction: netref.py from net-1; standalone.py from port-3; payload.bin from fixed-net’s normative base64; replica2.py from Taylor’s pinned solved directory. Place all four beside the replay harness and change netref’s path insertion to that same directory. Python filter/policy content otherwise remains unchanged. Save the shared compiler/call helpers as scratch/check.py (the compiler caches by full source SHA-256): ```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, as used: ```python import sys,json,time,hashlib from pathlib import Path from check import compiled,call,HERE from amm_competition.evm.executor import EVMStrategyExecutor from netref import Net2 import replica2 as R class Stop(Exception): pass def trace(seed): p=HERE/f'trace{seed}.json' if p.exists(): return json.loads(p.read_text()) pol=Net2(); 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 replay(seed,c): d=trace(seed);e=EVMStrategyExecutor(bytes.fromhex(c['creation']));ini=call(e,[100*10**18,10000*10**18],True) imax=max(abs(a-b)*1e4 for a,b in zip(ini,d['init']));diff=[];gas=[] for args,f in d['rec']: buy,ax,ay,t,x,y,*_=args fees=call(e,[buy,int(ax*1e18),int(ay*1e18),t,int(x*1e18),int(y*1e18)]) gas.append(e.evm.result.gas_used);diff.extend(abs(a-b)*1e4 for a,b in zip(fees,f)) return {'seed':seed,'max_diff':max(diff),'sum_diff':sum(diff),'init_max':imax,'peak':max(gas),'peak_i':gas.index(max(gas)),'sum_gas':sum(gas),'n':len(gas),'trace_sha256':hashlib.sha256(json.dumps(d,separators=(',',':')).encode()).hexdigest()} if __name__=='__main__': src=sys.argv[1];a,b=map(int,sys.argv[2:4]);c=compiled(src);out=[] for seed in range(a,b): row=replay(seed,c);out.append(row);print(row,flush=True) (HERE/(Path(src).stem+f'_F{a}_{b}.json')).write_text(json.dumps(out)) ``` scratch/engine.py, as used (paths preserve the measured v4 filename): ```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 9530000<=start