From 54ab30407c93c0548402c616ef78cb3f35c0033d Mon Sep 17 00:00:00 2001 From: Aere Network Date: Sun, 27 Sep 2026 06:36:36 +0300 Subject: [PATCH] verify-anchor.mjs: ANCHOR_REPORT= writes the most recent verified anchor and the parent hash its seals signed, as JSON, for tools that build on it (nothing printed changes) --- tools/verify-anchor.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/verify-anchor.mjs b/tools/verify-anchor.mjs index 949ec5b..74ef485 100644 --- a/tools/verify-anchor.mjs +++ b/tools/verify-anchor.mjs @@ -434,6 +434,7 @@ let unmeasured = 0; // summary so a stranger gets the answer to "which block is final" from this tool, not from our word. Nodes do not serve the // finalized/safe tags on this chain yet (measured 2026-09-26: eth_getBlockByNumber("finalized") answers "Unknown block"). let newestOk = null; +let newestParentHash = null; // the hash of block newestOk - 1 the verified seals signed (M(parent)), for ANCHOR_REPORT // ce scheme au fost CHIAR verificate: rezumatul final nu are voie sa numeasca o schema pe care nu a vazut-o const schemesSeen = new Set(); let cursor = anchor; @@ -517,7 +518,7 @@ for (let i = 0; i < COUNT; i++) { && unknownScheme.length === 0 && unknownIndex.length === 0 && notValidator.length === 0 && noKey.length === 0 && unbound.length === 0; const summary = Object.entries(perScheme).map(([nm, c]) => c + ' ' + nm).join(' + '); - if (good) { ok++; if (newestOk === null) newestOk = h; console.log(h + ' OK: bound under block hash' + (isV2 ? ' (v2, scheme-tagged)' : '') + ', ' + n + ' seals (' + summary + '), all valid and from validators of this height (' + (h - 1 >= KEYS_FROM && v3EpochAt(h - 1) ? 'keys of the registry v3 epoch ' + v3EpochAt(h - 1).bindHeight : 'manifest ' + man.bindHeight) + ')'); } + if (good) { ok++; if (newestOk === null) { newestOk = h; newestParentHash = String(parent.hash).toLowerCase(); } console.log(h + ' OK: bound under block hash' + (isV2 ? ' (v2, scheme-tagged)' : '') + ', ' + n + ' seals (' + summary + '), all valid and from validators of this height (' + (h - 1 >= KEYS_FROM && v3EpochAt(h - 1) ? 'keys of the registry v3 epoch ' + v3EpochAt(h - 1).bindHeight : 'manifest ' + man.bindHeight) + ')'); } else if (envBlocked) { unmeasured++; console.log(h + ' NOT VERIFIED HERE: bound under block hash, ' + falconValid + ' valid falcon-512 seals, but this' @@ -700,6 +701,15 @@ console.log(all + (unmeasured ? ' (' + unmeasured + ' more could not be checked here: npm install @noble/post-quantum)' : ''))); if (newestOk !== null) console.log('FINALIZED (post-quantum): block ' + (newestOk - 1) + ', the parent of anchor ' + newestOk + ', the most recent anchor whose certificate verified here. Nothing between anchors is final; a header between anchors carries only its proposer\'s seal.'); if (!slhDsa) console.log('note: @noble/post-quantum is not installed, so a v2 certificate carrying SLH-DSA seals cannot be verified here (npm install @noble/post-quantum).'); +// ANCHOR_REPORT= (2026-09-27): the most recent anchor that verified here, as JSON, for a tool that builds on it (the AIP-23 proof +// verifier). parentHash is the hash the certificate's seals were verified over, so such a tool can bind the parent header to it by +// re-encoding the header, without a second copy of the certificate check. Written whatever the verdict; a caller also needs exit code 0. +if (process.env.ANCHOR_REPORT) { + try { + fs.writeFileSync(process.env.ANCHOR_REPORT, JSON.stringify({ chainId: CHAIN_ID, anchor: newestOk, parentNumber: newestOk === null ? null : newestOk - 1, + parentHash: newestParentHash }) + '\n'); + } catch (e) { console.error('note: ANCHOR_REPORT could not be written: ' + e.message); } +} // three states, three exit codes: 0 verified, 1 the chain failed a check, 2 this machine could not measure. // exitCode, not process.exit(): on Windows, exiting while the HTTP sockets are still closing aborts node inside libuv // (0xC0000409), and the verdict printed above would reach the caller with a code that is neither 0, 1 nor 2.