@atropyle/circuits
v0.2.0
Published
Atropyle policy circuit: NetlistVM builder, bitsliced simulator, reference model and exhaustive proof.
Readme
@atropyle/circuits
The Atropyle policy circuit for TapeOut on X Layer, plus the tools that prove it:
- a NetlistVM byte-stream builder (
Netlist), and the reusable sub-circuitsKofN5andGe4; - a 32-lane bitsliced simulator (
compile,stepBytes) with the same semantics as the on-chainNetlistVM; - the reference model (
refStep) and an exhaustive check of properties P1–P8 over all 2^26 inputs (verifyPolicy).
import { buildAll, verifyPolicy } from '@atropyle/circuits';
const { program } = buildAll();
const report = verifyPolicy(program);
console.log(report.mismatches === 0 && report.violations.every((v) => v === 0));To check the circuit that is live on chain, use npx -y [email protected] verify or verifyPolicy() from @atropyle/sdk.
Try to break it
Break one gate of a copy of the policy and see the proof catch it. Everything runs on a program in memory: the deployed circuit cannot change.
import { buildAll, faultPath, firstViolation, mutate } from '@atropyle/circuits';
const { program } = buildAll();
const broken = mutate(program, { gate: 120, kind: 'stuck1' }); // or 'stuck0', 'rewire', 'and'
const r = firstViolation(broken.program, { reference: program });
if (r.counterexample) {
const cx = r.counterexample; // state, inputs, next, out, the model's answer, the properties it breaks
console.log(cx.property, cx.story); // P3 inherit-without-votes
console.log(faultPath(program, broken, cx.state, cx.inputs).gates); // the gates the fault runs through
} else {
console.log(r.complete); // true: the copy equals the policy on all 2^26 combinations, so this break changes nothing
}mutate(program, mutation): one gate (0 … 195, NAND gates in run order) stuck at 0, stuck at 1, with input a wired to another signal, or computing AND. The original is not changed.firstViolation(program, options): visits the seed blocks first (POLICY_SEED_BLOCKS, regenerated bynpm run seeds), then every block, and stops at the first counterexample. With no counterexample it has checked all 67,108,864 combinations.verifyPolicyis unchanged.storyOf(counterexample): one plain sentence, true of that counterexample, and the property it is about.isLifelike(case): true when a deployed vault can ask the circuit that case, by the rules of the vault contract (counterexample.lifelike).firstViolationshows such a case first.
test/mutation-score.md classifies all 784 single-gate mutations (196 gates, four kinds) as caught or redundant: 743
caught with a counterexample checked against the reference model, 41 redundant (3 stuck at 1, 38 rewires), where the
copy answers like the policy on all 67,108,864 combinations. 730 of the 743 are shown with a case a deployed vault can
ask the circuit; the other 13 have no such failing case anywhere. test/mutation-score.test.ts rebuilds it; run
npx vitest run -u test/mutation-score.test.ts after a change to the policy, and npm run seeds if it reports a
mutation that only the full scan catches.
The web app runs the same code in a worker on its proof page: /proof/#sabotage=122,stuck1
breaks gate 122 and shows the case that breaks P3, "With this gate broken, your heir could claim while you are still
checking in."
