Fil-C on Nix

Filnix wiki

the formal campaign

rocq/theories/Getopt.v

Trusted getopt_long boundary. Admission describes memory independently of parsing success: arbitrary NUL-terminated argument contents are allowed. The result relation deliberately abstracts scanning order, abbreviations and diagnostics, not capability provenance. It is a safety contract, not a functional specification of GNU getopt.

The client supplies a projection from its ONE libc world, initialized parser representation, in-progress representation and a frame relation preserving locale and authoritative shutdown/stdout state. Private roots include diagnostic stderr state when needed; they must not include caller-owned storage. Native adequacy and safepoint coverage remain trusted obligations, not new runtime axioms.

From Stdlib Require Import String ZArith List Bool Lia Permutation
From Nanofil Require Import Term Syntax Values Memory Runtime Ops Semantics Identity ExternalCalls Startup ExternalMachine
Import ListNotations
Open Scope Z_scope
Open Scope list_scope

A selected x86-64 option record is 32 bytes: name at 0, has_arg at 8, flag at 16 and val at 24. Padding is not interpreted.

22Record long_option: Type ≔ mkLongOption
option_name
 : ptr
option_text
 : listZ
option_argument
 : Z
option_flag
 : ptr
option_value
 : Z

Logical witnesses for one call family. Argument pointers include their exact capabilities; subsequent calls may permute only the tail. No bound on string contents is imposed beyond C termination.

33Record getopt_input: Type ≔ mkGetoptInput
getopt_argc
 : Z
getopt_argv
 : ptr
getopt_arguments
 : listptr × listZ
getopt_optstring
 : ptr
getopt_short_options
 : listZ
getopt_longopts
 : ptr
getopt_options
 : listlong_option
getopt_longindex
 : ptr

Physical cells are references supplied by startup/linking. The four values alone do NOT establish initialization of glibc's private parser. Reads, writes and release ownership are separate authorities.

47Record getopt_world: Type ≔ mkGetoptWorld
getopt_optarg_cell
 : ptr
getopt_optind_cell
 : ptr
getopt_opterr_cell
 : ptr
getopt_optopt_cell
 : ptr
getopt_errno_cell
 : ptr
getopt_optarg
 : ptr
getopt_optind
 : Z
getopt_opterr
 : Z
getopt_optopt
 : Z
getopt_errno
 : Z
getopt_reads
 : listspan
getopt_roots
 : listspan
getopt_owned
 : listZ

Canonical signed C int, stored/returned as its unsigned W bits.

64Definition getopt_intz : Z : Prop ≔
−2 ^ 31 ≤ z < 2 ^ 31

Writable aligned int cell with an independently specified value.

67Definition getopt_int_cellm p z : Prop ≔
getopt_intz ∧ writable_spanm mkSpanp 4 ∧ access_resm ptr_addrp ptr_capp 4 Read 4 = Someok ∧ access_resm ptr_addrp ptr_capp 4 Write 4 = Someok ∧ load_bytesm ptr_addrp 4 = z mod 2 ^ 32

The selected x86-64 native parser structure is 56 bytes. The fixed parser pointer must identify libc's actual private object, not a caller-chosen phase tag. Its root is delegated by the existing parser inventory; main owns none of these bytes.

77Definition getopt_parser_storageparser : ptr m g : Prop ≔
InmkSpanparser 56 getopt_rootsg ∧ readable_bytesm parser 56 ∧ writable_spanm mkSpanparser 56 ∧ access_resm ptr_addrparser ptr_capparser 56 Read 8 = Someok

First use, not a reset inferred from public optind alone. Native __initialized is the int at offset 24; zero forces initialization of nextchar, ordering and permutation bounds. Startup must identify this storage and establish that no preceding call initialized it. Public optopt need not equal the zero-initialized private copy.

87Definition getopt_parser_freshparser m g : Prop ≔
getopt_parser_storageparser m g ∧ getopt_optindg = 1 ∧ load_bytesm ptr_addrparser + 24 4 = 0

Optional out-int: null is absence, not a writable null span.

92Definition getopt_optional_intm p : Prop ≔
ptr_addrp = 0 ∨ ∃z, getopt_int_cellm p z

Pointer slots, including the exact null sentinel. Each native byte is canonical independently of the aggregate pointer load; consumers can reconstruct exact byte pieces after argv permutation.

98Fixpoint getopt_slotsm a ps : listptr : Prop ≔
match ps with
[ ]
⇒
pointer_slotm a mkPtr0 CNone ∧ ∀k, 0 ≤ k < 8 → 0 ≤ m_bytesm a + k < 256
p :: rest
⇒
pointer_slotm a p ∧ ∀k, 0 ≤ k < 8 → 0 ≤ m_bytesm a + k < 256 ∧ getopt_slotsm a + 8 rest

argv0 is fixed; GNU permutation moves whole tail pointers, never merely their address bits. argc=0 admits just the sentinel.

109Definition getopt_orderbefore after : listptr : Prop ≔
match before, after with
[ ], [ ]
⇒
True
p :: ps, q :: qs
⇒
p = q ∧ Permutationps qs
_, _
⇒
False

Argument strings are borrowed, readable C strings.

117Definition getopt_stringsm input : Prop ≔
Forallλentry ⇒ c_stringm fstentry sndentry getopt_argumentsinput

A writable argv vector and one capability-exact permitted ordering.

121Definition getopt_vectorm input : Prop ≔
writable_spanm mkSpangetopt_argvinput 8 × getopt_argcinput + 1 ∧ access_resm ptr_addrgetopt_argvinput ptr_capgetopt_argvinput 8 × getopt_argcinput + 1 Read 8 = Someok ∧ access_resm ptr_addrgetopt_argvinput ptr_capgetopt_argvinput 8 × getopt_argcinput + 1 Write 8 = Someok ∧ ∃ps, getopt_ordermapfst getopt_argumentsinput ps ∧ getopt_slotsm ptr_addrgetopt_argvinput ps

All records and names are readable; optional flag writes require their own authority. A null name terminates the table.

132Fixpoint getopt_recordsm a options : listlong_option : Prop ≔
match options with
[ ]
⇒
∃p, ptr_addrp = 0 ∧ pointer_slotm a p
o :: rest
⇒
pointer_slotm a option_nameo ∧ ptr_addroption_nameo ≠ 0 ∧ c_stringm option_nameo option_texto ∧ 0 ≤ option_argumento ≤ 2 ∧ load_bytesm a + 8 4 = option_argumento ∧ pointer_slotm a + 16 option_flago ∧ getopt_intoption_valueo ∧ load_bytesm a + 24 4 = option_valueo mod 2 ^ 32 ∧ getopt_optional_intm option_flago ∧ getopt_recordsm a + 32 rest

The five actual argument words, independent of any result.

147Definition getopt_wordsinput : listword ≔

Caller admission includes the entire sentinel-terminated table and every optional writable flag/index, even on an unknown option.

154Definition getopt_input_atm input : Prop ≔
0 ≤ getopt_argcinput < 2 ^ 31 ∧ getopt_argcinput = Z.of_natlengthgetopt_argumentsinput ∧ getopt_vectorm input ∧ getopt_stringsm input ∧ c_stringm getopt_optstringinput getopt_short_optionsinput ∧ access_resm ptr_addrgetopt_longoptsinput ptr_capgetopt_longoptsinput 32 × Z.of_natlengthgetopt_optionsinput + 1 Read 8 = Someok ∧ getopt_recordsm ptr_addrgetopt_longoptsinput getopt_optionsinput ∧ getopt_optional_intm getopt_longindexinput ∧ Z.of_natlengthgetopt_optionsinput < 2 ^ 31

Public exposed state is coherent with memory. A separate rep premise certifies initialized continuation or reset optind=0, including GNU ordering/environment and any interior nextchar borrow.

A pointer borrow into any argv string, including its NUL, retains the original capability. Empty --greeting= is therefore admitted.

177Definition getopt_borrowinput p : Prop ≔
∃q text offset, Inq, text getopt_argumentsinput ∧ 0 ≤ offset ≤ Z.of_natlengthtext ∧ p = mkPtrptr_addrq + offset ptr_capq

Null or an argv borrow, never a fresh owned allocation.

183Definition getopt_optarg_atinput p : Prop ≔
ptr_addrp = 0 ∨ getopt_borrowinput p

Spans protected against all writes, including private/errno roots. Separation is about storage, not restrictions on argument bytes.

188Definition getopt_protectedinput : listspan ≔
mapλentry ⇒ mkSpanfstentry Z.of_natlengthsndentry + 1 getopt_argumentsinput ++ mkSpangetopt_optstringinput Z.of_natlengthgetopt_short_optionsinput + 1; mkSpangetopt_longoptsinput 32 × Z.of_natlengthgetopt_optionsinput + 1 ++ mapλo ⇒ mkSpanoption_nameo Z.of_natlengthoption_texto + 1 getopt_optionsinput

Optional writable output span.

197Definition getopt_optional_spanp : listspan ≔
ptr_addrp =? 0
→
[ ]
else

Exposed writable cells, distinct from private parser roots.

Caller-owned outputs remain separate from parser-private spans.

207Definition getopt_public_writesinput w : listspan ≔

No character-buffer writes are authorized by parsing.

214Definition getopt_writesinput w : listspan ≔

The separate output pieces do not overlap. This intentionally excludes aliased flag/index/state outputs, whose last-write behavior is not specified here; it excludes no Hello argument contents.

220Fixpoint getopt_disjointspans : listspan : Prop ≔
match spans with
[ ]
⇒
True
s :: rest
⇒
∀t a, Int rest → span_containss a → ¬span_containst a ∧ getopt_disjointrest

The argv slots and strings supply borrowed capabilities for optarg and permutation, but do not delegate private ownership.

230Definition getopt_sourcesinput w : listspan ≔

Disjoint protected bytes and write spans. Representation must also keep private release rights exclusive of all caller objects.

235Definition getopt_separatedinput w : Prop ≔
∀source root a, Insource getopt_protectedinput → Inroot getopt_writesinput w → span_containssource a → ¬span_containsroot a ∧ ∀public private a, Inpublic getopt_public_writesinput w → Inprivate getopt_rootsw → span_containspublic a → ¬span_containsprivate a

Private releases name live heap objects and exclude every caller capability-bearing input/output object, not merely its byte span.

245Definition getopt_private_ownedm input w : Prop ≔
∀base, Inbase getopt_ownedw → ∃reg, object_regionbase m_regionsm = Somereg ∧ r_kindreg = Heap ∧ r_lifereg = Live ∧ ∀source, Insource getopt_protectedinput ++ getopt_public_writesinput w → ptr_capspan_ptrsource ≠ Objbase ∧ ptr_capspan_ptrsource ≠ Robase

Normal outcomes preserve protected bytes AND shadow entries.

253Definition getopt_frameinput m m′ : Prop ≔
∀source a, Insource getopt_protectedinput → span_containssource a → m_bytesm′ a = m_bytesm a ∧ m_auxm′ a = m_auxm a

Physical public cell identities never change across a call.

Private projection capabilities come from explicitly enumerated private pointers or new objects, NOT complete pointer slots inside caches, which may contain a caller's optarg/nextchar borrow.

268Definition getopt_private_capw born c : Prop ≔
c = CNone ∨ ∃source, Insource getopt_readsw ++ getopt_rootsw ∧ c = ptr_capspan_ptrsource ∨ ∃base, Inbase born ∧ c = Objbase ∨ c = Robase

Private authority can only descend from old private authority or born objects. In particular storing optarg never makes its argv object a parser root or an owned allocation eligible for release.

277Definition getopt_delegatesw born m′ w′ : Prop ≔
∀root, Inroot getopt_rootsw′ → getopt_private_capw born ptr_capspan_ptrroot ∧ ∀a, span_containsroot a → write_authoritygetopt_rootsw born m′ a ∧ ∀source, Insource getopt_readsw′ → getopt_private_capw born ptr_capspan_ptrsource ∧ ∀base, Inbase getopt_ownedw′ → Inbase getopt_ownedw ++ born

Drop GNU's leading ordering marker, then the error marker.

286Definition getopt_short_bodyoptions : listZ : listZ ≔
let body ≔
match options with
marker :: rest
⇒
marker =? 43 || marker =? 45
→
rest
else
options
[ ]
⇒
[ ]
in
match body with
marker :: rest
⇒
marker =? 58
→
rest
else
body
[ ]
⇒
[ ]

First occurrence of a short option selects its argument mode. Native char is signed on this target; high bytes are sign-extended.

294Fixpoint getopt_short_modeoptions : listZ byte : Z : optionZ ≔
match options with
[ ]
⇒
None
head :: rest
⇒
head =? byte
→
Some
match rest with
58 :: 58 :: _
⇒
2
58 :: _
⇒
1
_
⇒
0
else

Mode zero has no optarg, mode one needs a nonnull argv borrow, and mode two permits either. No ownership is transferred.

307Definition getopt_argument_atinput p mode : Prop ≔
mode =? 0
→
ptr_addrp = 0
else
getopt_optarg_atinput p ∧ mode = 1 → ptr_addrp ≠ 0

Abstract result classification. Long success reports its table index and writes its flag, or returns val when the flag is absent. A required argument always yields a nonnull readable argv borrow. Errors and end-of-options have null optarg. Scanning order is left abstract; this relation promises no termination or exact diagnostics.

316Definition getopt_resultinput m′ w′ code : Prop ≔
code = −1 ∧ ptr_addrgetopt_optargw′ = 0
∨
code = 63 ∨ code = 58 ∧ ptr_addrgetopt_optargw′ = 0
∨
∃ byte mode  ,
0 < byte < 256
∧
byte ≠ 58
∧
byte ≠ 59
∧
code
=
byte <? 128
→
byte
else
byte − 256
∧
∨
∃rest, getopt_short_optionsinput = 45 :: rest ∧ code = 1 ∧ getopt_borrowinput getopt_optargw′ ∧ ptr_addrgetopt_optargw′ ≠ 0
∨
∃ i o  ,
nth_errorgetopt_optionsinput i = Someo
∧

GNU diagnostics are stderr acceptance only; the caller-owned errno cell may change even when no diagnostic is emitted.

334Definition getopt_tracetrace : listevent : Prop ≔
Forallλe ⇒ ∃bytes, e = StreamBytes2 bytes ∧ Forallλb ⇒ 0 ≤ b < 256 bytes trace

Ready admission does not equate reset with arbitrary writable state. Private ownership/liveness and noninterference belong to rep.

340Definition getopt_preW input view : W → getopt_world rep xs m w : Prop ≔
xs = getopt_wordsinput ∧ getopt_input_atm input ∧ repm w ∧ getopt_state_atm vieww ∧ 0 ≤ getopt_optindvieww ≤ getopt_argcinput ∧ Forallwritable_spanm getopt_rootsvieww ∧ Forallλs ⇒ readable_bytesm span_ptrs span_sizes getopt_readsvieww ∧ getopt_separatedinput vieww ∧ getopt_disjointgetopt_public_writesinput vieww ∧ getopt_private_ownedm input vieww

Logical prefix endpoints use an in-progress representation, not completed parser state at arbitrary native cutpoints. Resource ends inherit only this prefix relation, not the normal postcondition.

352Definition getopt_prefixW input view : W → getopt_world inflight : mem → W → Prop stable : W → W → Prop xs : listword m : mem w born trace m′ w′ : Prop ≔
inflightm′ w′ ∧ stablew w′ ∧ getopt_tracetrace ∧ getopt_same_cellsvieww vieww′ ∧ getopt_delegatesvieww born m′ vieww′ ∧ getopt_frameinput m m′

Normal completion restores represented option state and all input borrows for positive argc. The argc=0 early return exports private optarg/optopt, not necessarily their old public values or a borrow into this empty argv. optind is in range; opterr is unchanged. optopt is deliberately not overconstrained on successful paths.

364Definition getopt_postW input view : W → getopt_world rep : mem → W → Prop xs : listword m : mem w : W born : listZ trace : listevent ending m′ w′ : Prop ≔
repm′ w′
∧
getopt_input_atm′ input
∧
getopt_state_atm′ vieww′
∧
∧
∃ code  ,
ending = CallReturnWIntcode mod 2 ^ 32
∧
getopt_argcinput =? 0
→
code = −1 ∧ getopt_optindvieww′ = getopt_optindvieww
else
getopt_optarg_atinput getopt_optargvieww′ ∧ ptr_addrgetopt_optargvieww′ = 0 ∨ ∃bytes, c_stringm′ getopt_optargvieww′ bytes ∧ 0 ≤ getopt_optindvieww′ ≤ getopt_argcinput ∧ getopt_resultinput m′ vieww′ code

Exact W/P/P/P/P arguments and W result, even when discarded.

379Definition getopt_abir args : Prop ≔
r = CVoid ∨ ∃d, r = CResultd W ∧ ∃a b c d e, args = ArgW a; ArgP b; ArgP c; ArgP d; ArgP e

Trusted family over a projection of the existing libc world. The supplied stable relation must preserve effective locale names, text, codec and epoch and the one shutdown/stdout inventory. requests accounts for diagnostic/private allocations; there is no promise of purity, ordinary malloc NULL, or native adequacy.

388Definition getopt_contractWorld input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop : contractWorld ≔
mkContractWorld RClassW getopt_abi getopt_preinput view rep λ_ _ w ⇒ getopt_sourcesinput vieww λ_ _ w ⇒ getopt_writesinput vieww λ_ _ w ⇒ getopt_ownedvieww requests getopt_prefixinput view inflight stable getopt_postinput view rep resource_reason λwhy ⇒ Inwhy NullCapability; OutOfBounds; Misaligned; Readonly; ArgumentSize; ReturnSize

A functional libc binding refines ordinary completions without changing the safety contract's admission, authority or resource prefixes. The transition is an additional trusted claim until a concrete binding establishes its native realization; it is not a consequence of initialized public cells or the base postcondition.

404Definition getopt_refined_contractWorld input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop transition : listword → mem → World → listZ → listevent → listword → mem → World → Prop : contractWorld ≔
let base ≔ getopt_contractinput view rep inflight stable requests in
λ xs m w born trace ending m′ w′  ⇒
contract_postbase xs m w born trace ending m′ w′
∧
match ending with
⇒
transitionxs m w born trace values m′ w′
_
⇒
True

The exact capability of a borrowed optarg is never replaced by a stronger Obj capability having the same address.

423Lemma getopt_borrow_cap
∀ input p
∃q text, Inq, text getopt_argumentsinput ∧ ptr_capp = ptr_capq
Explore proof 3 tactics

Initial goal

⊢
∀input : getopt_input p : ptr, getopt_borrowinput p → ∃q : ptr text : listZ, Inq, text getopt_argumentsinput ∧ ptr_capp = ptr_capq

intros input p q & text & offset & Hin & Hrange & →

q :
text :
listZ
offset :
Z
Hin :
Inq, text getopt_argumentsinput
Hrange :
0 ≤ offset ≤ Z.of_natDatatypes.lengthtext
⊢
∃q0 : ptr text0 : listZ, Inq0, text0 getopt_argumentsinput ∧ ptr_capptr_addr ≔ ptr_addrq + offset; ptr_cap ≔ ptr_capq = ptr_capq0

exists q, text

q :
text :
listZ
offset :
Z
Hin :
Inq, text getopt_argumentsinput
Hrange :
0 ≤ offset ≤ Z.of_natDatatypes.lengthtext
⊢
Inq, text getopt_argumentsinput ∧ ptr_capptr_addr ≔ ptr_addrq + offset; ptr_cap ≔ ptr_capq = ptr_capq

auto

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros input p q & text & offset & Hin & Hrange & →
exists q, text
auto

Permutation preserves argv's full pointer inventory.

432Lemma getopt_order_inventory
∀ before after
getopt_orderbefore after
Permutationbefore after
Explore proof 5 tactics

Initial goal

⊢
∀before after : listptr, getopt_orderbefore after → Permutationbefore after

intros | p ps | q qs H ; simpl in H ; try contradiction

2 open

H :
True
⊢
Permutation[ ] [ ]
focused goal
p :
ps :
listptr
q :
qs :
listptr
H :
p = q ∧ Permutationps qs
⊢
Permutationp :: ps q :: qs

–apply Permutation_refl

deferred goal
p :
ps :
listptr
q :
qs :
listptr
H :
p = q ∧ Permutationps qs
⊢
Permutationp :: ps q :: qs

–destruct H as → H

ps :
listptr
q :
qs :
listptr
H :
Permutationps qs
⊢
Permutationq :: ps q :: qs

apply perm_skip

ps :
listptr
q :
qs :
listptr
H :
Permutationps qs
⊢
Permutationps qs

exact H

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros | p ps | q qs H ; simpl in H ; try contradiction
–apply Permutation_refl
–destruct H as → H
apply perm_skip
exact H

Every option result is a normal W return, never an exit request.

441Lemma getopt_post_return
∀ W input view rep xs m w born trace ending m′ w′
@getopt_postW input view rep xs m w born trace ending m′ w′
∃code, ending = CallReturnWIntcode mod 2 ^ 32
Explore proof 2 tactics

Initial goal

⊢
∀W : Type input : getopt_input view : W → getopt_world rep : mem → W → Prop xs : listword m : mem w : W born : listZ trace : listevent ending : call_end m′ : mem w′ : W, getopt_postinput view rep xs m w born trace ending m′ w′ → ∃code : Z, ending = CallReturnWIntcode mod 2 ^ 32

intros W input view rep xs m w born trace ending m′ w′ _ & _ & _ & _ & code & H & _

W :
Type
view :
rep :
mem → W → Prop
xs :
listword
m :
w :
W
born :
listZ
trace :
listevent
ending :
m′ :
w′ :
W
code :
Z
H :
ending = CallReturnWIntcode mod 2 ^ 32
⊢
∃code0 : Z, ending = CallReturnWIntcode0 mod 2 ^ 32

eauto

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros W input view rep xs m w born trace ending m′ w′ _ & _ & _ & _ & code & H & _
eauto

Required arguments cannot be a null optarg, even for empty strings.

450Lemma getopt_required_argument
∀ input p
getopt_borrowinput p ∧ ptr_addrp ≠ 0
Explore proof 3 tactics

Initial goal

⊢
∀input : getopt_input p : ptr, getopt_argument_atinput p 1 → getopt_borrowinput p ∧ ptr_addrp ≠ 0

intros input p Harg Hnonnull

p :
Harg :
Hnonnull :
1 = 1 → ptr_addrp ≠ 0
⊢
getopt_borrowinput p ∧ ptr_addrp ≠ 0

specialize Hnonnulleq_refl

p :
Harg :
Hnonnull :
ptr_addrp ≠ 0
⊢
getopt_borrowinput p ∧ ptr_addrp ≠ 0

split ; destruct Harg ; contradiction | assumption | assumption

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros input p Harg Hnonnull
specialize Hnonnulleq_refl
split ; destruct Harg ; contradiction | assumption | assumption

The post exposes exactly the ordinary pointer-load protocol main uses: address bytes together with the original capability in aux.

459Lemma getopt_post_optarg_load
∀ World input view rep xs m w born trace ending m′ w′
@getopt_postWorld input view rep xs m w born trace ending m′ w′
Explore proof 3 tactics

Initial goal

⊢
∀World : Type input : getopt_input view : World → getopt_world rep : mem → World → Prop xs : listword m : mem w : World born : listZ trace : listevent ending : call_end m′ : mem w′ : World, getopt_postinput view rep xs m w born trace ending m′ w′ → pointer_load_effectsm′ ptr_addrgetopt_optarg_cellvieww′ AuxRead; LowerResolve; AddressRead = Somegetopt_optargvieww′

intros World input view rep xs m w born trace ending m′ w′ _ & _ & Hcell _ & _

World :
Type
view :
World → getopt_world
rep :
mem → World → Prop
xs :
listword
m :
w :
World
born :
listZ
trace :
listevent
ending :
m′ :
w′ :
World

apply exposed_pointer_load

World :
Type
view :
World → getopt_world
rep :
mem → World → Prop
xs :
listword
m :
w :
World
born :
listZ
trace :
listevent
ending :
m′ :
w′ :
World

exact Hcell

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros World input view rep xs m w born trace ending m′ w′ _ & _ & Hcell _ & _
exact Hcell

Refinement lemmas over the consumer's supplied machine, so the projection never transports an invocation between sibling functors.

470Module GetoptRefinementOn R : Runtime M : ExternalMachineSigR
471Module E ≔ M.E

Every refined invocation is a base invocation with the same effects, allocation witnesses, trace, runtime and memory/world endpoints.

475Theorem refined_invoke_base
∀ World input view rep inflight stable requests transition r args xs s m w : World trace ending s′ m′ w′
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace ending s′ m′ w′
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′
Explore proof 5 tactics

Initial goal

⊢
∀World : Type input : getopt_input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop transition : listword → mem → World → listZ → listevent → listword → mem → World → Prop r : call_result args : listarg xs : listword s : R.state m : mem w : World trace : listevent ending : call_end s′ : R.state m′ : mem w′ : World, E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace ending s′ m′ w′ → E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′

intros World input view rep inflight stable requests transition r args xs s m w trace ending s′ m′ w′ Hcall

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace ending s′ m′ w′
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′

destruct Hcall as trace ending s′ m′ w′ born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why trace s′ m′ w′ born Habi Hpre Hp Hfailure Hresource

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_refined_contractinput view rep inflight stable requests transition xs m w born trace ending m′ w′
Hnr :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_refined_contractinput view rep inflight stable requests transition values ∧ Forallword_authoritycontract_sourcesgetopt_refined_contractinput view rep inflight stable requests transition xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′
focused goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_refined_contractinput view rep inflight stable requests transition xs m w s′ why
Hresource :
contract_resourcegetopt_refined_contractinput view rep inflight stable requests transition why
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′

–eapply E.invoke_normal with born := born ; try eassumption

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_refined_contractinput view rep inflight stable requests transition xs m w born trace ending m′ w′
Hnr :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_refined_contractinput view rep inflight stable requests transition values ∧ Forallword_authoritycontract_sourcesgetopt_refined_contractinput view rep inflight stable requests transition xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_refined_contractinput view rep inflight stable requests transition xs m w s′ why
Hresource :
contract_resourcegetopt_refined_contractinput view rep inflight stable requests transition why
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′

exact proj1Hpost

deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_refined_contractinput view rep inflight stable requests transition xs m w s′ why
Hresource :
contract_resourcegetopt_refined_contractinput view rep inflight stable requests transition why
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′

–eapply E.invoke_resource with born := born ; eassumption

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros World input view rep inflight stable requests transition r args xs s m w trace ending s′ m′ w′ Hcall
destruct Hcall as trace ending s′ m′ w′ born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why trace s′ m′ w′ born Habi Hpre Hp Hfailure Hresource
–eapply E.invoke_normal with born := born ; try eassumption
exact proj1Hpost
–eapply E.invoke_resource with born := born ; eassumption

Only an ordinary refined return supplies the additional transition; resource prefixes do not imply a completed parser state.

493Theorem refined_return
∀ World input view rep inflight stable requests transition r args xs s m w : World trace values s′ m′ w′
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′
∃born, transitionxs m w born trace values m′ w′
Explore proof 4 tactics

Initial goal

⊢
∀World : Type input : getopt_input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop transition : listword → mem → World → listZ → listevent → listword → mem → World → Prop r : call_result args : listarg xs : listword s : R.state m : mem w : World trace : listevent values : listword s′ : R.state m′ : mem w′ : World, E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′ → ∃born : listZ, transitionxs m w born trace values m′ w′

intros World input view rep inflight stable requests transition r args xs s m w trace values s′ m′ w′ Hcall

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
values :
listword
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′
⊢
∃born : listZ, transitionxs m w born trace values m′ w′

inversion Hcall as tr ending sr mr wr born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why tr sr mr wr born Habi Hpre Hp Hfailure Hresource ; subst

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
values :
listword
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_refined_contractinput view rep inflight stable requests transition xs m w born trace CallReturnvalues m′ w′
Hnr :
∀why : reason, CallReturnvalues ≠ CallResourcewhy
Hvalues :
∀values0 : listword, CallReturnvalues = CallReturnvalues0 → return_shapecontract_returnsgetopt_refined_contractinput view rep inflight stable requests transition values0 ∧ Forallword_authoritycontract_sourcesgetopt_refined_contractinput view rep inflight stable requests transition xs m w born m′ values0
Hexit :
∀status : Z, CallReturnvalues = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
∃born0 : listZ, transitionxs m w born0 trace values m′ w′

eexists

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
values :
listword
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_refined_contractinput view rep inflight stable requests transition xs m w born trace CallReturnvalues m′ w′
Hnr :
∀why : reason, CallReturnvalues ≠ CallResourcewhy
Hvalues :
∀values0 : listword, CallReturnvalues = CallReturnvalues0 → return_shapecontract_returnsgetopt_refined_contractinput view rep inflight stable requests transition values0 ∧ Forallword_authoritycontract_sourcesgetopt_refined_contractinput view rep inflight stable requests transition xs m w born m′ values0
Hexit :
∀status : Z, CallReturnvalues = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
transitionxs m w ?born trace values m′ w′
shelved goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
values :
listword
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallReturnvalues s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_refined_contractinput view rep inflight stable requests transition r args
Hpre :
contract_pregetopt_refined_contractinput view rep inflight stable requests transition xs m w
Hp :
E.prefixgetopt_refined_contractinput view rep inflight stable requests transition xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_refined_contractinput view rep inflight stable requests transition xs m w born trace CallReturnvalues m′ w′
Hnr :
∀why : reason, CallReturnvalues ≠ CallResourcewhy
Hvalues :
∀values0 : listword, CallReturnvalues = CallReturnvalues0 → return_shapecontract_returnsgetopt_refined_contractinput view rep inflight stable requests transition values0 ∧ Forallword_authoritycontract_sourcesgetopt_refined_contractinput view rep inflight stable requests transition xs m w born m′ values0
Hexit :
∀status : Z, CallReturnvalues = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
listZ

exact proj2Hpost

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros World input view rep inflight stable requests transition r args xs s m w trace values s′ m′ w′ Hcall
inversion Hcall as tr ending sr mr wr born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why tr sr mr wr born Habi Hpre Hp Hfailure Hresource ; subst
eexists
exact proj2Hpost

Refining ordinary posts preserves resource invocations in both directions, even when the selected transition is unsatisfiable.

509Theorem refined_resource_iff
∀ World input view rep inflight stable requests transition r args xs s m w : World trace why s′ m′ w′
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′ ↔ E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
Explore proof 8 tactics

Initial goal

⊢
∀World : Type input : getopt_input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop transition : listword → mem → World → listZ → listevent → listword → mem → World → Prop r : call_result args : listarg xs : listword s : R.state m : mem w : World trace : listevent why : reason s′ : R.state m′ : mem w′ : World, E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′ ↔ E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′

intros World input view rep inflight stable requests transition r args xs s m w trace why s′ m′ w′

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′ ↔ E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′

split

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′ → E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
focused goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′ → E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

–apply refined_invoke_base

deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
⊢
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′ → E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

–intros Hcall

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

inversion Hcall as tr ending sr mr wr born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why′ tr sr mr wr born Habi Hpre Hp Hfailure Hresource ; subst

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
Hp :
E.prefixgetopt_contractinput view rep inflight stable requests xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace CallResourcewhy m′ w′
Hnr :
∀why0 : reason, CallResourcewhy ≠ CallResourcewhy0
Hvalues :
∀values : listword, CallResourcewhy = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, CallResourcewhy = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′
focused goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
Hp :
E.prefixgetopt_contractinput view rep inflight stable requests xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

+exfalso

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
Hp :
E.prefixgetopt_contractinput view rep inflight stable requests xs s m w born trace s′ m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace CallResourcewhy m′ w′
Hnr :
∀why0 : reason, CallResourcewhy ≠ CallResourcewhy0
Hvalues :
∀values : listword, CallResourcewhy = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, CallResourcewhy = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
False
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
Hp :
E.prefixgetopt_contractinput view rep inflight stable requests xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

exact Hnrwhy eq_refl

deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
transition :
listword → mem → World → listZ → listevent → listword → mem → World → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
why :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace CallResourcewhy s′ m′ w′
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
Hp :
E.prefixgetopt_contractinput view rep inflight stable requests xs s m w born trace s′ m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
E.invokegetopt_refined_contractinput view rep inflight stable requests transition r args xs s m w trace CallResourcewhy s′ m′ w′

+eapply E.invoke_resource with born := born ; eassumption

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros World input view rep inflight stable requests transition r args xs s m w trace why s′ m′ w′
split
–intros Hcall
inversion Hcall as tr ending sr mr wr born Habi Hpre Hp Hpost Hnr Hvalues Hexit | why′ tr sr mr wr born Habi Hpre Hp Hfailure Hresource ; subst
+exfalso
exact Hnrwhy eq_refl
+eapply E.invoke_resource with born := born ; eassumption

Runtime-facing lemmas for this machine instance. Sibling functor applications are generative; using these inside Logic requires the separately reviewed exact-instance integration, not an alias claim.

531Module Getopt R : Runtime
532Module M ≔ ExternalMachine R
533Module E ≔ M.E

Both normal and resource endpoints expose the actual finite effect path and stable composite world. Only normal endpoints restore the postcondition; a failed allocation does not imply parser completion.

538Theorem getopt_invocation
∀ World input view rep inflight stable requests r args xs s m w : World trace ending s′ m′ w′
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′
getopt_preinput view rep xs m w ∧ ∃born, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born ∧ getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
Explore proof 14 tactics

Initial goal

⊢
∀World : Type input : getopt_input view : World → getopt_world rep inflight : mem → World → Prop stable : World → World → Prop requests : listword → mem → World → Z → Z → Prop r : call_result args : listarg xs : listword s : R.state m : mem w : World trace : listevent ending : call_end s′ : R.state m′ : mem w′ : World, E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′ → getopt_preinput view rep xs m w ∧ ∃born : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born ∧ getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy

intros World input view rep inflight stable requests r args xs s m w trace ending s′ m′ w′ Hcall

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
Hcall :
E.invokegetopt_contractinput view rep inflight stable requests r args xs s m w trace ending s′ m′ w′
⊢
getopt_preinput view rep xs m w ∧ ∃born : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born ∧ getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy

destruct Hcall as trace ending s′ m′ w′ born Habi Hpre He Hp Hpost Hresource Hvalues Hexit | why trace s′ m′ w′ born Habi Hpre He Hp Hfailure Hresource

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
Hresource :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
focused goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

–split ; exact Hpre |

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
Hresource :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

exists born

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
Hresource :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born ∧ getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

split ; exact He |

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
Hresource :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

split ; exact Hp |

2 open

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
trace :
listevent
ending :
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hpost :
contract_postgetopt_contractinput view rep inflight stable requests xs m w born trace ending m′ w′
Hresource :
∀why : reason, ending ≠ CallResourcewhy
Hvalues :
∀values : listword, ending = CallReturnvalues → return_shapecontract_returnsgetopt_contractinput view rep inflight stable requests values ∧ Forallword_authoritycontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w born m′ values
Hexit :
∀status : Z, ending = CallExitstatus → ∃before : listevent, trace = before ++ ProcessExitstatus
⊢
getopt_postinput view rep xs m w born trace ending m′ w′ ∨ ∃why : reason, ending = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy
deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

auto

deferred goal
World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_preinput view rep xs m w ∧ ∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

–split ; exact Hpre |

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
∃born0 : listZ, E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born0 ∧ getopt_prefixinput view inflight stable xs m w born0 trace m′ w′ ∧ getopt_postinput view rep xs m w born0 trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

exists born

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
E.effectsgetopt_sourcesinput vieww getopt_writesinput vieww getopt_ownedvieww requestsxs m w s m [ ] s′ m′ born ∧ getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

split ; exact He |

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_prefixinput view inflight stable xs m w born trace m′ w′ ∧ getopt_postinput view rep xs m w born trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

split ; exact Hp |

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
getopt_postinput view rep xs m w born trace CallResourcewhy m′ w′ ∨ ∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

right

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
∃why0 : reason, CallResourcewhy = CallResourcewhy0 ∧ E.resource_failurerequestsxs m w s′ why0 ∧ resource_reasonwhy0

exists why

World :
Type
view :
World → getopt_world
rep, inflight :
mem → World → Prop
stable :
World → World → Prop
requests :
listword → mem → World → Z → Z → Prop
args :
listarg
xs :
listword
s :
R.state
m :
w :
World
why :
trace :
listevent
s′ :
R.state
m′ :
w′ :
World
born :
listZ
Habi :
contract_abigetopt_contractinput view rep inflight stable requests r args
Hpre :
contract_pregetopt_contractinput view rep inflight stable requests xs m w
He :
E.effectscontract_sourcesgetopt_contractinput view rep inflight stable requests xs m w contract_writesgetopt_contractinput view rep inflight stable requests xs m w contract_releasesgetopt_contractinput view rep inflight stable requests xs m w contract_requestsgetopt_contractinput view rep inflight stable requests xs m w s m [ ] s′ m′ born
Hp :
contract_prefixgetopt_contractinput view rep inflight stable requests xs m w born trace m′ w′
Hfailure :
E.resource_failurecontract_requestsgetopt_contractinput view rep inflight stable requests xs m w s′ why
Hresource :
contract_resourcegetopt_contractinput view rep inflight stable requests why
⊢
CallResourcewhy = CallResourcewhy ∧ E.resource_failurerequestsxs m w s′ why ∧ resource_reasonwhy

auto

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros World input view rep inflight stable requests r args xs s m w trace ending s′ m′ w′ Hcall
destruct Hcall as trace ending s′ m′ w′ born Habi Hpre He Hp Hpost Hresource Hvalues Hexit | why trace s′ m′ w′ born Habi Hpre He Hp Hfailure Hresource
–split ; exact Hpre |
exists born
split ; exact He |
split ; exact Hp |
auto
–split ; exact Hpre |
exists born
split ; exact He |
split ; exact Hp |
right
exists why
auto

Slot controls separate canonical bytes from their aggregate load. The noncanonical null encoding cancels 256 against -1 * 256.

562Module GetoptSlotChecks

Canonical zero bytes admit both an argv entry and its sentinel.

565Example canonical_slots: getopt_slotsmkMemλ_ ⇒ 0 [ ] λ_ ⇒ CNone 0 mkPtr0 CNone
Explore proof 2 tactics

Initial goal

⊢
getopt_slotsm_bytes ≔ λ_ : Z ⇒ 0; m_regions ≔ [ ]; m_aux ≔ λ_ : Z ⇒ CNone 0 ptr_addr ≔ 0; ptr_cap ≔ CNone

cbn [ getopt_slots ]

⊢
pointer_slotm_bytes ≔ λ_ : Z ⇒ 0; m_regions ≔ [ ]; m_aux ≔ λ_ : Z ⇒ CNone 0 ptr_addr ≔ 0; ptr_cap ≔ CNone ∧ ∀k : Z, 0 ≤ k < 8 → 0 ≤ m_bytesm_bytes ≔ λ_ : Z ⇒ 0; m_regions ≔ [ ]; m_aux ≔ λ_ : Z ⇒ CNone 0 + k < 256 ∧ pointer_slotm_bytes ≔ λ_ : Z ⇒ 0; m_regions ≔ [ ]; m_aux ≔ λ_ : Z ⇒ CNone 0 + 8 ptr_addr ≔ 0; ptr_cap ≔ CNone ∧ ∀k : Z, 0 ≤ k < 8 → 0 ≤ m_bytesm_bytes ≔ λ_ : Z ⇒ 0; m_regions ≔ [ ]; m_aux ≔ λ_ : Z ⇒ CNone 0 + 8 + k < 256

repeat split ; try reflexivity ; try lia ; intros k Hk ; change 0 ≤ 0 < 256 ; lia

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
cbn [ getopt_slots ]
repeat split ; try reflexivity ; try lia ; intros k Hk ; change 0 ≤ 0 < 256 ; lia

These integers decode to zero but are not native memory bytes.

573Definition noncanonical: mem ≔
λ a  ⇒
a =? 0
→
256
a =? 1
→
−1
else
0
[ ]
λ_ ⇒ CNone

Merely specifying the loaded pointer does not exclude this memory.

578Example noncanonical_pointer: pointer_slotnoncanonical 0 mkPtr0 CNone
Explore proof 2 tactics

Initial goal

vm_compute

⊢
Datatypes.Eq = Datatypes.Gt → False ∧ Datatypes.Lt = Datatypes.Lt ∧ 0 = 0 ∧ CNone = CNone

repeat split ; congruence

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
vm_compute
repeat split ; congruence

Bounds apply to the final null slot too, not only nonnull entries.

582Example noncanonical_sentinel_rejected: ¬getopt_slotsnoncanonical 0 [ ]
Explore proof 4 tactics

Initial goal

intros _ Hbytes

Hbytes :
∀k : Z, 0 ≤ k < 8 → 0 ≤ m_bytesnoncanonical 0 + k < 256
⊢
False

specialize Hbytes0 ltac:lia

Hbytes :
0 ≤ m_bytesnoncanonical 0 + 0 < 256
⊢
False

change 0 ≤ 256 < 256 in Hbytes

Hbytes :
0 ≤ 256 < 256
⊢
False

lia

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros _ Hbytes
specialize Hbytes0 ltac:lia
change 0 ≤ 256 < 256 in Hbytes
lia