Skip to content

feat(cil): migrate execution and proof bindings to decoded CIL - #602

Draft
benaadams wants to merge 1203 commits into
mainfrom
feat/canonical-cil
Draft

benaadams wants to merge 1203 commits into
mainfrom
feat/canonical-cil

Conversation

@benaadams

@benaadams benaadams commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

This draft works toward #568, #582, #596, #597 and #598. Decoded CIL as the sole executable representation remains the objective. On this head the extractor defines every method that decodes in full from its decoder (3,673 of 3,764 admitted methods of its own assembly); the lowered instruction language and the translator still exist for the rest.

The branch history was rewritten on 2026-11-16 to give every merge commit a subject and a description; no file content changed. Commit hashes in the entries below that predate that rewrite name commits of the old history, which CI runs still refer to by run number.

Implemented

  • Decode tiny and fat CIL bodies in Lean and check instructions, offsets, operands, branch targets, stack limits and initialization flags against the carried bytes. Reject malformed encodings, invalid tokens and unsupported exception sections.
  • Check method identities, signatures, locals, generic owners and constraints, type operands, fields and call targets against carried metadata. Shared indexes avoid repeated scans. Omitted heap entries preserve the distinction between zero and maximum-width offsets.
  • Decide how a method reads each argument from its declared signature and parameter homes: Method.argumentAccess with generated facts method{n}_argumentAccess{i} and the reduceArgumentAccess simproc in cil_step. The facts cost about 8,400 kernel-checked heartbeats per argument at 8, 32 and 128 parameters (10,800 with homes), and a lookups row fails a quadratic form.
  • The feature certificate carries only the locals with a known word, as index and word pairs in increasing order. Its cost per instruction no longer grows with the number of locals: 21,719, 21,832 and 22,048 kernel heartbeats at 16, 64 and 256 locals, where it cost 23,163, 28,471 and 52,354. FeatureFlowValid.expand and FeatureListValid.known prove the check accepts exactly the certificates the one-fact-per-local specification accepts.
  • A native method-table step reads a carried entry count (with a proof that it equals the number of entries) instead of walking the table: 24,722, 24,714 and 24,753 kernel heartbeats at 16, 64 and 256 entries, where it cost 29,483, 41,785 and 90,934. MethodTable and NativeMethodTable gain the fields entryCount and counted, and a table load checks its index against the carried count. The step still costs time linear in the number of static bindings, and a load of entry i costs time linear in i.
  • Add the typed field reference FieldRef (owner, index, type and metadata name), built by FieldRef.ofOperand? from a raw field operand; the class and static field instructions carry it. Templates write their links explicitly.
  • Argument loads are the CIL instruction ldarg. Instruction.arg and its narrowing operand are deleted; ldarg reads the declared signature and the parameter homes through Method.argumentAccess, and argumentAccess_of_evidence proves that validated evidence reads an argument without a home at the narrowing of its storage. The 45 stepping rows are within 2% of their baseline.
  • Instruction.ofRaw? decodes a raw opcode to the instruction ECMA-335 assigns it and refuses an operand its encoding cannot carry. 84 of the 109 instruction constructors decode from raw CIL; 25 do not yet. Tests/ValueDecoding.lean decides in the kernel a table of raw forms with the instruction each must give. Decoding costs 14,043, 14,015 and 14,007 heartbeats per instruction at 500, 2,000 and 8,000 instructions.
  • An indirect call selects its target through the named function indirectTarget, and step_managed_call_eq states the step with that selection as a rewrite target. The generated proofs of calli runs use cil_kernel_rfl, so the length of an owner identity no longer limits them; a run through a 400-byte owner is tested.
  • ManagedCallsValid reads the link table by one walk beside the code and requires the link keys to ascend and to be call sites. ManagedCallsValid_iff_original proves it accepts exactly what the list form accepts. Its cost per call site falls slightly from 64 to 1,024 sites, where a scan per site grew 3.23 times from 64 to 256.
  • Tests/Objects.cs verifies its 38 example proofs in one generated batch, as 22 other test files do; locally the file went from 676 s to between 107 and 163 s.
  • The declared signature is checked by its own conjunct of MethodEvidenceValid, DeclaredValid, proved by rfl in the generated method{n}_declared_validated. On a 16-method fixture the shape theorems went from 4,211,835 to 774,006 heartbeats and the declared theorems add about 11,250 per method.
  • The object identity and null-test arms of Safety.step sit in its first match, so neither match exceeds the 79 alternatives split handles. The 91 generated step equations state the same facts. step_raise_faulting costs 7.1% more and has a raised heartbeat budget.
  • Method.ofRaw? gives the method a raw definition denotes, with each instruction decoded by Instruction.ofRaw? and the frame, signature and homes computed by the functions the evidence checks use; Method.ofBody? takes the code and the init flag from the pinned body bytes after checkBody, and decodedProgram? does so for every method of an extraction. Method.ofBody?_of_decodes rewrites it with the generated body check. Decoding a method costs 24,775, 24,494 and 24,425 kernel heartbeats per instruction at 500, 2,000 and 8,000 instructions.
  • Examples/Proofs/DecodedAdd.lean proves correctness_decoded: the program that decodedProgram? reads from the bytes of Arithmetic::Add returns the sum of its arguments modulo 2^64. The proof names neither the emitted method nor the emitted program, and changing the add byte to sub in the extraction makes it fail. It costs 1.87M heartbeats and 479,000 kernel heartbeats, 1.38 and 1.24 times the proof over the emitted method.
  • localloc is a CIL instruction: Instruction.stackAlloc is deleted, the zeroing flag is DeclaredSignature.initLocals, which DeclaredValid ties to the localsinit bit of the body, and Instruction.ofRaw? decodes opcode 0xFE0F.
  • A call site states its method once, as a typed MethodRef (owner, metadata name, signature, generic arity and method arguments); the declaring type, return type and parameter types are read from it. checkCallOperand requires the name to spell the metadata row name, and the generic arity and method arguments to equal the row and the site. The name clause costs 41,199 and 151,448 heartbeats at 20 and 80 bytes, linear per byte.
  • The indirect access rule ties what ldind, stind, ldobj, stobj, cpblk and initblk emit to the width, sign and alignment of the raw instruction. 39 forged emissions that every check accepted are rejected, and the 25 emissions the extractor produces are accepted. ldobj and stobj of an operand type the extractor refuses accept nothing but the span no-op.
  • Every raw opcode decodes. Instruction.unadmitted (opcode) replaces Instruction.unsupported: it carries the raw opcode and faults when stepped. Instruction.ofRaw gives the instruction ofRaw? admits and a hole otherwise (ofRaw_eq_unadmitted_iff), Method.ofRaw? maps it over the code and refuses code that names an undeclared argument, and Method.ofRaw?_code states that each pc holds the decoding of the raw instruction there. The extractor writes the raw opcode at every hole. Instruction.ofRaw? and Instruction.ofRaw take the raw instruction before the one they decode (none at the first pc), where a prefix stands, and Instruction.ofRawCode decodes code in one pass that carries it; ldelema is the first instruction to read it. The checks that compare an emitted instruction with its decoding take the same previous instruction, and ScalarFlowValid.instruction_checked states the match after it.
  • A byte list over 256 bytes is written as one fixedBytes literal whose code joins numerals of at most 256 bytes with Nat.lor and Nat.shiftLeft. The kernel keys its caches by a hash that reads only the low 64 bits of a numeral (Hashable Nat and expr_eq_fn in the Lean source), so the separate numerals the extractor wrote before, joined by ++, collided when they ended in the same eight bytes and made a body check quadratic in its numerals. fixedDigitsWithin is the one splitter, over digits of any width. The body check of 125, 500 and 1,000 string tokens now costs 88,900, 92,700 and 99,800 heartbeats per instruction (89,600, 136,300 and 201,500 before), and rows over 5, 10 and 20 KB of equal-tail and random numerals bound the growth at 1.15 per byte; the former form fails them at 10 KB. Whole body obligations of bodies of at most 256 bytes rise by 0.06 to 0.46 percent. Binding pages take the same form (fixedDigitsWithin 512 over one joined code): the digest proof of a 4 KB page whose chunks end in the same eight bytes costs 23.26M heartbeats against 23.25M for random ends, 506.1M against 23.0M before. The splitter lives in CIL/Extraction/FixedDigits.lean, which imports only the prelude, so a generated audit module costs 1.92M heartbeats and 1.2 s where importing it through the Lean library cost 5.25M and 2.9 s; a check in Tests/BodyLiteral.lean fails when that import closure reaches a Lean module.
  • PrefixEntryFree states over raw code that no branch or switch arm, reachable or not, enters the instruction after unaligned., volatile., tail., constrained., no. or readonly.. Body decoding already refuses such a branch, so checkBody_prefixEntryFree, instantiateMethod_prefixEntryFree and MethodEvidenceValid.prefixEntryFree give the rule for every method with body evidence and the evidence check decides nothing new; prefixEntryFreeWith decides it in one pass over a bit mask of the branch destinations (about 1,380 heartbeats per instruction). The extractor refuses the same bodies in InstructionPrefixes.ValidateEntry with the blocker "Branch enters the instruction after a prefix". No corpus, example or fixture method holds such a branch.
  • A homed argument is stored with starg, addressed with ldarga and read with ldarg; the lowered local forms for homes are gone, and the four raw forms decode. step_relabel_faulting is proved by splitting on the first match of step and costs 52,100 heartbeats where it cost 212,700.
  • Method.fieldShape and Method.valueShape resolve a typed field reference or a value type against the layout environment, with one generated fact per distinct operand that the kernel checks from one layout entry: 268,814 to 271,626 heartbeats per field fact and 13,294 to 16,135 per value fact from 8 to 512 structs. No instruction reads them yet.
  • A raised exception is a typed ExceptionType, in instructions, faults, contracts and example proofs; text is produced for display only.
  • The receiver fold is deleted: a raw stloc and ldloca before a span get_Length or get_Item call are emitted as themselves and checked against their raw instructions.
  • StepMetadata requires equal layout environments, and a method signature with an explicit receiver is refused in Lean by instantiation and by the metadata identity check; the declared signature check costs 9,883, 9,890 and 9,939 heartbeats per method at 1, 4 and 16 parameters.
  • Byte lists in generated evidence are numerals read by CIL.Extraction.fixedBytes instead of list literals: checking a generated file costs 29% (Add), 25% (Countdown) and 17% (Struct) fewer heartbeats in total, and the kernel part rises 3 to 6% because each check decodes its bytes.
  • MetadataName.ofBytes? reduces in the kernel in time linear in the name: 13,498, 35,148 and 119,302 heartbeats at 20, 80 and 320 bytes, where it cost 143,456, 1,746,460 and 26,147,681.
  • Deep check of carried metadata: SliceMatches joins the assembly block, the rows and the #US entries of one slice against a prepared image, sliceBound decides it, and its success implies the proposition under a bounded view. Deep verification reconfirms the metadata-rows fact through BindingAudit.metadataRows, with each distinct Assembly block checked once, beside the body-bytes fact; a forged row page must fail exactly that fact (Tests/DeepVerify.cs). An unchanged deep result is reused, also under --proof-root: its key binds the compiled import closure, each certified closure part is hashed and its header read once per process, and a failure between staging a consumer deep result and publishing it leaves no receipt and no new entry. StrictBinding also checks a type definition of a pinned image in constant work (TypeDefAt: name, kind, field range, base and nesting, at rows the claim states as hints), with absence of a NestedClass row shown by adjacent rows and the sortedness that rests on stated as a whole-table fact (TablesSorted); no deep request uses these yet. A run that opens the certified library from the local cache, a release or the closure cache traces that stage, so a forced full verification with a warm cache shows its library stage.
  • A support result is keyed by the extraction it was computed for, so a changed extraction no longer reuses the support of another one.
  • The proofs of Guards::Count and Guards::Index close again and Tests/Guards.cs runs in the evidence suite. Tests/HoleCorpus.cs pins that no admitted corpus method (3,764) gets a parameter home from dead code or holds a dead prefix other than unaligned..
  • The extractor defines a method that decodes in full from its decoder: it writes cil_decoded_method method{n} := Method.ofRaw? ..., and the kernel computes the definition from the raw body. A method decodes in full when no pc holds a hole and every pc is reachable; every other method keeps its literal definition. 3,673 of the 3,764 admitted methods of the extractor's own assembly are defined this way (Tests/canonical-methods.txt), as are the examples Add, Choose, Countdown and Calls. The blockers report gives the first refusal of each of the 91 that are not: callvirt 34, fields 23 (9 more since the deep binding scripts, whose records hold a 32-byte digest struct), ldstr 19, a call or construction the extractor still translates 15 (an exception constructor followed by throw 13, other modelled runtime calls 2).
  • Raw ldind and stind are the instructions ldind and stind over a numeric kind; load64, store64 and tableLoad are deleted.
  • ldnull, castclass and isinst are instructions with decode arms; objectTest and the memory operation nullObject are deleted. Method.ofRaw? decodes the instantiated code.
  • Class field access is ldfld, ldflda and stfld over a FieldRef, stepped through Method.fieldShape and decoded from opcodes 123 to 125. The six class field memory operations, their site and match checks and their translator arms are deleted. A class field store is admitted only of the field's stack kind. The extractor reads a field name from the bytes of its metadata row.
  • Static field access is ldsfld, ldsflda, stsfld and field ldtoken over a FieldRef; the static memory operations are deleted, the static field tie compares the field name, and the stepper builds a static read from the body's site fact. These four instructions have no decode arm yet.
  • newarr carries its raw type token and steps through the element shape the layout environment gives it; newArray and newReferenceArray are deleted, and a System.Object element array is refused by identity.
  • Call targets are read from each method's link table: the call arms of step take their target from the link of their pc and fault with unlinkedCall without one, and cil_instruction_equations states a link fact per call site.
  • The runtime-model arms of step run through named functions (intrinsicCall, featureCall and the rest). RuntimeModelsAgree, a new part of MethodEvidenceValid, ties each call to a modelled runtime method to its entry in a typed model table. memory_stepRenamed transports the model of every memory operation under an allocation renaming, so an entry family that resolves only memory operations adds its case to runtimeModel_stepRenamed by naming it; RuntimeModel.StepRenamed now takes the well-formedness of the source memory and an observable source step. A call of a BitOperations helper, of the same helper an integer type declares, or of BinaryPrimitives.ReverseEndianness keeps its call and runs the scalar intrinsic that its entry in CIL/Extraction/BitModels.lean gives its method reference (70 entries; signed Log2 and signed 8- and 16-bit rotations have none); a proof outline steps the four bit counts through that call.
  • A fault the model does not cover refutes nothing: ExecutionFault.definite is false for an unsupported instruction and for fuel exhaustion, Settled requires a definite fault, and the refutation lemmas take Settled.
  • newobj is one instruction over the typed MethodRef of its constructor, decoded from opcode 0x73; newAggregate and newObject, their translator records and their step lemmas are deleted. Each method states one named link table, method{n}Links, which its literal, its evidence and its decoder all take, so the links of a decoded method are the ones the extractor wrote. ManagedCallsValid ties every live newobj to its raw site: the site names the instruction's constructor, the linked method is the one the site names, a class gets an object link and a value type an aggregate link, and the bases and the size match the constructor's raw method. Negative tests reject a forged link index, kind, base list and size, a missing link, a call opcode and a constructor owner the site does not name. Constructors of span and exception types keep their literal models.
  • call is one instruction over the typed MethodRef of its target, with tail. and constrained. carried as CallPrefixes, decoded from opcode 0x28; the lowered call and tailCall forms with their index and count operands are deleted, the argument count is read from the MethodRef and the target from the link of the pc. Instruction.ofCallSite? decodes call and newobj from a call site operand, Method.ofRaw?, Method.ofBody? and decodedProgram? take the link table after the environment, and Method.withCode drops the links of both, so a rewritten body states its links again. ManagedCallsValid requires a direct link at every call pc, tied to the site's method and token. The decoder admits a call that the extractor translates to a plain static call; every other kind of call is still translated.
  • Three families of runtime calls are calls without a link, each with a typed entry in the model table, in place of their lowered operations and translator arms: the integer Math helpers (Min, Max, Clamp, Abs, Sign; 31 call sites in the corpus and 44 in the examples), and Vector128.CreateScalarUnsafe and GetElement over Vector128 and Vector256 of ulong (23 sites in the examples). A modelled call leaves the unspecified-operand guard to its model, which states the operands it observes; a linked managed call keeps its guard, and step_call_linked states that its step is unchanged. reduceRuntimeModel evaluates the model of a closed method under a variable environment, and the stepper rewrites a modelled call whose intrinsic step the kernel cannot evaluate with step_call_intrinsic. The intrinsic call stepping row costs 32% fewer frontend and 71% fewer kernel heartbeats; rows for instance and virtual calls record today's cost, about 61,000 heartbeats per virtual table entry.
  • step_call_eq states a call step as callStep of the link at its pc, a regular definition, and every call-family step rewrites its link fact in the pass that applies its step equation. With a match on the link in the equation the kernel evaluated the table read once per site, and the calls stepping row cost 10,827, 16,474 and 47,170 kernel heartbeats per instruction at 16, 64 and 256 instructions. The row now costs 7,131, 5,397 and 4,963 kernel heartbeats (7,742, 5,800 and 5,315 before the conversion) and 801,548, 817,861 and 822,727 frontend heartbeats (821,255, 840,326 and 846,190).
  • The stepper rewrites the link fact of a newobj step in the pass that applies its step equation, so only the arm of the link's kind is simplified. The constructions stepping row costs 438,693, 395,870 and 385,510 frontend heartbeats per instruction at 16, 64 and 256 instructions (472,527, 433,397 and 424,162 before the conversion) and 6,825, 4,082 and 3,396 kernel heartbeats (7,299, 4,258 and 3,497). With the link fact one pass later the row cost 12 to 15% more than before the conversion.
  • Tests that read or rewrite generated method text go through shared helpers in Tests/GeneratedEvidence.cs, which forge a decoded method through its decoder call or through the raw definition the decoder reads and fail on a method kept as a literal. Every rejection test is kept: a forged decoder is refused by DeclaredValid, MethodShapeValid or ManagedCallsValid, and a changed raw instruction by ScalarFlowValid.
  • Array element and length access decodes: ldlen, ldelem and stelem by numeric kind, the reference load and store, the typed ldelem and stelem over their element type, and newarr. The lowered arrayLoad, arrayStore and arrayTransfer memory operations and the managed table length and element operations are deleted with their translator records. A typed access resolves its element shape from the layout environment, which binds the width its step uses, and a by-ref-like element is refused there. An object type binds only to a pinned class or to System.String, so an array of an interface or System.Object element is refused in Lean and no longer only by the extractor. Stepping an element load or store by kind costs what the lowered forms cost (278,864 against 278,242 frontend heartbeats per instruction at 10 instructions). A typed access costs 6 to 8 percent fewer frontend heartbeats than the lowered forms (256,343, 148,602 and 116,353 per instruction at 16, 58 and 254 instructions), stepped from facts derived from the element shape facts cil_resolution_facts generates (step_ldelem_any_of_element, step_stelem_any_of_write and the transfer forms).
  • ldelema is the instruction .ldelema element readOnly, decoded from opcode 143 with the flag set when the instruction before it is readonly.; readonly. decodes to .nop, and any other instruction after it, or ldelema after another prefix, does not decode. Its step reads the element shape the method's layouts give the operand type and forms the address with the unchanged arrayAddress. MemoryOp.arrayAddress, the lowered ArrayAddress operation, Arrays.ValidateReadOnly and the readonly window of the scalar check are deleted: a site after readonly. must be an ldelema emitting its decoding, and a branch into it is refused by PrefixEntryFree. step_arrayAddress_of_element gives way to arrayAddress_of_element and step_ldelema_of_element. The address stepping rows cost 4 to 8 percent less than the lowered form. A readonly. site requires the instruction after it to be ldelema, which with fall-through and PrefixEntryFree is the rule that only ldelema follows readonly.. Per site at 512 sites every ScalarFlowValid row is at or below its cost before the conversion (plain addresses 277,254 against 277,621, readonly addresses 364,641 against 396,905, block copies 471,028 against 472,062). The generated bodies of those rows carry the byte offsets extraction writes, which about doubled them. No corpus method holds ldelema; 61 methods of the examples do.
  • DecodedSummary binds a checked method contract to a method defined from its decoder: the contract, the proof that it holds, and the method's evidence record by pin, token and type arguments. decodedProgram?_eq_some transfers it to the program read from the body bytes, and the site lemma gives a caller the token and type arguments of the callee it links. Examples prove one caller property both by stepping through the callee and through its summary: the generic identity at one and two sites, Arithmetic::Calls, and callers with 1, 4 and 16 calls of a method that writes through a reference. At 16 calls the summary proof costs 52.1M heartbeats with the summary's own proof, binding and decoding included, against 158.4M stepped, and 621,945 kernel heartbeats against 3,228,438. Tests/SummaryCalls.cs fails when the cost per call through a summary grows by more than 1.6 times from 4 to 16 calls or when the summary proof at 16 calls costs as much as stepping. Negative tests refuse a contract whose footprint omits the written cell, a caller that leaves the callee's precondition unproved, a callee whose raw definition is forged, and a summary bound to another method's token.
  • An instance field access whose owner has no carried definition is refused in Lean (unboundInstanceField). Before, the operand check accepted any field name at index 0 for a type of an unpinned assembly or of a contract import, and no other check bound the index to the field the token names: a forged extraction in which ldfld of one field read another field's offset passed the whole evidence check, on the struct path and on the class path, and only the extractor refused it. Item1 and Item2 of the core-library ValueTuple pair keep indices 0 and 1. All 5,065 instance field accesses in the admitted corpus have owners in the module itself.
  • A class instance field typed System.Object or as a generic class is admitted in Lean as the extractor admits it: a class-like generic instance is an application over a head that states it is a class, and binding compares the head with the kind the metadata gives. The 45 corpus methods (88 admitted entries) that Lean refused are accepted. The arity of a generic owner is tied to its GenericParam rows: an owner without parameters carries the adjacent rows that bracket it, so a type definition with parameters named without arguments is refused in Lean and no longer only by the extractor. That rests on the table being sorted by owner, as ECMA-335 requires, which no check reconfirms yet. A method whose signature has no GENERIC flag is read as having none without brackets, as before. Over 60 corpus extractions the brackets cost 1.7 percent of total heartbeats (the tables check 16 percent, the body check 2.3 percent). Tests/SelfAdmission.cs gains an opt-in mode that checks every admitted entry in Lean (about 2.7 CPU-hours; no suite runs it); on 290e747f Lean accepts all 3,760 admitted corpus methods.
  • The generated method{n}_calls_validated theorem is decided in the kernel on ManagedCallsValid, which reads links by one walk. The earlier tactic went through a list form that read each pc's link by a table scan, so its cost grew with instructions times links: 24.1M heartbeats at 125 string tokens and 159.4M at 500. It now costs 3.1M and 9.0M, and the lookups rows bound the whole file and the call check per token at 1.15 (strings 1.04, fields 1.09, calls 1.07).
  • The generated feature theorem states its link lookup as MethodEvidenceValid does. With the two stated differently, assembling the evidence theorem unified them by unfolding the decoded body, about 390,000 heartbeats per instruction; it now costs about 395,000 at 502, 1,002, 2,002 and 4,002 instructions. cil_decoded_method writes an all-zero struct local as List.replicate size 0, the term a literal definition has, so a caller's goal after frame entry is unchanged by decoding.
  • The System.Object constructor is the first entry of the runtime-model table. The base constructor call of a constructor stays one .call with no link, where the extractor lowered it to pop. A call whose method the table models states no link and a call it does not model states the link the call check required before; ManagedCallsValid takes the modelled set and decides both in its one match on the instruction, so a pc that is not a call pays about 79 heartbeats for it. callEmitsNoPop, part of UnsafeCallsValid, refuses pop at a call or construction site, and the runtime catalog lowers nothing. Stepping a constructor's base call costs 18 to 25 percent fewer frontend heartbeats than the pop did at 16, 64 and 256 instructions, and the calls stepping rows 5 to 9 percent fewer kernel heartbeats. Model facts are proved per table entry, so a further entry adds a case. This conversion defines 791 more corpus methods from their decoder.
  • A static site is bound to the field its token names: each static descriptor carries the typed field reference, and the static field check requires the site's descriptor to name the instruction's field for ldsfld, ldsflda, stsfld and field ldtoken. Before, a forged extraction could put one field's descriptor at a site whose token names another, and a static load returned the other field's value. A static whose owner is not carried is refused, except the platform constant the feature check requires verbatim, and a static named through an instantiated owner is refused. StaticIdentitiesValid, a new conjunct of TranslationValid, requires one static identity per field and one field per identity in the whole program, by sorting the pairs in both directions (oneToOne_spec); before, two fields could share an identity and alias in the model. It costs 22,544, 20,876 and 22,706 heartbeats per site at 8, 32 and 128 sites. The extractor reports an instance field operand whose owner is not carried as a blocker with its reason.
  • A decoded summary carries over to other programs. Program.closure computes the methods a method reaches through its links and checks every entry it relies on; MethodContract.Holds.restrict carries a contract proved in a program to the closure, and DecodedSummary.relocate into any program the closure relocates into. The closures suite proves a contract once, binds it over its closure and applies it in three programs, and Lean refutes a relocation into a target with other bytes. The search takes a lookup (closureWith), and Program.closure_eq_closureWith rewrites a closure to one over any lookup that agrees with the list. Every extraction states programLength, programIndex (a balanced tree written by program_index%) and programIndex_get?, checked once by one kernel comparison, so a proof decides a closure of n methods with e link callees in a program of P in n log P + e steps: a whole-program chain costs 87,394, 335,656 and 1,422,953 kernel heartbeats at 8, 32 and 128 methods (90,395, 437,519 and 3,533,840 through the list), and a four-method closure 55,819, 58,512 and 61,237 in programs of 128, 512 and 2,048 (81,699, 179,818 and 571,795 through the list). Stating the index adds 0.49% to the elaboration of the Add extraction and 0.10% to a 128-method one.
  • The vector example: DivisionIntrinsics.UnsafeLowNext returns UnsafeLow(x) + 1, and Examples/Proofs/VectorSummary.lean proves it once by stepping through UnsafeLow and its two modelled vector calls and once from a DecodedSummary of UnsafeLow. Stepped it costs 3,192,215 heartbeats (118,705 in the kernel, 3,488 proof objects); through the summary, with the summary's own proof, binding and decoding, 3,506,999 (139,650; 4,614), so one use of a callee this small does not repay the summary. main has no proof of a caller of UnsafeLow to compare with. A forged UnsafeLow that reads the other lane is refused by the body check.
  • Segment contracts (CIL/Safety/SegmentContract.lean): a precondition, a memory footprint and a postcondition over checked exits, with sequential and branch composition and links to weakest-precondition proofs.
  • The stepping tactics keep an index of the equation hypotheses in scope, so the cost of a step no longer grows with them (21 to 61 heartbeats per hypothesis per instruction between 16 and 256 hypotheses), and snapshot walks restate a fixed number of facts per store.
  • Path comparison in the verification scripts follows links and uses the case rule of the volume that holds each path, read from the operating system.
  • An x64 profile below the .NET 11 x86-64-v2 baseline is rejected, and the x64-sse2 profile is removed.
  • StrictBinding: methodMetadataBound and MetadataRowsBound bound the carried rows of a method across pages.
  • Closed argument storage is decided without Classical.choice; that check costs 57% less on Add and 44% less on Countdown.
  • Represent metadata names, UTF-16 user strings, assembly versions and identities with typed values. Preserve raw identity components and use a lawful assembly ordering. Some scoped identity comparisons remain textual.
  • The reference interpreter CIL.step itself gives a mixed int32 and native-int operand pair its ECMA-335 III.1.5 result for sixteen instructions (arithmetic, bit operations, comparisons and signed branches); Safety.step reaches the widening only through it, and Tests/MixedNativeOpcodes.lean proves the two interpreters agree for every operand, both orders and any stack beneath. Unsigned branches still refuse a mixed pair: on .NET 11 the runtime zero-extends or sign-extends the int32 operand of a mixed unsigned branch depending on whether the JIT has it as a constant, and one method changed its result after tier-up, so no single rule matches the runtime.
  • Execute mixed native arithmetic and reference offsets through the bare opcodes: add on a reference and an integer keeps the checked byte-offset semantics of the form it replaces, and Tests/ReferenceTests.lean proves the two equal and rejects the old lowering. add on a native method table and an integer offset, in either order, executes the checked cursor addition; ManagedOp.tableOffset and the C# TableOffset record are deleted.
  • Use opcode-specific arithmetic, conversion and local instructions. Local narrowing comes from declared metadata. Checked return dispatch rejects incompatible narrowing; execution and structural proofs use the shared dispatch. Remove unused vector-home components and dead block helpers.
  • Integrate deep checks into the internal standalone verification path. Retain pinned image snapshots, build StrictBinding in the selected certified library, jointly replay and audit the proof and binding contributions, and include binding evidence in successful reports. verify --deep-checks exposes them, and replay failures are attributed to the declaration that the kernel rejected.
  • StrictBinding gains the check that a carried Assembly block (table header bytes, decoded header, Assembly row, and the assembly's string and blob entries) equals the pinned image's bytes, with assemblyMatches_of_assemblyBound proving the proposition from the check. Heap keys are compared through a numbering the check derives; a row key without its entry and an entry no row names are refused. The same check covers the carried table rows of a slice with the #Strings and #Blob entries they name (RowsMatch, rowsBound, rowsMatch_of_rowsBound): a MethodDef row is compared with its body address column masked, and one sort and merge-join builds the numbering, at 1.07 times the cost per added row from 256 to 1,024 rows. The extractor's own slices for 88 methods and 949 rows across all eleven carried tables are accepted. The metadata root accepts a 256-byte version field.
  • Check pinned SHA-256 digests and PE method-body locations with paged body claims and flat image-list auditing. Validate original library bytes and file sets before cache promotion, including same-length changes with restored timestamps.
  • Keep pinned metadata contexts alive through contract import/export, source-bundle verification, inventory probes and exception linting.
  • Read the metadata table header through the stream directory and the Valid mask, and refuse an uncompressed #- table stream and malformed roots, each with its own error. Carried MethodDef rows keep the body address zeroed, so editing one method leaves the evidence of other methods byte-identical.
  • Every Lean test library has a suite that builds it: 19 libraries that only an all-library build reached are now built by core, evidence or intrinsics, and Tests/Strings.cs, Tests/Identities.cs and Tests/StrictBindingFixture.cs run in a suite.- Build with .NET 11. Share hash operations and reduce repeated work in stepping, embedding, metadata lookup, extraction and audit preparation.

Proof-author changes

  • Instruction constructors follow ECMA-335 mnemonics: and, or, xor, not, shr_un, conv_i1 to conv_u, ceq, cgt, cgt_un, clt, clt_un, br, brfalse, brtrue, bne_un, bge_un, bgt_un, ble_un, blt_un, ldc_i4, ldc_i8 (argument value), ldloc, stloc and ldloca. Lemmas named after an instruction follow.
  • divide, checkedArithmetic and checkedConvert are replaced by div, div_un, rem, rem_un, add_ovf to mul_ovf_un, and conv_ovf and conv_ovf_un over ConvTarget; conv_i is its own instruction. step_checked_result, step_conv_ovf_result and step_conv_ovf_un_result replace the earlier result lemmas, and guard_div to guard_mul_ovf_un are in cil_guard.
  • ldloc and stloc take only an index; narrowing comes from the slot kind. step_local_annotation and step_setLocal_annotation are removed. ldloca on a span local pushes the view it holds.
  • ret reads its narrowing from the declared return type (Method.returnNarrow, declaredNarrow in CIL/Resolution.lean).
  • add on a reference and an integer, in either order, executes the checked byte offset; step_add_reference_i32_eq, step_add_reference_i64_eq and the read-only and commuted forms state it.
  • add on a native method table and a 32-bit or native offset, in either order, executes the checked cursor addition; it returned invalidState before. step_add_table_i32_eq, step_add_table_i64_eq and step_add_table_commuted_eq state it, and ManagedOp.tableOffset is removed. Extraction accepts the table form only for opcode add with no operand.
  • The first match of CIL.step begins with the two table arms, so a split on step leaves 14 exclusion hypotheses in its last case; it left 12. step_add_commuted_eq, step_add_readOnly_commuted_eq, step_memory_add_commuted_eq and step_memory_add_readOnly_commuted_eq are closed with id rfl. Memory.Renamed.stepReference now depends on Classical.choice. checkedNative_bind is public in FixedStepHelpers.
  • FeatureState is FeatureFacts over a list of index and word pairs, and the entry state has locals := []; featureSuccessors takes the stack; FeatureFlowValid_iff_list is replaced by FeatureListValid, FeatureFlowValid.expand and FeatureListValid.known; checkFeatureSite is removed; factWeakens and factsWeaken are in FeatureLocals.lean. A handwritten feature certificate lists only known facts.
  • CIL.Extraction.linkKeysAscend and linkKeysAscend_bound are keysAscend and keysAscend_bound over any element type. CIL.CodeSuffix.advance and lookup take an implicit element type; generated suffix and instruction facts keep their statements. cil_resolution_facts also declares {m}_argumentAccess{i}, {m}_parameterSuffix{16k} and, with homes, {m}_homeSuffix{16k}, {m}_homesAscend and {m}_localCount, and it fails on homes that do not ascend or on a signature it cannot resolve.
  • CIL.step matches on the instruction and CIL.widenMixed applied to the stack. fallback_relabel, fallback_raise, fallback_appendLocals and Memory.Renamed.stepFallback state values where they stated CIL.widenMixed op values. The CIL.step.eq_N lemmas of the arms that match the stack take the hypothesis widenMixed op stack = pattern, so simp only [CIL.step] needs CIL.widenMixed and CIL.nativePureBinary in its simp set; the generated step_*_eq equations keep their statements. base_relabel_binary and base_relabel_comparison take the instruction first; nativePureBinary_relabel and widenMixed_relabel are removed.
  • CIL.step gives no meaning to local instructions and has no frame parameter; step_feature, step_return, step_intrinsic, step_profile_eq, BaseRelabel, Fallthrough, Branching and the fallback lemmas lose that argument.
  • Removed with no replacement: vectorArg, vectorArgAddr, vectorLocal, vectorLocalAddr, setVectorLocal, lane, laneAddress, setLane, newVector256, asRef, tableAddress, skipInit, init256, bitcast256, mul64, byteToBool, Method.vectorLocals, Method.vectorArgs, Frame.arguments and Address.home. Frame has four fields.
  • A method records its declared signature, layout environment and call links. TranslationValid, MethodEvidenceValid and MethodsChecked take the pin list. Handwritten certificates must supply the metadata evidence.
  • broadcastBinaryMethod, broadcastShiftMethod and the invoke_broadcast* facts take the declared signature and environment.
  • The 23 step equations that hold by unfolding are closed with id rfl, so simp applies them as propositional lemmas; statements are unchanged.
  • The certificate is schema 5 with a binding section of twelve facts, and the verify --format json report is schema 2. verify --deep-checks digests.sha256 runs the deep checks; there is no separate audit command. A default verify prints Binding: default and one line per trusted fact.
  • In StrictBinding, body proofs compose through checkAll, ClaimsHold and PagesHold; ClaimedBodiesBound, ClaimPagesBound and claimedBodiesBound_of_pages are removed.
  • Extraction refuses a runtime-async method, body bytes for a row with no IL body, a method generic parameter past the arity, a reference into a pinned assembly whose slice is missing, and an image whose table stream is #-.
  • .arg i is written .ldarg i; its narrowing comes from the declared signature, not from an operand. A closed calli run is proved by cil_kernel_rfl, and a single calli step by step_managed_call_eq with a kernel-checked indirectTarget fact. validateManagedCallWith takes the link read at the site. A mutated declared signature is rejected by method{n}_declared_validated, no longer by method{n}_shape_validated, and argumentAccess_of_evidence takes DeclaredValid.
  • .stackAlloc zeroed is written .localloc, with the flag in declared.initLocals; DeclaredSignature has the field initLocals and StepMetadata the field declared. A CallSite literal states method := { owner, name, hasThis, genericArity, returnType, parameters }; declaringType, hasThis, returnType and parameterTypes are accessors. step_relabel_faulting has a raised heartbeat budget.
  • .unsupported description is written .unadmitted opcode. An exception is a typed value (.throw .overflow, .thrown .argumentOutOfRange); proofs that named exception text name the member. StepMetadata has the field environment; segmentStores, untouchedLocals and SegmentLocalEffects take the body; a homed argument appears as .starg, .ldarga and .ldarg. Generated byte definitions read CIL.Extraction.fixedBytes n 0x...
  • .load64 and .store64 are written .ldind .i8 and .stind .i8; a narrow or native indirect access names its kind the same way.
  • .memory .nullObject is written .ldnull, and .objectTest is written .castclass type or .isinst type.
  • A class field access is written .ldfld field, .stfld field or .ldflda field with a named FieldRef; step_ldfld_eq, step_stfld_eq, step_ldflda_eq and their word, reference and array forms replace the class field forms of step_memory_eq. argumentStep is equationStep.
  • A static field access is written .ldsfld field, .ldsflda field, .stsfld field or .ldtoken; step_ldsfld_eq, step_ldsflda_eq and step_ldtoken_eq state their result as a match on the read, and staticAt is Method.staticAt.
  • step_newarr_i32_eq and step_newarr_i64_eq replace the step_newReferenceArray equations; after stepping newarr a goal shows allocateElements of the element shape.
  • managedStep takes the link of its pc, and an extraction states method{n}_link{pc} facts.
  • A refutation from a fault passes a proof that the fault is definite where it passed a proof that the fault is not fuel exhaustion; run_mono and invoke_mono take Stable. A refutation from an unsupported fault no longer elaborates.
  • A proof that stepped an intrinsic call by unfolding step rewrites with step_intrinsic_eq.
  • A method defined by cil_decoded_method gets its step equations from cil_instruction_equations; the command takes the field references the method names.
  • An object or aggregate construction is written .newobj constructor with a MethodRef; step_newobj_eq states its step as a match on the link of its pc, and after the link fact rewrites the goal shows the earlier do-block with constructor.parameters.length where the literal argument count was. step_newAggregate, its action form and run_newAggregate_of_contract are step_newobj_aggregate, step_newobj_aggregate_action and run_newobj_aggregate_of_contract, and the first and last take an aggregate link premise. objectSiteType, StepEffect, StepContract and SiteConsistent take a pc; step_callee concludes readsLink. An extraction writes method{n}Links, methodEvidence.links and method{n}_links, and its decoder call takes the table.
  • A direct call is written .call method prefixes with a MethodRef; .tailCall is .call method { tail := true }. step_call_eq states the step as callStep of the link at the pc. Forwards, ForwardsOut and WP.load_call_store take the call's MethodRef and its arity, and MethodIdentity and StructuralLabels state call facts over the MethodRef. A body built with Method.withCode has no link at a call or newobj pc until its links are stated. validateLinkedCallWith checks both instructions; callOf?, construction?, ManagedCallsValid.reads, ManagedCallsValid_of_implied, all3_implied and ManagedCallsValid.linkAt_eq are removed. A supplied body.linkAt pc = link fact rewrites with the step equation.
  • An element load or store is written .ldelem kind, .stelem kind, .ldelem_ref, .stelem_ref, .ldelem_any element or .stelem_any element, and a length read .ldlen. step_arrayLoad_of_element, step_arrayStore_of_write and step_arrayStore_i64_of_write are arrayLoad_of_element, arrayStore_of_write and arrayStore_i64_of_write. ldelem.i on a null table with a scalar that is not an index gives invalidState where it threw a null reference. Instruction.typeTest? is ofType?, and Memory.Renamed.managedStep lost an unused argument.
  • cil_contract_steps skips a local invocation fact whose start memory is a different variable from the memory the call steps from; kernel heartbeats on the shared tactic libraries are unchanged. In a proof with several summarised calls, clear the earlier frame once the next call's frame exists. LocalSnapshots.read_word64 reads a remembered 64-bit local.
  • cil_checked_steps steps a call without a link on in the same method. With the link fact and the model fact the stepper rewrites a modelled call by step_call_model, and a directly linked .call by step_call_direct; step_call_eq remains for a call whose link no fact decides. callStep takes an argument for the unlinked case, and the cil_managed_calls macro is removed.
  • TranslationValid has the conjunct StaticIdentitiesValid and translation_of_methods a parameter for it; BodyEvidence has the field statics; a linked static collision is the typed StaticCollision; MetadataIndex.link is IndexTables.link. The metadata errors unboundInstanceField, unboundStaticField and instantiatedStaticField are new.
  • SegmentState.localFootprint takes the body. The x64-sse2 profile no longer exists; x64-sse42 is the lowest x64 profile.

Fixes for failed CI runs

Defects in the library or tools that a run exposed:

  • Parsing separate replay results forced full collections at 4,096 records; the sets are presized and the test bounds allocation at 256 bytes per record.
  • A struct return compared layout identity strings during rfl and reached the recursion limit; declaredNarrow answers none for any head other than a primitive or an enum, and declaredNarrow_eq_storage proves the value unchanged.
  • A run that built the certified library kept reading its temporary build directory after publishing, so no later run could restore the support it published; it now reads the published entry, hash-checked against its manifest.
  • On Windows a certified library in a cache path over 259 characters failed inside the build; a run now refuses it when it opens it and names the file.
  • The library cache eviction could remove an entry one millisecond before its deadline without reporting that it gave up; a pass at its limit now reads nothing and removes nothing.
  • The stepper derived a narrow stind fact that never applied and, for a one-byte write, accepted a derived fact the kernel rejects; each derived fact is now type-checked.
  • The extractor read a field operand's name from the specialized copy of a generic body, whose token it cannot resolve; it reads the definition's body.
  • The development pack check of the cli suite rebuilt Extractor/bin with the pack's version stamped in, so later suites in the same job ran another extractor than the job was given (the check is on main; the suites first shared a job on this branch). The pack builds into its own directories and the test fails when the shared extractor's hash changes.

Tests and CI configuration:

  • Negative tests in seven files built type references that no written image can hold; they write the forged scope as an assembly reference. Their expected rejections are unchanged.
  • evidence exceeded its 30-minute limit after seven test libraries were registered in it; the duration table CI packs jobs from now holds measured times, and a job is given at least twice its measured time.
  • 26 checks that decide from elapsed time were tabulated; those a loaded runner could fail decide on counted work or compare their largest size with their smallest. One allocation check and one stepping row each failed once for a cause that is not established; both now report every sample.
  • Tests that stated a generated form as it was before a landing changed it were brought to the current form, twelve times in all. The latest was the evidence narrowing, which matched theorem names without a trailing ? and so kept programIndex_get? while removing the theorem it cites. The three before it were on 49bd7ab3: a cost row wrote ModelsAgree without its profile argument, the runtime model inventory asked only for lowered forms and lost the 90 definitions that became model entries, and a forgery check replaced an intrinsic that is now a modelled call. The hole corpus baseline no longer pins the number of refused corpus methods, which went stale twice. The constant regexes this branch added in tests are [GeneratedRegex] methods (31 call sites in ten files); patterns built at run time stay inline.
  • Eighteen runs passed every job, the latest 44164502709 on 692c0604; a full run takes 60 to 66 minutes. The lookups suite reads each control and each open form in the file of its decided statement, 69 fewer Lean runs, with every row within 0.4 percent.

Measurements

  • The recorded step-equation comparison reduced kernel heartbeats per instruction by 40-64%, with proof bytes increasing 4-21%.
  • Across 36 matched stepping workloads, the return-dispatch change increased frontend heartbeats by at most 0.2967% and kernel heartbeats by at most 0.4098%.
  • Checking one generated Extracted.lean costs 2 to 2.3 times what it costs on main (Add: 4.8M to 11.3M heartbeats). Of the 6.5M added for Add, 4.6M elaborate the literal metadata, name and table bytes and 2.0M run the checks; the checks of the lowered program, 2.4M to 16.4M per file, are still carried beside the decoded evidence.
  • A method defined from its decoder by cil_decoded_method verifies the proofs of Add, Choose and Countdown unchanged, with the same heartbeats, kernel heartbeats and axioms for the correctness theorems. Defining the method costs about 45,000 heartbeats per instruction, 4.1 to 4.3 times the emitted literal with its facts, and adds 6.0 to 6.6% to an extraction module (measured before the field instructions decoded); that is a regression against the 5% threshold, caused by running the decoder once to compute the literal and once in the kernel.
  • Status against the issues on this head (a reading of the work against the criteria; the 74 boxes were last counted one by one at an older head, 28 met, 19 partly and 27 not): none of the five can close. Kernel-check canonical CIL decoding against exact method bytes and metadata #596 is closest: the default check binds bytes and tokens in the kernel, and the deep checks reconfirm 2 of 12 trust facts with cached reuse. Derive and reuse checked semantic summaries over canonical CIL sequences #597 has kernel-checked whole-method summaries with scalar, memory, loop and vector examples and their cost against main; sub-method regions and an invalidating reuse store are missing. Use canonical decoded CIL as the sole executable instruction representation #568, Emit canonical CIL and metadata without constructing specialised executable instructions #582 and Migrate checked execution and consumer proofs from CIL.Op to canonical CIL #598 wait on the same conversion: 84 of 109 instruction constructors decode, 552 of 1,191 distinct example methods decode in full, and the lowered language, the translator and the raw-against-emitted checks are all still present.
  • Summaries against stepping and against main (27953edb, built once; its rows match CI run 43422873269). Heartbeats, with kernel heartbeats in brackets; a summary row includes the summary's own proof, its decoding and its binding. CountCalls: main 10,373,560 (655,554), stepped here 9,807,269 (453,183), through a summary of Decrement 9,949,785 (240,803). Identity64: main 1,543,005 (64,260), stepped 1,556,811 (57,833), summary 2,051,844 (87,160). Repeated: main 2,398,448 (68,830), stepped 2,424,688 (63,273), summary 2,478,344 (103,540). Nested: main 2,414,643 (80,782), stepped 2,440,469 (73,854). Calls for every input, which main does not prove: stepped 8,361,015 (347,408), summary 9,292,411 (237,414). A single use of a summary costs more frontend heartbeats than stepping in every example and less kernel work only for Calls and CountCalls; reuse is where it pays, 52.1M against 158.4M at 16 calls of one callee. Proof objects and module sizes: CountCalls 20,489 objects on main, 18,145 stepped and 11,072 through the summary, in a module of 664,616 bytes on main and 897,144 here; Identity64 2,193, 2,399 and 3,612 objects.
  • The one proof with the same statement on both sides, Calls by rfl at one input, costs 1,882,199 heartbeats and 524,220 kernel heartbeats on this head against 1,412,152 and 374,759 on main: 33% and 40% more for evaluating a decoded method with two calls.
  • Conversion state on this head: Instruction.ofRaw? decodes 84 of 109 instruction constructors, and every other opcode decodes to a hole. The translator files (InstructionTranslation.cs, Operation.cs, TypeTests.cs, Throws.cs, FrameMetadata.cs, ParameterStorage.cs) total 1,532 lines, against 1,327 before the conversions of this PR; Operation.cs also holds the typed operand records, and the count has not been split between those and the lowered forms. 3,673 of 3,764 admitted corpus methods are defined from their decoder. The acceptance coverage above was not rebuilt on this head.

Remaining work

  • Execute decoded CIL directly and delete the lowered language, translator and raw-versus-emitted comparisons. Methods that decode in full are defined from their decoder, but the extractor still emits every evidence theorem for them and still translates every other method. 91 admitted corpus methods keep a literal definition: 34 stop at callvirt, 23 at fields, 19 at ldstr, 13 at an exception constructor followed by throw and 2 at other modelled runtime calls. That corpus is the extractor's own assembly, which is mostly simple code. In the examples assembly 552 distinct methods decode in full under the scalar profile and 639 keep a literal (478 and 713 before the bit and byte-order models). The breakdown that follows was measured before those models and still counts their 74 methods: 490 stop at a runtime call the extractor still translates (Unsafe 224, Span and ReadOnlySpan 91, MemoryMarshal 34, BitOperations 30, Math.DivRem and similar 19, BinaryPrimitives 18), 74 at value-type fields, 64 at initobj, ldobj, stobj or sizeof, 50 at constrained., callvirt or ldftn, and 28 at ldstr or ldtoken.
  • The deep report reconfirms two of twelve binding facts (body bytes and metadata rows). Reconfirmation of platform definitions (type kinds, enum underlying types, the value tuple field order, object fields) has reviewed statements and no code; the other six facts are not started.
  • Summaries (Derive and reuse checked semantic summaries over canonical CIL sequences #597): scalar, memory, loop and vector examples on decoded methods exist with their cost comparison against stepping and against the proofs on main. Reuse of a summary across extractions with its invalidation, and binding beyond the method record (the site lemma cannot conclude the pin while the call check compares owners as text) remain. The migration of the proof corpus (Migrate checked execution and consumer proofs from CIL.Op to canonical CIL #598) waits on canonical execution.
  • Complete typed assembly attribution and scoped metadata, and bind all carried metadata rows and heap entries to pinned image bytes.
  • Reconfirm the ten binding facts that the deep checks still report as not covered.
  • 25 of the 109 Instruction constructors do not decode: instance, virtual and indirect calls, static fields, value-type fields, block and size instructions and runtime tokens.
  • A generic instantiation states the kind of its head and of its arguments, and both come from the extractor: the body check alone accepts a head and its marker flipped together (the specialization, scalar and call checks refuse it), and a platform argument stated as an enum is admitted with an empty platform table. The fix resolves instantiations from the MethodSpec and TypeSpec blobs in Lean; it is ruled and not started.
  • Most of the body check of a method is the kernel converting the name strings its claims state to bytes, at about n^1.5 in the length (154,000 heartbeats at 20 bytes, 2.8M at 160; one 183-byte instantiation name costs 4.35M of an 8.66M check). The library half of the fix is in (byteString, a string stored as its bytes behind a decided spelling, read at 27,474, 92,662 and 353,187 heartbeats at 20, 80 and 320 bytes against 103,840, 604,639 and 2,614,145 for the literal); the extractor does not emit such constants yet. On hand-edited extractions they take 13 to 22 percent off larger extractions. Lean 4.36.0 does not change this cost or the numeral collision cost (both measured on 4.35.0 and 4.36.0).
  • Checking the token table of a body costs 139,000 to 157,000 heartbeats and 3.3 to 3.8 MB of kernel memory per token (69.7M, 151.8M and 235.6M heartbeats at 500, 1,000 and 1,500 tokens; 7.7 GB at 2,000), so a body of 2,000 tokens does not fit the 16 GB memory guard. It is recorded and not fixed.
  • Three reads still cost kernel time linear in a position or a count, because the kernel walks a list: an argument read in its index (5,015, 5,466 and 12,434 heartbeats per instruction at 16, 64 and 256 arguments), a native table load in its entry index, and a native table step in the number of static bindings.
  • Preparing a pinned image compares its identity as text at a cost quadratic in the name length; the binding library takes typed identities next.

The carried metadata is checked internally; its complete correspondence to pinned image bytes remains unfinished. This draft does not yet satisfy every acceptance criterion of the linked issues.

Not verified

  • Each landing was built on the ARM64 build machine (all library targets, no sorryAx), and its changed C# tests, the helper checks, the documentation checks and the recorded corpus files passed on Windows. The suites, including those that share the stepping tactics and the outline suites, run in CI only, as do the Linux branch of the link-following and case-rule path code and the non-Windows branch of the path-length test.
  • Run 44051817837 on dc7a6893, which adds the ldelema conversion, passed in full. The run on 49bd7ab3, which adds the binding page form and the modelled Math and vector calls, failed three suites on tests that the next push fixed, and run 44081993153 on that push passed in full. Run 44107343116 on 6f135727, which deletes the readonly window, passed in full. Run 44122985007 on 2b1ba8e9, which adds the vector summary example, passed in full. Run 44137376339 on 290e747f, which adds the class field and generic arity fixes and the readonly rule at the prefix site, passed in full. Run 44164502709 on 692c0604 passed in full. The run on this head, which makes generated outlines step typed array accesses from shape facts, is in progress.
  • Suite time is above main and has not come down: the same 79 suites took 17,343 s in run 44151461181 on 00560842 against 9,200 s on main (27953edb), 89% more (17,400 s on 75778dc8). The largest increases are lookups (94 to 2,444 s), assemblies (289 to 2,057 s), unsafe (651 to 1,382 s), stepping (105 to 817 s), evidence (799 to 1,438 s) and dispatch (726 to 1,155 s). On 75778dc8, matched by stage, tests added on this branch accounted for 5,368 s and tests on both sides that cost more for 4,521 s. Measured on two batches, the declarations that exist on both sides cost the same or less, and the added cost is the new per-method evidence, led by the body check; the string constants above address its largest part. A full run takes 60 to 66 minutes.
  • Not measured: the structural arm of cil_managed_calls on extracted evidence after the link walk change; the heartbeat comparison on the shared tactic tests after the hole, localloc, starg and ldarga arms joined the first match of step; Tests.StoreFacts and the loop suites after the typed exception change; the linked first pass for instance, virtual and managed calls (the stepping rows exercise call only).
  • The managed-call check costs 14,906, 13,311 and 12,913 heartbeats per site at 64, 256 and 1,024 sites against 10,585, 9,105 and 8,734 before the call conversion; of about 13,300 per site at 256 sites, the table-shape conjuncts take about 1,650, the walk over the zipped lists 4,050, the first link read 2,560 and the link fit 2,200.
  • Tests/SelfAdmission.cs -- --update records an empty baseline and reports success when the extractor in Extractor/bin is a Debug build, in which every method is "not checked". It is not fixed on this head.
  • Open review notes on this head: the statics stepping row passes even without its site facts; Lean admits a class ldflda that the extractor refuses, and its step faults as unsupported; a contract can still be disproved by unfolding invoke by hand over a run that reaches a hole, and the audit would accept that proof.

@benaadams benaadams added feature Adds a capability area: proofs Lean proof API, contracts and tactics labels Nov 14, 2026
@benaadams benaadams changed the title feat(extraction): check extracted methods against their decoded CIL bytes feat(cil): add decoded body checks, metadata binding and typed identities Nov 14, 2026
@benaadams benaadams changed the title feat(cil): add decoded body checks, metadata binding and typed identities feat(cil): add decoded body checks and typed metadata identities Nov 14, 2026
@benaadams benaadams changed the title feat(cil): add decoded body checks and typed metadata identities feat(cil): check decoded bodies and typed metadata identities Nov 14, 2026
@benaadams benaadams changed the title feat(cil): check decoded bodies and typed metadata identities feat(cil): validate decoded bodies, metadata and deep proof bindings Nov 14, 2026
@benaadams benaadams changed the title feat(cil): validate decoded bodies, metadata and deep proof bindings feat(cil): migrate execution and proof bindings to decoded CIL Nov 14, 2026
ParameterEvidence, ConstrainedCalls, GenericOwners, NativeManagedDispatch, LookupScaling and
DecodedOpcodes read the defined methods, the decoded form and the literal instructions through the
helpers in GeneratedEvidence.cs instead of a pattern of their own.
…forgery

The component invalidation check edits the add the helper's decoder reads through the helper that
refuses a method kept as a literal.
… test helpers

Brings the extractor's reading of a field operand's name from its definition's body in every raw
method, the check that a specialized body's closed raw method names its field operand, the hole
corpus recorded over the merged extractor and the name of the link key fact in the binding guide.
No file conflicted; Tests/ConstrainedCalls.cs keeps both the method count through the shared helper
and the incoming field operand check.
Brings in the tests that read or rewrite generated method text, moved onto
shared helpers that understand a method defined from its decoder.

Tests/GeneratedEvidence.cs gains the helpers: one forges the decoder call
with a structure update of the decoded method, one edits the raw definition
the decoder reads, one forges the declared return type, and three read
whether and from what a method is decoded. Each fails on a method kept as a
literal, so a reader never takes an absent body for an empty one.

GenericEvidence, PointerOperations, StackAllocation, ReferenceInstructions,
Objects and ConsumerComponents forge through the helpers; every rejection
test is kept and names the check that refuses it. ParameterEvidence,
ConstrainedCalls, GenericOwners, NativeManagedDispatch, LookupScaling and
DecodedOpcodes read through them.

Nothing conflicted.
The raw call opcode (0x28) is now `Instruction.call (method : MethodRef) (prefixes : CallPrefixes)`,
with `tail.` and `constrained.` carried as prefixes. Its target is the link at its pc, so the lowered
`call`/`tailCall` index-and-count forms and their step arm are gone; the argument count is
`method.argumentCount`.

- Instruction.ofRaw? decodes opcode 40 to the call its operand names; Method.ofRaw?, Method.ofBody?
  and decodedProgram? take the link table, so cil_decoded_method defines methods with calls.
- linksOfCode implies no link for a call; Method.withCode keeps only implied links, so a body with
  calls states its links. ManagedCallsValid requires ascending keys bounded by the code and a
  .direct link at every call pc, read by one walk beside the code.
- The call check ties the operand to the call site's method and the link to its token; constrained
  calls require the constrained prefix and no tail prefix. FeatureFlowValid and calleeConstant read
  the link of the pc.
- Forwards, ForwardsOut and WP.load_call_store take the call's MethodRef and its arity.
- MethodIdentity and StructuralLabels state call facts over the MethodRef; a dsimproc reduces
  MethodRef.argumentCount of a literal during stepping.
- The extractor writes each call over its closed operand term and passes the link table to the
  decoder, and decodes methods with plain static calls.
…ranch

Brings in the shared decoded-method helpers of Tests/GeneratedEvidence.cs and the forgeries and
readers rewritten onto them. The merge had no conflicts; every file keeps both sides.
Raw newobj (0x73) decodes to `.newobj constructor`, where `constructor` is the
typed MethodRef its operand names. What it builds and which method it enters
come from the link of its pc in the method's table: `.aggregate callee size`
for a value type, `.object callee bases size` for a class. The lowered
`newAggregate` and `newObject` instructions and their translator arms are
gone.

Link form: each method's links are one named table, `method{n}Links`, of
`(pc, method{n}Link{pc})` entries. The literal states `links := method{n}Links`
and the decoder takes the same constant, `Method.ofRaw? profile environment
method{n}Links original typeArguments`, so a decoded method's links are the
extractor's and there is no second representation. `Instruction.readsLink`
marks the instructions whose step reads the table. ManagedCallsValid checks
each pc with the link the table gives it: a non-construction must have the
link its code implies, and a live newobj must pass validateConstructionWith,
which requires a raw managed newobj site naming exactly the instruction's
constructor, the linked method to be the one the site names, an `.object`
link for a class constructor with an object receiver and an `.aggregate` link
for a value type, the link's bases to be those the constructor's raw method
records, and the size to be one slot per instance field. A forged link index,
kind, base list or size is rejected.

The extractor's table of decoded opcodes gains newobj. A newobj whose
constructor the literal emits as a runtime model (span constructors,
exception constructors, System.Object) keeps its method's literal through the
RuntimeMethod refusal.

objectSiteType, StepEffect, StepContract and SiteConsistent take the pc, and
ObjectSitesConsistent quantifies over pcs of each body.
Brings in the helpers in Tests/GeneratedEvidence.cs that read and forge a
method defined from its decoder, and the tests moved onto them.

The helpers now match and write the decoder call with the method's link table,
`Method.ofRaw? profile environment method{n}Links original typeArguments`, and
a forged decoder takes and passes on the table.

The one conflict, in Tests/GenericEvidence.cs, kept the link forgeries that edit
the named `method{n}Links` table: the dropped link, the link at a wrong pc and
the link at a non-call each change the table that both a literal and a decoded
method read, and each is still refused by the method's ManagedCallsValid
decision.
Call sites name their method and take their target from the link at their pc, so the C# tests forge a call's target by its link definition (ForgeLink, DirectLinks in Tests/GeneratedEvidence.cs), forge a decoded method's links through the table its decoder is given, and check the rendered call and tail prefix. The managed-call cost fixtures, the embedding fixtures and the stepping calls workloads write the call over a MethodRef with an explicit link table.
step_newAggregate, step_newAggregate_action and run_newAggregate_of_contract
named the deleted lowered instruction; they are now step_newobj_aggregate,
step_newobj_aggregate_action and run_newobj_aggregate_of_contract. Long lines
from the conversion are wrapped to the limits.
…ow rejections by method

A call implies no link, so the binding and embedding docs and the skills supply a body's call links after withCode, and the parametric-body example writes its link table over the callee parameter. Rejection tests match a decided-false FeatureFlowValid by the method's own certificate arguments (FeatureObligation), since the printed obligation now carries the method's link reader between the constants and the closed signature.
…traction does

The constructions body names its constructor by a full MethodRef literal, the
form an extraction emits, instead of a structure update of MethodRef.arity.
…ts equation

The newobj step equation matches on the link at its pc. With the link fact
applied only in the second pass, simp carried and simplified both the value-type
and the class arm before the match reduced. cil_checked_linked_step_by_equations
adds the link fact to the first pass, so only the linked arm is simplified.

Constructions stepping (frontend HB / kernel HB per instruction):

  instructions          16             64             256
  base b921cb2         472527 / 7299  433397 / 4258  424162 / 3497
  before (7c7293f)     529335 / 8570  495324 / 4739  487198 / 3781
  named constant        527838 / 8555  494385 / 4729  486455 / 3772
  count dsimproc        529376 / 8570  495369 / 4739  487244 / 3781
  link in first pass    436205 / 6811  393267 / 4079  382842 / 3396

The named-constant row writes the constructor as a reducible definition the
body names; the count row reduces parameters.length of a literal MethodRef by
a dsimproc. Neither moves the row by more than 0.3%; only the link pass does.
step_call_eq now states a call's step as callStep of the link at its pc. Stepping rewrites the call's argument count and prefixes in place; under a match on the link, the kernel checked that rewrite by unfolding the matcher and evaluating the link table's read, which costs the pc's position in the table, so a body of n calls cost the square of n. A regular definition lets the kernel compare the arguments instead. The calls and tablecalls stepping rows measured 10827, 16474 and 47170 kernel heartbeats per instruction at 16, 64 and 256 before this change.
The first pass of a newobj step took every supplied fact along with the link
fact, so caller facts such as allocation results rewrote before the step
equation's guards were simplified. Only the generated link fact now joins the
first pass; supplied facts apply in the second pass as for any other step.

Constructions stepping (frontend HB / kernel HB per instruction):

  instructions          16             64             256
  base b921cb2         472527 / 7299  433397 / 4258  424162 / 3497
  all facts first pass  436767 / 6811  393875 / 4079  383449 / 3396
  link fact only        438693 / 6825  395870 / 4082  385510 / 3396

The link fact accounts for the gain; supplied facts in the first pass add 0.5%.
Brings in newobj as one decoded instruction, .newobj over its constructor's
MethodRef, in place of the lowered newAggregate and newObject forms, whose
instructions, translator records and step lemmas are deleted.

Each method states one named link table that its literal, its evidence and
its decoder all take, so a decoded method's links are the extractor's.
ManagedCallsValid ties every live newobj to its raw site: the site names the
instruction's constructor, the linked method is the one the site names, a
class gets an object link and a value type an aggregate link, and the bases
and size match the constructor's raw method. Negative tests reject a forged
link index, kind, base list, size, a missing link, a call opcode and a
constructor owner the site does not name.

The stepper rewrites a newobj step's link fact in the pass that applies its
equation, so only the arm of the link's kind is simplified. Constructions
stepping measures 438693 / 395870 / 385510 frontend heartbeats per
instruction at 16 / 64 / 256, against 472527 / 433397 / 424162 before.

Consumer-visible: step_newobj_eq; the aggregate lemmas are named for newobj
and take an aggregate link premise; StepEffect, StepContract, SiteConsistent
and objectSiteType take a pc; step_callee concludes readsLink; extractions
write method{n}Links, methodEvidence.links and method{n}_links.

2,595 of 3,742 admitted corpus methods are defined from their decoder.
Constructors of span, exception and System.Object stay literal models.

Nothing conflicted.
The extractor's own code is the corpus, so replacing the NewAggregate and
NewObject records with Newobj and MethodRef moves it: 3,742 of 13,284 methods
are admitted and 2,595 are defined from their decoder.

canonical-methods.txt drops the 14 getters and init setters of the two deleted
records, which no longer exist, and gains 304 methods. The hole corpus skips
9,542 refused methods.
…r calls

The corpus now has 13,402 methods, 3,759 of them admitted and 3,669 defined from their decoder. LeanEmitter.RecursionDepth, whose first refusal was a Math call, decodes in full, and the ModelCall record carries the operation it runs as, so its parameterless constructor leaves the list and its three new members join it. 90 methods keep a literal: 34 stop at callvirt, 23 at fields, 18 at ldstr and 15 at a translated call or construction.
…ummary

DivisionIntrinsics.UnsafeLowNext returns UnsafeLow of its argument plus one. UnsafeLow runs
Vector128.CreateScalarUnsafe and GetElement through their runtime models, calls without a link, so
its record decodes in full and its contract binds as a DecodedSummary like any other body. The
VectorSummary example proves the caller's result once by stepping UnsafeLow and once from that
summary, and runs in the core suite.

Tests/SummaryCalls.cs forges the original of UnsafeLow to read the other lane: the body check
refuses the record and the summary rests on sorryAx. The compiler coverage baseline admits the new
caller under every compiler column. The examples, contract and validation pages and the
proof-writing skill describe the example.
ModelsAgree takes the feature profile since a modelled call must be available under the profile of its method, and the cost row of Tests/LookupScaling.cs still wrote the statement without it, so the generated file did not elaborate and the lookups job of run 44072748947 failed. The row states the scalar profile; it costs 205,276, 661,306 and 2,492,234 heartbeats at 8, 32 and 128 sites.
…entory

The runtime model inventory asked the extractor only for the lowered form of each runtime method, and the translator now asks first whether the Lean model table models a call, which keeps its call. The integer Math helpers and the scalar vector calls moved to that path, so the inventory reported 90 definitions removed and the dispatch job of run 44072748947 failed, although the same methods are still modelled.

The inventory now asks for the call model before the lowered form, as the translator does. Its recorded list keeps every earlier entry and gains the System.Object constructor, which has been a model entry since it stopped being lowered to a pop: 474 definitions in 44 families.
The external call check of Tests/GenericEvidence.cs replaced the emitted createScalarUnsafe64 intrinsic of DivisionIntrinsics::UnsafeEquals with another intrinsic and required ExactIntrinsicsValid to refuse it. CreateScalarUnsafe is now a modelled call, so the replacement found nothing and the evidence job of run 44072748947 failed with "Call mutation was not applied". The check forges the comparison intrinsic the body still emits, and ExactIntrinsicsValid refuses it; a forged modelled call is refused in Tests/RuntimeModels.lean.
Brings in ldelema decoding with its readonly. prefix, byte lists and binding
image pages in the joined digit form, the modelled Math helpers and scalar
vector calls, type definitions and nesting checked against image rows, the
runtime inventory and model agreement fixes and the re-recorded corpus files.

Every file merged without a conflict. Scalars.lean, GenericEvidence.cs,
MetadataSlices.cs, BodyLiteral.lean, Tests/GenericEvidence.cs and the
OPCODES, SOUNDNESS-EVIDENCE, SOUNDNESS-RUNTIME and VALIDATION documents
keep both sides: the opaque class field heads, the generic arity rows and
the new marker rejection alongside the incoming changes.
… into the vector summary

The incoming side counts the calls the model table models in the runtime inventory, states the
model agreement row with its profile and forges the intrinsic the external call fixture still
emits. It changes only tests; no file conflicted.
…ndow

The ldelema decoding commit made Instruction.ofRaw? refuse every instruction after
readonly. other than ldelema, made ldelema decode its flag from the instruction before
it, and added readOnlyDecodedMatches to the scalar check. With that, the readonly
window decided nothing PrefixEntryFree and decoding do not, as
ScalarFlowValid_iff_decodedReadOnly showed. This deletes the window
(readOnlySiteWindow, readOnlySiteMatches, followsReadOnly and their lemmas),
ScalarFlowValidWith, ScalarFlowValid_iff_decodedReadOnly with its helper lemmas, and
MethodEvidenceValid.scalarFlowValid_decodedReadOnly. ScalarFlowValid is now the check
with no readonly parameter.

checkScalarSite takes the raw instruction before each site from `predecessors`
(`none :: code.map some`), zipped into the list all3Flow walks, instead of
`rawBefore rawAt pc`. ScalarFlowValid.instruction_checked keeps its statement at
`rawBefore (raw.code[·]?) pc` and proves it through predecessors_getElem?.

A branch into the address after readonly. now passes ScalarFlowValid and is refused
by PrefixEntryFree, which body decoding establishes
(Tests/ReadOnlyArrayReferences.lean branch_into_address_rejected). The single-site
window tests are gone; the decoded-rule tests check ScalarFlowValid alone.
LookupScaling no longer measures the window next to the prefix entry rule.

These extractor checks refuse the same bodies before Lean sees them, and they stay:
InstructionPrefixes.ValidateTaker (an instruction other than ldelema after readonly.,
or readonly. at the end of a body) and InstructionPrefixes.ValidateEntry (a branch
into the instruction after a prefix). Neither became unreachable: the extractor runs
both before it emits a body.

Kernel heartbeats per site of the LookupScaling rows at 128 / 256 / 512, before the
ldelema decoding commit, after it, and after this commit:

| Row | Before | After decoding | This commit |
| --- | --- | --- | --- |
| plain addresses | 274065 / 274402 / 277621 | 292593 / 294890 / 300715 | 268857 / 268876 / 271776 |
| readonly addresses | 377827 / 385402 / 396905 | 419350 / 429306 / 443981 | 344972 / 345706 / 350124 |
| block copies | 462296 / 465056 / 472062 | 478759 / 483431 / 492992 | 469905 / 475862 / 489267 |
| unaligned block copies | 553858 / 558367 / 568629 | 574675 / 581542 / 594935 | 563689 / 572802 / 592279 |
| integer locals | 57115 / 57069 / 57472 | 61909 / 62187 / 62913 | 57701 / 57655 / 58057 |
| addressed integer locals | 59743 / 59708 / 60122 | 64537 / 64825 / 65563 | 60329 / 60293 / 60707 |
| native-int locals | 55581 / 57202 / 59254 | 60432 / 62375 / 64748 | 56251 / 57872 / 59924 |

Every row is within 2% of the row before the decoding commit except block copies,
+3.6% and +4.2% at 512 (+1.6% and +1.8% at 128). Measured at 512 copies on the
parent with the decoding commit reversed and on this commit (millions of
heartbeats, plain / unaligned): 241.70 / 291.14 against 250.50 / 303.25. Dropping
readOnlyDecodedMatches from this commit's check saves 1.26 / 1.50, so the rest of
the gap comes from walking the zipped predecessor list. The decode, method decode,
decoded definition, decoded program, prefix entry and compile rows are unchanged
by this commit.
…dow removal into the vector summary

The incoming side streams the predecessor in the scalar certificate and drops the readonly window,
with its tests, cost rows and documentation. No file conflicted.
Brings in the decoder that streams the previous instruction and drops the
readonly window, with its lookup scaling rows, readonly array tests and
documentation.

Scalars.lean merged without a conflict and keeps both sides: the opaque
class field admission next to the streamed predecessor.
Brings in the vector example for decoded summaries. DivisionIntrinsics.UnsafeLowNext returns
UnsafeLow(x) + 1, and Examples/Proofs/VectorSummary.lean proves that once by stepping through
UnsafeLow and its CreateScalarUnsafe and GetElement model calls, and once from a DecodedSummary of
UnsafeLow, which needed no change to the summary shape. Tests/SummaryCalls.cs forges UnsafeLow to
read the other lane; the body check refuses the record and the summary rests on sorryAx.

The stepped proof costs 3,192,215 heartbeats, 118,705 in the kernel, and 3,488 proof objects; the
summary route with its own proof, binding and decoding costs 3,506,999, 139,650 and 4,614, more on
each measure for one use of a callee this small. The compiler coverage baseline gains the new
caller.

Nothing conflicted.
Each statement-only control of the lookups suite is now elaborated in the
same file as the decision it is subtracted from. PartHeartbeats reads a
heartbeat count after every part of one file, less the cost of a reading,
with three readings after the first part so the evaluator is warm; the
decided statement follows its stated form, so the shared header is
elaborated once. This removes 39 Lean runs. The element shape rows share
the 8-type, 8-site sample, which is now elaborated once.

Every row keeps its bound and size; a side-by-side run of the old and new
suite gives the same heartbeats to within 0.1 percent per row.
…one file

Each body, tables, spelling and calli selection row of the lookups suite
now reads its proof in one file: the extraction narrowed to the body
obligation, with every measured proof preceded by the same theorem closed
with sorry under another name, both read between heartbeat counts. The
rows of one extraction share that file, so the tables row of the bulk and
field extractions is read beside their body row. This removes 30 Lean
runs.

Every row keeps its bound and size; a side-by-side run of the old and new
suite gives the same heartbeats to within 0.4 percent per row, the largest
difference being 89 heartbeats on the 20-byte spelling row.
The scalar check walked a list of every site's predecessor so that each site
could check that it was not an instruction other than ldelema after readonly.
Walking that list cost block copies 3.6% and 4.2% per copy at 512 copies, and
locals about 1%, over the check before the ldelema decoding commit. The rule now
sits at the prefix site: readOnlyPrefixMatches requires the raw instruction after
a readonly. to be ldelema (143), so a readonly. that ends the body is refused.
That equals the follower form: a reachable readonly. falls through to the
instruction after it, and PrefixEntryFree keeps every branch out of that
instruction. readOnlyDecodedMatches keeps only the decoding of readonly. and
ldelema, and checkScalarSite passes `rawBefore rawAt pc` to scalarEmissionMatches
again, which reads the predecessor only at the sites whose decoding needs it.
`predecessors` and predecessors_getElem? are gone; ScalarFlowValid.instruction_checked
keeps its statement at `rawBefore (raw.code[·]?) pc`.

Tests/ReadOnlyArrayReferences.lean keeps every refusal and its reason:
- final_prefix_refused, wrong_followers_refused (readonly. readonly. ldelema,
  readonly. nop ldelema, readonly. ldelem) and prefixed_call_refused now also
  state that readOnlyPrefixMatches refuses the prefix site.
- unaligned. ldelema, both wrong flags and another element type are refused by
  decoding, as before.
- dead_prefix_follower_refused is new: a dead readonly. followed by a live ret that a
  branch reaches passes ScalarFlowValid and is refused by PrefixEntryFree.

Kernel heartbeats per site of the LookupScaling rows at 128 / 256 / 512, before the
ldelema decoding commit, after it, after the commit that streamed the predecessor,
and after this commit:

| Row | Before decoding | After decoding | Streamed | This commit |
| --- | --- | --- | --- | --- |
| plain addresses | 274065 / 274402 / 277621 | 292593 / 294890 / 300715 | 268857 / 268876 / 271776 | 273707 / 274038 / 277254 |
| readonly addresses | 377827 / 385402 / 396905 | 419350 / 429306 / 443981 | 344972 / 345706 / 350124 | 357580 / 359265 / 364641 |
| block copies | 462296 / 465056 / 472062 | 478759 / 483431 / 492992 | 469905 / 475862 / 489267 | 461259 / 464020 / 471028 |
| unaligned block copies | 553858 / 558367 / 568629 | 574675 / 581542 / 594935 | 563689 / 572802 / 592279 | 552545 / 557055 / 567319 |
| integer locals | 57115 / 57069 / 57472 | 61909 / 62187 / 62913 | 57701 / 57655 / 58057 | 56891 / 56845 / 57248 |
| addressed integer locals | 59743 / 59708 / 60122 | 64537 / 64825 / 65563 | 60329 / 60293 / 60707 | 59519 / 59484 / 59898 |
| native-int locals | 55581 / 57202 / 59254 | 60432 / 62375 / 64748 | 56251 / 57872 / 59924 | 55442 / 57063 / 59115 |

Every row is at or below its value before the decoding commit. The decode, method
decode, decoded definition, decoded program and prefix entry rows are unchanged,
and compiling an extracted method costs 270724 and 264484 per instruction, against
271537 and 265296 for the streamed check.
Brings in two binding fixes. A class instance field typed System.Object or as
a generic class is admitted in Lean as the extractor admits it: the held type
of the operand is the type the signature decodes to, a class-like generic
instance is an application over a head that states it is a class, and the
binding check compares that head with the kind the metadata gives. The 45
corpus methods (88 admitted entries) that Lean refused with an operand
mismatch are accepted, and forged heads are refused. The arity of a generic
owner is tied to its GenericParam rows: an owner with no parameters carries
the adjacent rows that bracket it, so a type definition with parameters named
without its arguments is refused; this rests on the table being sorted by
owner, as ECMA-335 requires.

Each slice carries about a quarter more rows for the brackets (64,193 to
80,994 over the corpus). Over 60 corpus extractions total heartbeats rise by
3.0 percent, the tables check by 28 percent and the body check by 4 percent.
Tests/SelfAdmission.cs gains an opt-in mode that checks every admitted entry
in Lean, about 2.7 CPU-hours, which no suite runs.

Open after this: a generic instantiation's head marker and its head are both
stated by the extractor, so flipping both together is caught only by the call
site's own checks.

Nothing conflicted against the readonly rule at the prefix site.
The extractor gains MetadataSlices.Slice.GenericOwnerCode, which is admitted and defined from its decoder: the corpus has 13,410 methods, 3,760 admitted and 3,670 defined from their decoder. The 90 literal methods and their first refusals are unchanged.
modelStep_memory states that a runtime model of a memory operation steps
exactly as the .memory instruction of that operation: both guard the
operation's argumentCount operands for unspecified bits and run
memoryInstruction. step_call_memory composes it with step_call_model, so
a link-free call whose method's model is a memory operation rewrites to
that instruction and its existing step equations apply. The runtime
model tests reach a success and the unspecified-bits fault through it.
docs/VALIDATION-COVERAGE.md now says that the readonly. before a call is refused at
its own site and that a live instruction after a dead readonly., which a branch
reaches, is left to PrefixEntryFree, as dead_prefix_follower_refused shows.
A typed ldelem or stelem stepped through the instruction-level facts
arrayLoad_of_element, arrayStore_of_write and arrayTransferInstruction, which the
stepper applies under the step's bind, pair projections and shape match at every
access. CIL/Safety/ArrayContents.lean now derives the step-level fact once from
the element shape fact cil_resolution_facts declares:
- step_ldelem_any_of_element and step_stelem_any_of_write for an integer, enum,
  bool or char element, from the element's address and its load or write;
- step_ldelem_any_of_transfer and step_stelem_any_of_transfer for a struct or
  vector element, from its transfer.
The lemmas carry no cil_step attribute, and no tactic library changes. The
typedelements row of Tests/SteppingScaling.cs derives its four facts from
body_elementShape0 and body_elementShape1. Proving the shape by rfl instead
costs about 245,000 kernel heartbeats per proof (21,302 per instruction at 16).

Per instruction at 16 / 58 / 254 instructions, frontend and kernel heartbeats:

| Row | Frontend | Kernel |
| --- | --- | --- |
| typedelements, lowered to step-level facts | 273581 / 159922 / 126037 | 5811 / 2920 / 2068 |
| typedelements before this commit | 275612 / 175995 / 145695 | 8019 / 3769 / 2519 |
| typedelements after this commit | 256343 / 148602 / 116353 | 5859 / 2893 / 2019 |
| typedsteps, supplied step facts | 262986 / 150552 / 117051 | 5697 / 2875 / 2044 |

Against the lowered row, frontend is 6.3%, 7.1% and 7.7% lower and kernel 0.8%
higher, 0.9% and 2.4% lower. The lowered row was measured before the history
rewrite; the others on this commit's parent. The typedsteps, elements and
addresses rows are unchanged.
…ded spelling

A String may now be built from its UTF-8 bytes, so bytesOf of it reads
those bytes instead of encoding the text in the kernel.

- KernelEquation: utf8Characters_decode, the inverse of
  utf8Characters_encode, for any list of characters.
- MetadataBytes: spelled?_bytesOf (spelled? (bytesOf s) = some s, for
  every String s, no condition), byteArray_of_spelled, byteString and
  byteString_eq. byteString bytes text h takes h : spelled? bytes = some
  text, decided once by cil_kernel_rfl where the string is defined.
- MetadataBinding: MethodNames.spelledBy compares the owner and base
  bytes with bytesOf of the method's strings; spell_of_spelledBy turns it
  into Spell without spelling the names in the kernel.

Tests: a byteString whose bytes are not its literal is refused by
cil_kernel_rfl at its definition; a claim naming another stored string
is refused by the check that refuses the wrong literal, with the same
error, for checkTypeOperand, checkCallOperand, checkFieldOperand,
methodIdentityValid, Frame.admits and Spell.

The lookups suite pins bytesOf of a stored name against its literal
(read cost, definition cost, literal cost in heartbeats):

  20 bytes    27,474    44,043    103,840
  80 bytes    92,662   119,864    604,639
  320 bytes  353,187   422,903  2,614,145
A method whose signature has no GENERIC flag and that carries no run or link
has no generic parameters, as ECMA-335 requires of its GenericParam rows, so
the extractor no longer carries the neighbouring rows that showed it. A carried
run is still read and checked against the signature's count, and a method
that declares parameters keeps the neighbour rule.

Over the same 60 corpus extractions against the tree without generic owner
rows, total heartbeats fall from +3.02% to +1.72%, the tables check from
+27.9% to +15.6% and the body check from +4.0% to +2.3%.
A typed ldelem or stelem in a generated outline now steps by
step_ldelem_any_of_element, step_stelem_any_of_write or the new
step_stelem_any_of_wide_write, citing the shape fact
cil_resolution_facts declares for its element type
(Extracted.method{n}_elementShape{k}). ProofOutline.ShapeFacts numbers
the element types in raw pc order as that command does, and an outline
refuses a typed access whose numbering it cannot reproduce.

The outline catalog gains ReadGeneric<UInt32> and ReadGeneric<UInt64>,
extracted with --type-argument; no earlier outline reached a typed
access. Tests/ResolutionFacts.lean steps a four- and an eight-byte
typed store from shape facts and checks that a four-byte shape cannot
step the eight-byte store.

Untyped array outlines change only in where the cil_checked_steps line
of an array read breaks (ArrayReadInt32, ArrayReadUInt64); the other
100 catalog outlines are byte-identical to what they were.

Cost of the correctness theorem of ReadGeneric<UInt32>, raw heartbeats
on this thread (Elab.async false):
  arrayLoad_of_element              1,749,078
  step_ldelem_any_of_element        1,753,154  (+0.23%)
  ReadGeneric<UInt64>, step lemma   1,754,976

A specialized generic entry names its type arguments, so the generated
postcondition docstring of ReadGeneric<System.UInt32> ran past 100
columns and new-proof refused the method; the sentence now breaks before
its subject when it does not fit on one line.
The outline generator gains the shape accessors of a numeric array access and the closures of ProofOutline.ShapeFacts: the corpus has 13,417 methods, 3,764 admitted and 3,673 defined from their decoder. One more admitted method stops at ldstr, so 91 keep a literal.
memory_stepRenamed proves RuntimeModel.StepRenamed for the model of any
MemoryOp, so a model table entry that resolves only memory operations
adds its case to runtimeModel_stepRenamed by naming it. The model runs
as memoryInstruction behind the unspecified-operand guard, and
Memory.Renamed.memoryInstructionResult already relates that
instruction's results on renamed memories.

StepRenamed gains two premises, both required by
memoryInstructionResult:
- The source memory is well formed (source.WellFormed). The memory
  relation alone does not give the allocation and view invariants the
  memory instruction proofs read.
- The source model step succeeds or throws (SuccessOrThrow of
  modelStep on the source). memoryInstructionResult relates results only
  for an observable source run; an invalid state or an unsupported
  operation has no renamed counterpart to state.

Memory.Renamed.stepBoundary already holds both, as its formed and
observable hypotheses, and passes them to the private stepCall. stepCall
forwards them to runtimeModel_stepRenamed after rewriting the observable
run by the call's link and model. The object constructor and intrinsic
cases ignore the new premises. Nothing outside BoundaryStepRenaming.lean
states StepRenamed or calls stepCall, so no consumer statement changes.

Tests/RuntimeModels.lean instantiates the case for a whole-array view, a
span copy and an out-operand division, and derives the case for any
entry family that resolves only memory operations.
Program.closure read each visited method with program[index]?, so a
closure of n methods cost O(n * P) list steps in a program of P. The
search now takes a lookup: ClosureSearch.visit and run read through it,
closureWith is the only body of the search, and Program.closure is
closureWith (program[.]?) program.length root. Program.closure_eq_closureWith
rewrites a closure to closureWith over any lookup that agrees with the
list, so a proof decides it over an index stated once and pays
O(n * log P + e). No statement of closure_closed, closure_relocates or
closureEvidence_decodes changes.

program_index% (CIL/Extraction/FlowIndex.lean) writes FlowIndex.ofList
of a list as a literal tree whose leaves are the list's cell terms;
ModelTable reuses its list reader. Every extraction now states
programLength, programIndex and programIndex_get?, each checked once:
programIndex_eq is one cil_kernel_rfl against FlowIndex.ofList program,
which compares method{n} constants without unfolding them.
Tests/ProgramClosures decides its closure through the index.

Elaborating the whole Extracted.lean (raw heartbeats, Elab.async false):

| Extraction | Methods | Before | After |
| --- | --- | --- | --- |
| Arithmetic::Add | 1 | 12590029 | 12651370 (+0.49%) |
| VirtualCalls::DogLegs, largest example | 5 | 47892265 | 47983482 (+0.19%) |
| chain of 16 (generated Bodies) | 16 | 107812209 | 107980274 (+0.16%) |
| chain of 128 (generated Bodies) | 128 | 957295634 | 958228563 (+0.10%) |

The closure row of Tests/LookupScaling.cs decides each closure through
its stated index and reads n * log P + e units; it adds a long chain at
128/256/512, keeps the list form beside it, requires the four-method
tail to cost less through the index at every size, and measures stating
the index. Kernel heartbeats:

| Shape | Sizes | Through the index | Through the list |
| --- | --- | --- | --- |
| chain | 8/32/128 | 87394 / 335656 / 1422953 | 90395 / 437519 / 3533840 |
| long chain | 128/256/512 | 1422542 / 3013064 / 6568957 | - / - / 43269245 |
| fan | 32/128/512 | 140799 / 367218 / 1273057 | 144084 / 370459 / 1276182 |
| tail | 128/512/2048 | 55819 / 58512 / 61237 | 81699 / 179818 / 571795 |

Growth per unit between the last sizes and the first: chain 0.84, long
chain 1.02, fan 1.00, tail 1.01. Stating the index at 128/512/2048
costs 260137 / 857704 / 3248483 heartbeats (1.00 per method). The list
long chain at 512 was measured from a probe of the row's file.
A call of a BitOperations helper (IsPow2, PopCount, LeadingZeroCount,
TrailingZeroCount, Log2, RoundUpToPowerOf2, RotateLeft, RotateRight), of
the same helper an integer type declares, or of
BinaryPrimitives.ReverseEndianness now keeps its call and runs the
scalar intrinsic the runtime model table gives its method reference, in
place of the lowered intrinsic, which no Lean check tied to its call.

- CIL/Extraction/BitModels.lean adds one entry per owner and name: 8
  under BitOperations, 61 on the ten integer types, and ReverseEndianness
  under the exact System.Memory scope. An entry's resolve gives a model
  only to a static, non-generic reference that takes one runtime integer
  type, then Int32 for a rotation, and returns the result its owner
  declares: Int32 for a BitOperations count, the type itself (a 64-bit
  word only at 64 bits) for a count the type declares, Boolean for
  IsPow2. Signed Log2 and signed 8- and 16-bit rotations have no entry.
- modelEntries, runtimeModels_entries and runtimeModel_stepRenamed gain
  the entries; bitEntries_yields gives each model as an intrinsic.
- BinaryTransfers reads spanMemoryScope; its private copy binaryScope of
  the same System.Memory literal is deleted.
- Extractor/BitModels.cs holds the exact signatures and CallModel asks it
  first; the bit loops of BuildScalarOperations and ReverseEndianness()
  are removed from RuntimeModels.cs.

Tests/BitModels.lean states each group's resolution, one kernel-checked
test per result rule (BitOperations.PopCount gives an int word,
UInt64.PopCount a long word, UInt32 and Byte counts an int word), the
rejections (receiver, generic arity or method argument, wrong or mixed
parameter, wrong result, signed Log2, signed narrow rotation, an
undeclared helper, another owner, assembly or opcode), one mutation per
group (LeadingZeroCount emitted at a PopCount site, UInt64.PopCount with
an int word, ReverseEndianness(ulong) at 32 bits), each refused and each
accepted by a table without the helpers, the same agreement under the
scalar and AVX2 profiles, and steps against the lowered intrinsic: the
counts and Log2 of zero, RoundUpToPowerOf2 of 0x80000001, and the byte
reversal of a sign-extended short and sbyte.

Tests/RuntimeModelInventory.txt is unchanged: 474 definitions. CallModel
admits exactly the signatures Translate lowered, and signed Log2, signed
8- and 16-bit rotations and the Int128 and UInt128 BigMul forms were already
absent from it.

Call sites: the examples have 104 (BitOperations 32 in 30 methods, the
integer types' own members 61 in 34, ReverseEndianness 11 in 11); the
self-admission corpus has 2 (BitOperations.RotateRight(uint) and
PopCount(ulong)). Example methods that decode in full under the scalar
profile: 478 -> 552, none lost; methods kept as literals 713 -> 639.
Corpus: 3,764 admitted and 3,673 decoded, unchanged.

Rows, before and after: the lookups model lookup and agreement rows are
unchanged (their tables are synthetic); in one file, deciding the
runtime table's lookup of Math.Max costs 276,653 kernel heartbeats on the
table without the helpers and 276,208 on the runtime table (8 -> 17 name
groups, 49 -> 119 entries). Stepping, frontend / kernel heartbeats per
instruction:

  calls 16/64/256              unchanged
  objectconstructors 16        185,725 / 4,517  ->  185,717 / 4,517
  objectconstructors 256       103,425 / 2,075  ->  103,443 / 2,075
  intrinsiccalls 14            248,249 / 6,492  ->  248,233 / 6,492
  intrinsiccalls 62            161,284 / 3,281  ->  161,295 / 3,281
A call of PopCount, LeadingZeroCount, TrailingZeroCount or Log2 of
BitOperations or of an integer type keeps its call since the bit
helpers joined the runtime model table, so its operation is
ModelCall(ScalarIntrinsic). Body.Pure and the scalar path walk matched
only a bare ScalarIntrinsic, so an outline that reached such a count
stopped there with a hole where it had stepped before.

Body.Pure (ProofOutlineLoops.cs) and the result width of a pure word in
the scalar path walk (ProofOutlineScalar.cs) now match the model call;
cil_checked_steps already steps it with step_call_intrinsic. No
extractor path emits a bare count intrinsic any more, so the bare
pattern is replaced, not kept beside it.

No outline matcher ever covered the other bit helpers (rotations,
IsPow2, RoundUpToPowerOf2, ReverseEndianness), as a bare intrinsic or a
model call; ReverseI16 and PowerU32 stay outlined with a hole, as
before.

Tests/ProofOutlines.cs adds Population64 (BitOperations.PopCount of a
ulong) and PopulationU32 (UInt32.PopCount) and checks each outline steps
its whole body. With the matchers reverted, the Population64 check
fails. outlines-control passes: 41 outlines.
NarrowEvidence removes every generated theorem except the obligation under test, and matched a theorem name with \w+. An extraction now states programIndex_get?, whose name that pattern does not match, so a narrowed source kept it while removing programIndex_eq, which its proof cites, and the positive batch of the generic evidence check failed with an unknown identifier. The name pattern now accepts the ?, ! and ' a Lean identifier may carry.
A regex whose pattern is a constant is now a [GeneratedRegex] method. This converts the constant patterns among the inline regexes this branch added, and every constant pattern of the two evidence helpers Tests/GeneratedEvidence.cs and Tests/RejectedEvidence.cs: 31 call sites in ten files (GeneratedEvidence, RejectedEvidence, IncrementalEvidence, LookupScaling, ManagedDispatch, PreparedLeanFixtures, ReferenceAddOutlines, StrictBindingDecoding, SummaryCalls and scripts/TestSelectVerification).

A pattern built at run time stays inline: one interpolated with a method number, a theorem name or a byte literal, one joined with Regex.Escape of a value, and the pattern parameters of ChangeByte, ChangeLiteralByte and TokenCost.

The one-line theorem pattern of the kernel refutation check accepts the ?, ! and ' a Lean name may end in, as the narrowing pattern does. RejectedEvidence keeps its own import pattern because Tests/TranslationAudit.cs includes it without GeneratedEvidence. The inline regexes that predate this branch are unchanged in the other eight files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: proofs Lean proof API, contracts and tactics feature Adds a capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant