Library SetcodeConcrete.vmchecked
Word and byte-size preservation for the new instruction set
From Stdlib Require Import ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Vm.
Require Import QedkConcrete.vmmachinewords QedkConcrete.vmarithmeticwords
QedkConcrete.vmmiscwords QedkConcrete.vmlocalsizes QedkConcrete.vmsizes
QedkConcrete.vmhostwords QedkConcrete.vmhostframe QedkConcrete.vmrun.
Require Import QedkConcrete.vmbytewords QedkConcrete.wordrange MonadExecutionSpecs.Termination.VmDispatchProgress.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Section Instructions.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context (cold warm access write reserve : N).
Context (Hrevision : V.Params.(Vm.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Lemma setcode_clz_words invariant :
machineSafe invariant (fun _ ⇒ True) (dispatch Opcode.Clz).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.clz.
rewrite Hrevision. solve_machine_words.
Qed.
Lemma setcode_clz_sizes : sizesSafe (fun _ ⇒ True) (dispatch Opcode.Clz).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.clz.
rewrite Hrevision. solve_sizes Hrevision.
Qed.
Lemma setcode_opcode_words invariant :
(∀ current source static gas,
preservesCallback invariant (V.Host.(Evmc.HOST.setcodefrom) current source static gas)) →
machineSafe invariant (fun _ ⇒ True) (dispatch Opcode.Setcodefrom).
Proof.
intro Hcallback.
unfold dispatch, V.Executor.execute_opcode, V.Executor.setcodefrom.
rewrite Hrevision.
unfold V.M.HostAPI.setcodefrom, V.M.HostAPI.Base.
eapply safe_bind with (P := fun _ ⇒ True).
{ eapply safe_forget_result, safe_fmap, safe_pop. }
intros source _.
eapply safe_bind with (P := fun _ ⇒ True); [apply safe_read; intros; exact I|].
intros gas _.
eapply safe_bind with (P := fun _ ⇒ True).
- apply safe_host_frame. apply Hcallback.
- intros [[success remaining]|error] _; cbn beta iota zeta.
+ eapply safe_bind with (P := fun _ ⇒ True).
× apply safe_write. intros; assumption.
× intros [] _. eapply safe_bind.
-- apply safe_push. destruct success; [apply word_one|apply word_zero].
-- intros [] _. apply safe_increase_pc.
+ apply safe_fail.
Qed.
Lemma setcode_opcode_sizes : sizesSafe (fun _ ⇒ True) (dispatch Opcode.Setcodefrom).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.setcodefrom.
rewrite Hrevision. unfold V.M.HostAPI.setcodefrom, V.M.HostAPI.Base.
solve_sizes Hrevision.
Qed.
End Instructions.
Print Assumptions setcode_opcode_words.
Print Assumptions setcode_opcode_sizes.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Vm.
Require Import QedkConcrete.vmmachinewords QedkConcrete.vmarithmeticwords
QedkConcrete.vmmiscwords QedkConcrete.vmlocalsizes QedkConcrete.vmsizes
QedkConcrete.vmhostwords QedkConcrete.vmhostframe QedkConcrete.vmrun.
Require Import QedkConcrete.vmbytewords QedkConcrete.wordrange MonadExecutionSpecs.Termination.VmDispatchProgress.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Section Instructions.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context (cold warm access write reserve : N).
Context (Hrevision : V.Params.(Vm.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Lemma setcode_clz_words invariant :
machineSafe invariant (fun _ ⇒ True) (dispatch Opcode.Clz).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.clz.
rewrite Hrevision. solve_machine_words.
Qed.
Lemma setcode_clz_sizes : sizesSafe (fun _ ⇒ True) (dispatch Opcode.Clz).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.clz.
rewrite Hrevision. solve_sizes Hrevision.
Qed.
Lemma setcode_opcode_words invariant :
(∀ current source static gas,
preservesCallback invariant (V.Host.(Evmc.HOST.setcodefrom) current source static gas)) →
machineSafe invariant (fun _ ⇒ True) (dispatch Opcode.Setcodefrom).
Proof.
intro Hcallback.
unfold dispatch, V.Executor.execute_opcode, V.Executor.setcodefrom.
rewrite Hrevision.
unfold V.M.HostAPI.setcodefrom, V.M.HostAPI.Base.
eapply safe_bind with (P := fun _ ⇒ True).
{ eapply safe_forget_result, safe_fmap, safe_pop. }
intros source _.
eapply safe_bind with (P := fun _ ⇒ True); [apply safe_read; intros; exact I|].
intros gas _.
eapply safe_bind with (P := fun _ ⇒ True).
- apply safe_host_frame. apply Hcallback.
- intros [[success remaining]|error] _; cbn beta iota zeta.
+ eapply safe_bind with (P := fun _ ⇒ True).
× apply safe_write. intros; assumption.
× intros [] _. eapply safe_bind.
-- apply safe_push. destruct success; [apply word_one|apply word_zero].
-- intros [] _. apply safe_increase_pc.
+ apply safe_fail.
Qed.
Lemma setcode_opcode_sizes : sizesSafe (fun _ ⇒ True) (dispatch Opcode.Setcodefrom).
Proof.
unfold dispatch, V.Executor.execute_opcode, V.Executor.setcodefrom.
rewrite Hrevision. unfold V.M.HostAPI.setcodefrom, V.M.HostAPI.Base.
solve_sizes Hrevision.
Qed.
End Instructions.
Print Assumptions setcode_opcode_words.
Print Assumptions setcode_opcode_sizes.