|
Download stage3/interface-contract.md from Snapkitty/rea-unary: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/Snapkitty/rea-unary/resolve/main/stage3/interface-contract.md
- Command line
-
hf download hf://Snapkitty/rea-unary/stage3/interface-contract.md
-
curl -L -o interface-contract.md https://huggingface.co/Snapkitty/rea-unary/resolve/main/stage3/interface-contract.md
3.61 kB
Interface contract — pipeline boundary API
This contract is the hinge: everything below it is the checked pipeline (simulation, differential testing, trace conformance, firmware chain); everything above it (driver, GDScript bindings, web backend/frontend) talks only through these functions. Pre/post-conditions are stated, not assumed.
add32(a: uint32, b: uint32) -> {result: uint32, flags: {cf,pf,af,zf,sf,of}}
The arithmetic core. All upper layers use this signature.
- Pre-conditions:
a,bare 32-bit unsigned integers (0 ≤ a,b < 2³²). No other pre-conditions. - Post-conditions (all must hold on return):
result = (a + b) mod 2³²(wraparound;\addmod{a}{b}{2^{32}})cf = 1iffa + b ≥ 2³²(carry-out of bit 31)pf = 1iffresult[7:0]has even parityaf = 1iff(a[3:0] + b[3:0]) > 0xF(carry-out of bit 3)zf = 1iffresult = 0sf = result[31]of = 1iff (carry into bit 31) XOR (carry out of bit 31)
- Checked by:
differential-log.txt(silicon vs C model vs GHDL, 140/140),contract-check.log(7/7 clauses × 10 vectors).
recover(bytes) -> behavior_spec
Recovers a behavioral specification from raw binary bytes.
- Pre-conditions:
bytesis a non-empty byte string; the target ISA is x86-32 (32-bit mode). For the canonical demo:bytes[0:2] = 01 D8. - Post-conditions:
- returns a
behavior_specrecord with fields:address,mnemonic("ADD"),operands(dst="EAX", src="EBX"),semantics("EAX <- (EAX+EBX) mod 2^32; update CF,PF,AF,ZF,SF,OF"),ir(%result = add.i32 %a, %b/store.i32 %result, %destination). - the returned semantics must satisfy the
add32post-conditions above when lowered (checked by the differential oracle, not by assertion).
- returns a
- Implemented by: stage1 binary analysis (
sample.md,sample-analysis.json); the e1 router demo feeds the decoded operation ("unsigned addition") into this contract as the ALP candidate semantics.
verify(trace) -> verdict
Checks a recorded execution trace against the invariants.
- Pre-conditions:
traceis a sequence of records with fieldscycle,state,a_in,b_in,result,cf,pf,af,zf,sf,of,done;state∈ {FETCH, DECODE, EXECUTE, WRITEBACK}. - Post-conditions: returns
verdict = {pass: bool, violations: [...]}wherepassis true iff the recorded trace satisfies all checks: (a) every EXECUTE row's result/flags match theadd32post-conditions; (b) flags equal values recomputed from the operands; (c) state transitions ⊆ {FETCH→FETCH, FETCH→DECODE, DECODE→EXECUTE, EXECUTE→WRITEBACK, WRITEBACK→FETCH}; (d) no privileged-state rows (vacuously true for this machine); (e)done = 1exactly on WRITEBACK rows. - Precision: a passing verdict means the recorded traces satisfy the checks, NOT that every possible execution does (trace conformance).
- Implemented by:
sql-checks.sql→sql-results.txt(check-a 0/10 violations, check-b 0, check-c 0, check-d vacuous, check-e 0/0/10).
Error behavior
recoveron unrecognized bytes: returns a spec withmnemonic = "UNKNOWN"; never throws, never guesses semantics.verifyon a malformed trace:pass = falsewith aviolationsentry naming the malformed record; it does not silently skip records.add32has no failure mode within its pre-conditions (total function on 32-bit inputs).