Library QedkConcrete.vmhostframe
VM instructions that use nonrecursive Host operations
From Stdlib Require Import List ZArith.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vminvariant QedkConcrete.vmrun QedkConcrete.vmopcodeframe.
Require Import QedkConcrete.bytewords.
Require Import MonadExecutionSpecs.Termination.VmDispatchProgress
MonadExecutionSpecs.Termination.VmUnsignedGas.
Set Default Goal Selector "!".
Definition preservesCallback {Host_t A : Set} (invariant : Host_t → Prop)
(action : Host_t → A × Host_t) :=
∀ host, invariant host → invariant (snd (action host)).
Record PrimitiveHostFrame {Host_t : Set} (host : Evmc.HOST (t := Host_t))
(invariant : Host_t → Prop) : Prop := {
frame_account_exists : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.account_exists) a);
frame_get_balance : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_balance) a);
frame_access_account : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.access_account) a);
frame_get_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_storage) a k);
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vminvariant QedkConcrete.vmrun QedkConcrete.vmopcodeframe.
Require Import QedkConcrete.bytewords.
Require Import MonadExecutionSpecs.Termination.VmDispatchProgress
MonadExecutionSpecs.Termination.VmUnsignedGas.
Set Default Goal Selector "!".
Definition preservesCallback {Host_t A : Set} (invariant : Host_t → Prop)
(action : Host_t → A × Host_t) :=
∀ host, invariant host → invariant (snd (action host)).
Record PrimitiveHostFrame {Host_t : Set} (host : Evmc.HOST (t := Host_t))
(invariant : Host_t → Prop) : Prop := {
frame_account_exists : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.account_exists) a);
frame_get_balance : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_balance) a);
frame_access_account : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.access_account) a);
frame_get_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_storage) a k);
VM writes encode their values as 32-byte words, even before the full
stack-word invariant is established. Arbitrary strings are not inputs
to these callbacks from SSTORE or TSTORE.
frame_set_storage : ∀ a k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_storage) a k v);
frame_access_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.access_storage) a k);
frame_get_transient_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_transient_storage) a k);
frame_set_transient_storage : ∀ a k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_transient_storage) a k v);
frame_get_code_size : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_size) a);
frame_get_code_hash : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_hash) a);
frame_copy_code : ∀ a offset size,
preservesCallback invariant (host.(Evmc.HOST.copy_code) a offset size);
frame_get_block_hash : ∀ n,
preservesCallback invariant (host.(Evmc.HOST.get_block_hash) n);
frame_emit_log : ∀ a data topics,
preservesCallback invariant (host.(Evmc.HOST.emit_log) a data topics);
frame_selfdestruct : ∀ a b,
preservesCallback invariant (host.(Evmc.HOST.selfdestruct) a b)
}.
preservesCallback invariant (host.(Evmc.HOST.set_storage) a k v);
frame_access_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.access_storage) a k);
frame_get_transient_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_transient_storage) a k);
frame_set_transient_storage : ∀ a k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_transient_storage) a k v);
frame_get_code_size : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_size) a);
frame_get_code_hash : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_hash) a);
frame_copy_code : ∀ a offset size,
preservesCallback invariant (host.(Evmc.HOST.copy_code) a offset size);
frame_get_block_hash : ∀ n,
preservesCallback invariant (host.(Evmc.HOST.get_block_hash) n);
frame_emit_log : ∀ a data topics,
preservesCallback invariant (host.(Evmc.HOST.emit_log) a data topics);
frame_selfdestruct : ∀ a b,
preservesCallback invariant (host.(Evmc.HOST.selfdestruct) a b)
}.
Writes and SELFDESTRUCT name the current execution account, unlike
reads that may inspect any address. The weaker premises are needed to
prove that an unrelated undelegated account cannot be debited.
Record PrimitiveHostFrameAt {Host_t : Set} (host : Evmc.HOST (t := Host_t))
(invariant : Host_t → Prop) (self : Chain.Ethereum.Address.t) : Prop := {
frame_at_account_exists : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.account_exists) a);
frame_at_get_balance : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_balance) a);
frame_at_access_account : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.access_account) a);
frame_at_get_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_storage) a k);
(invariant : Host_t → Prop) (self : Chain.Ethereum.Address.t) : Prop := {
frame_at_account_exists : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.account_exists) a);
frame_at_get_balance : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_balance) a);
frame_at_access_account : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.access_account) a);
frame_at_get_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_storage) a k);
VM writes encode their values as 32-byte words, even before the full
stack-word invariant is established. Arbitrary strings are not inputs
to these callbacks from SSTORE or TSTORE.
frame_at_set_storage : ∀ k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_storage) self k v);
frame_at_access_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.access_storage) a k);
frame_at_get_transient_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_transient_storage) a k);
frame_at_set_transient_storage : ∀ k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_transient_storage) self k v);
frame_at_get_code_size : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_size) a);
frame_at_get_code_hash : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_hash) a);
frame_at_copy_code : ∀ a offset size,
preservesCallback invariant (host.(Evmc.HOST.copy_code) a offset size);
frame_at_get_block_hash : ∀ n,
preservesCallback invariant (host.(Evmc.HOST.get_block_hash) n);
frame_at_emit_log : ∀ data topics,
preservesCallback invariant (host.(Evmc.HOST.emit_log) self data topics);
frame_at_selfdestruct : ∀ b,
preservesCallback invariant (host.(Evmc.HOST.selfdestruct) self b)
}.
Lemma primitive_frame_at {Host_t : Set} (host : Evmc.HOST (t := Host_t)) invariant self :
PrimitiveHostFrame host invariant → PrimitiveHostFrameAt host invariant self.
Proof. intro H; destruct H; constructor; intros; eauto. Qed.
Definition primitiveHostOpcode (opcode : Opcode.t) : bool :=
match opcode with
| Opcode.Balance | Opcode.Extcodesize | Opcode.Extcodecopy | Opcode.Extcodehash
| Opcode.Blockhash | Opcode.Selfbalance | Opcode.Sload | Opcode.Sstore
| Opcode.Tload | Opcode.Tstore | Opcode.Log _ | Opcode.Selfdestruct ⇒ true
| _ ⇒ false
end.
Definition recursiveCallOpcode (opcode : Opcode.t) : bool :=
match opcode with
| Opcode.Create | Opcode.Call | Opcode.Callcode | Opcode.Delegatecall
| Opcode.Create2 | Opcode.Staticcall ⇒ true
| _ ⇒ false
end.
Ltac solve_host_invariant_extra ::=
lazymatch goal with
| |- preservesHost _ (@V.M.Seq.mapM _ _ _ _ _ _) ⇒
apply preserves_seq_map; intro; solve_host_invariant
| |- preservesHost _ (@V.M.HostAPI.lift _ _ _ _) ⇒
apply preserves_lift; unfold preservesCallback in *; eauto using word_encoding_length
| |- preservesHost _ (match ?value with _ ⇒ _ end) ⇒
destruct value; solve_host_invariant
| |- ?g ⇒ fail "Unhandled Host frame goal:" g
end.
Section Opcodes.
Context {Host_t : Set} {F : @MonadVM.Vm.Make.FArgs Host_t}.
Context `{U0 : RocqOfOCaml.Basics.Unreachable Z.t}.
Context `{U1 :
RocqOfOCaml.Basics.Unreachable (RocqOfOCaml.OCamlSeq.t int)}.
Context `{U2 : RocqOfOCaml.Basics.Unreachable RocqOfOCaml.OCamlInt32.t}.
Context `{U3 : RocqOfOCaml.Basics.Unreachable MonadVM.Uint64.t}.
Context `{U4 :
RocqOfOCaml.Basics.Unreachable MonadVM.Support.UintN.t}.
Context `{U5 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.U256.Repr.t}.
Context `{U7 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.Integer.t}.
Context `{U8 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.I256.t}.
Context `{U9 : RocqOfOCaml.Basics.Unreachable MonadVM.Gas.t}.
Context `{U10 :
RocqOfOCaml.Basics.Unreachable MonadVM.Delegation.Address.t}.
Context `{U11 :
RocqOfOCaml.Basics.Unreachable MonadVM.Chain.Ethereum.Address.t}.
Context `{U12 :
RocqOfOCaml.Basics.Unreachable MonadVM.Byte_string.Bytes.t}.
Context `{U13 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.M.Option.t Host_t F MonadVM.Numeric.U256.t)}.
Context `{U15 : RocqOfOCaml.Basics.Unreachable unit}.
Context `{U16 : RocqOfOCaml.Basics.Unreachable string}.
Context `{U17 :
RocqOfOCaml.Basics.Unreachable (option MonadVM.Numeric.U256.t)}.
Context `{U18 : RocqOfOCaml.Basics.Unreachable (option string)}.
Context `{U19 :
RocqOfOCaml.Basics.Unreachable
(list MonadVM.Byte_string.Bytes.t)}.
Context `{U20 : RocqOfOCaml.Basics.Unreachable (list int)}.
Context `{U21 : RocqOfOCaml.Basics.Unreachable int}.
Context `{U22 : RocqOfOCaml.Basics.Unreachable ascii}.
Context `{U23 : RocqOfOCaml.Basics.Unreachable (int × int)}.
Context `{U24 :
RocqOfOCaml.Basics.Unreachable
(Z.t → MonadVM.Numeric.U256.t)}.
Context `{U25 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Support.UintN.t → MonadVM.Support.UintN.t)}.
Context `{U26 :
RocqOfOCaml.Basics.Unreachable
(unit → RocqOfOCaml.OCamlSeq.node int)}.
Context `{U27 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.opcode_impl Host_t F)}.
Context `{U28 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Numeric.IntegerBase.(MonadVM.Numeric.Make.Make_result.t)}.
Context `{U31 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.t)}.
Context `{U32 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Numeric.U256.t → MonadVM.Numeric.U256.t →
@MonadVM.Vm.Make.Memory.t Host_t F →
@MonadVM.Vm.Make.M.Option.t Host_t F
(@MonadVM.Vm.Make.Memory.t Host_t F))}.
Context `{U33 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.Memory.t Host_t F →
MonadVM.Support.UintN.t)}.
Let State := @MonadVM.Vm.Make.MachineState.t Host_t F.
Section Environment.
Context {E : @V.Executor.FArgs Host_t F}.
Local Abbreviation executeOpcode := (@dispatch Host_t F E).
Lemma primitive_host_preserves_at (invariant : Host_t → Prop) opcode :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
primitiveHostOpcode opcode = true → preservesHost invariant (executeOpcode opcode).
Proof.
intros Hrevision Hdebug Hhost Hprimitive. destruct Hhost.
destruct opcode; cbn [primitiveHostOpcode] in Hprimitive; try discriminate.
all: cbn [dispatch V.Executor.execute_opcode].
all: unfold V.Executor.balance, V.Executor.extcodesize, V.Executor.extcodecopy,
V.Executor.extcodehash, V.Executor.blockhash, V.Executor.selfbalance,
V.Executor.sload, V.Executor.sstore, V.Executor.tload, V.Executor.tstore,
V.Executor.log, V.Executor.selfdestruct.
all: unfold V.Executor.debug_tstore_stack, V.Executor.extend_memory_to,
V.Executor.check_write_permissions, V.Executor.self.
all: try rewrite Hrevision; try rewrite Hdebug.
all: unfold V.M.HostAPI.get_balance, V.M.HostAPI.access_account,
V.M.HostAPI.get_code_size, V.M.HostAPI.copy_code, V.M.HostAPI.get_code_hash,
V.M.HostAPI.get_block_hash, V.M.HostAPI.access_storage, V.M.HostAPI.get_storage,
V.M.HostAPI.set_storage, V.M.HostAPI.get_transient_storage,
V.M.HostAPI.set_transient_storage, V.M.HostAPI.account_exists,
V.M.HostAPI.emit_log, V.M.HostAPI.selfdestruct, V.M.HostAPI.Base.
all: cbn beta iota zeta; cbn [negb].
all: solve_host_invariant.
Qed.
Lemma primitive_host_preserves (invariant : Host_t → Prop) opcode :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
primitiveHostOpcode opcode = true → preservesHost invariant (executeOpcode opcode).
Proof.
intros Hrevision Hdebug Hhost Hprimitive.
apply primitive_host_preserves_at; try assumption.
apply primitive_frame_at. exact Hhost.
Qed.
preservesCallback invariant (host.(Evmc.HOST.set_storage) self k v);
frame_at_access_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.access_storage) a k);
frame_at_get_transient_storage : ∀ a k,
preservesCallback invariant (host.(Evmc.HOST.get_transient_storage) a k);
frame_at_set_transient_storage : ∀ k v, OCamlString.length v = 32%Z →
preservesCallback invariant (host.(Evmc.HOST.set_transient_storage) self k v);
frame_at_get_code_size : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_size) a);
frame_at_get_code_hash : ∀ a,
preservesCallback invariant (host.(Evmc.HOST.get_code_hash) a);
frame_at_copy_code : ∀ a offset size,
preservesCallback invariant (host.(Evmc.HOST.copy_code) a offset size);
frame_at_get_block_hash : ∀ n,
preservesCallback invariant (host.(Evmc.HOST.get_block_hash) n);
frame_at_emit_log : ∀ data topics,
preservesCallback invariant (host.(Evmc.HOST.emit_log) self data topics);
frame_at_selfdestruct : ∀ b,
preservesCallback invariant (host.(Evmc.HOST.selfdestruct) self b)
}.
Lemma primitive_frame_at {Host_t : Set} (host : Evmc.HOST (t := Host_t)) invariant self :
PrimitiveHostFrame host invariant → PrimitiveHostFrameAt host invariant self.
Proof. intro H; destruct H; constructor; intros; eauto. Qed.
Definition primitiveHostOpcode (opcode : Opcode.t) : bool :=
match opcode with
| Opcode.Balance | Opcode.Extcodesize | Opcode.Extcodecopy | Opcode.Extcodehash
| Opcode.Blockhash | Opcode.Selfbalance | Opcode.Sload | Opcode.Sstore
| Opcode.Tload | Opcode.Tstore | Opcode.Log _ | Opcode.Selfdestruct ⇒ true
| _ ⇒ false
end.
Definition recursiveCallOpcode (opcode : Opcode.t) : bool :=
match opcode with
| Opcode.Create | Opcode.Call | Opcode.Callcode | Opcode.Delegatecall
| Opcode.Create2 | Opcode.Staticcall ⇒ true
| _ ⇒ false
end.
Ltac solve_host_invariant_extra ::=
lazymatch goal with
| |- preservesHost _ (@V.M.Seq.mapM _ _ _ _ _ _) ⇒
apply preserves_seq_map; intro; solve_host_invariant
| |- preservesHost _ (@V.M.HostAPI.lift _ _ _ _) ⇒
apply preserves_lift; unfold preservesCallback in *; eauto using word_encoding_length
| |- preservesHost _ (match ?value with _ ⇒ _ end) ⇒
destruct value; solve_host_invariant
| |- ?g ⇒ fail "Unhandled Host frame goal:" g
end.
Section Opcodes.
Context {Host_t : Set} {F : @MonadVM.Vm.Make.FArgs Host_t}.
Context `{U0 : RocqOfOCaml.Basics.Unreachable Z.t}.
Context `{U1 :
RocqOfOCaml.Basics.Unreachable (RocqOfOCaml.OCamlSeq.t int)}.
Context `{U2 : RocqOfOCaml.Basics.Unreachable RocqOfOCaml.OCamlInt32.t}.
Context `{U3 : RocqOfOCaml.Basics.Unreachable MonadVM.Uint64.t}.
Context `{U4 :
RocqOfOCaml.Basics.Unreachable MonadVM.Support.UintN.t}.
Context `{U5 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.U256.Repr.t}.
Context `{U7 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.Integer.t}.
Context `{U8 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.I256.t}.
Context `{U9 : RocqOfOCaml.Basics.Unreachable MonadVM.Gas.t}.
Context `{U10 :
RocqOfOCaml.Basics.Unreachable MonadVM.Delegation.Address.t}.
Context `{U11 :
RocqOfOCaml.Basics.Unreachable MonadVM.Chain.Ethereum.Address.t}.
Context `{U12 :
RocqOfOCaml.Basics.Unreachable MonadVM.Byte_string.Bytes.t}.
Context `{U13 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.M.Option.t Host_t F MonadVM.Numeric.U256.t)}.
Context `{U15 : RocqOfOCaml.Basics.Unreachable unit}.
Context `{U16 : RocqOfOCaml.Basics.Unreachable string}.
Context `{U17 :
RocqOfOCaml.Basics.Unreachable (option MonadVM.Numeric.U256.t)}.
Context `{U18 : RocqOfOCaml.Basics.Unreachable (option string)}.
Context `{U19 :
RocqOfOCaml.Basics.Unreachable
(list MonadVM.Byte_string.Bytes.t)}.
Context `{U20 : RocqOfOCaml.Basics.Unreachable (list int)}.
Context `{U21 : RocqOfOCaml.Basics.Unreachable int}.
Context `{U22 : RocqOfOCaml.Basics.Unreachable ascii}.
Context `{U23 : RocqOfOCaml.Basics.Unreachable (int × int)}.
Context `{U24 :
RocqOfOCaml.Basics.Unreachable
(Z.t → MonadVM.Numeric.U256.t)}.
Context `{U25 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Support.UintN.t → MonadVM.Support.UintN.t)}.
Context `{U26 :
RocqOfOCaml.Basics.Unreachable
(unit → RocqOfOCaml.OCamlSeq.node int)}.
Context `{U27 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.opcode_impl Host_t F)}.
Context `{U28 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Numeric.IntegerBase.(MonadVM.Numeric.Make.Make_result.t)}.
Context `{U31 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.t)}.
Context `{U32 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Numeric.U256.t → MonadVM.Numeric.U256.t →
@MonadVM.Vm.Make.Memory.t Host_t F →
@MonadVM.Vm.Make.M.Option.t Host_t F
(@MonadVM.Vm.Make.Memory.t Host_t F))}.
Context `{U33 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.Memory.t Host_t F →
MonadVM.Support.UintN.t)}.
Let State := @MonadVM.Vm.Make.MachineState.t Host_t F.
Section Environment.
Context {E : @V.Executor.FArgs Host_t F}.
Local Abbreviation executeOpcode := (@dispatch Host_t F E).
Lemma primitive_host_preserves_at (invariant : Host_t → Prop) opcode :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
primitiveHostOpcode opcode = true → preservesHost invariant (executeOpcode opcode).
Proof.
intros Hrevision Hdebug Hhost Hprimitive. destruct Hhost.
destruct opcode; cbn [primitiveHostOpcode] in Hprimitive; try discriminate.
all: cbn [dispatch V.Executor.execute_opcode].
all: unfold V.Executor.balance, V.Executor.extcodesize, V.Executor.extcodecopy,
V.Executor.extcodehash, V.Executor.blockhash, V.Executor.selfbalance,
V.Executor.sload, V.Executor.sstore, V.Executor.tload, V.Executor.tstore,
V.Executor.log, V.Executor.selfdestruct.
all: unfold V.Executor.debug_tstore_stack, V.Executor.extend_memory_to,
V.Executor.check_write_permissions, V.Executor.self.
all: try rewrite Hrevision; try rewrite Hdebug.
all: unfold V.M.HostAPI.get_balance, V.M.HostAPI.access_account,
V.M.HostAPI.get_code_size, V.M.HostAPI.copy_code, V.M.HostAPI.get_code_hash,
V.M.HostAPI.get_block_hash, V.M.HostAPI.access_storage, V.M.HostAPI.get_storage,
V.M.HostAPI.set_storage, V.M.HostAPI.get_transient_storage,
V.M.HostAPI.set_transient_storage, V.M.HostAPI.account_exists,
V.M.HostAPI.emit_log, V.M.HostAPI.selfdestruct, V.M.HostAPI.Base.
all: cbn beta iota zeta; cbn [negb].
all: solve_host_invariant.
Qed.
Lemma primitive_host_preserves (invariant : Host_t → Prop) opcode :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
primitiveHostOpcode opcode = true → preservesHost invariant (executeOpcode opcode).
Proof.
intros Hrevision Hdebug Hhost Hprimitive.
apply primitive_host_preserves_at; try assumption.
apply primitive_frame_at. exact Hhost.
Qed.
All other opcode cases are discharged above, including LOG's finite
sequence of stack reads and SELFDESTRUCT's Host call. The remaining six
instructions make recursive calls and must establish the child gas bound.
Lemma run_preserves_from_calls_at
(invariant : Host_t → Prop) (state : State) :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ opcode before, recursiveCallOpcode opcode = true →
(Z.of_N (MS.t.gas before) < 2^63)%Z → invariant (MS.t.host before) →
invariant (MS.t.host (snd (executeOpcode opcode before)))) →
(Z.of_N (MS.t.gas state) < 2^63)%Z → invariant (MS.t.host state) →
invariant (MS.t.host (snd (@generated_run Host_t F E
state))).
Proof.
intros Hrevision Hdebug Hprimitive Hcalls Hgas Hinitial.
apply (@run_preserves_from_host_instructions Host_t F E
invariant state).
- exact Hrevision.
- exact Hdebug.
- intros opcode before Hnonlocal Hbound Hbefore.
destruct (primitiveHostOpcode opcode) eqn:Hopcode.
+ apply primitive_host_preserves_at; assumption.
+ apply Hcalls; try assumption.
destruct opcode; cbn [recursiveCallOpcode machineOnlyOpcode primitiveHostOpcode] in *;
congruence.
- exact Hgas.
- exact Hinitial.
Qed.
Lemma run_preserves_from_calls
(invariant : Host_t → Prop) (state : State) :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ opcode before, recursiveCallOpcode opcode = true →
(Z.of_N (MS.t.gas before) < 2^63)%Z → invariant (MS.t.host before) →
invariant (MS.t.host (snd (executeOpcode opcode before)))) →
(Z.of_N (MS.t.gas state) < 2^63)%Z → invariant (MS.t.host state) →
invariant (MS.t.host (snd (@generated_run Host_t F E
state))).
Proof.
intros Hrevision Hdebug Hprimitive Hcalls Hgas Hinitial.
apply run_preserves_from_calls_at; try assumption.
apply primitive_frame_at. exact Hprimitive.
Qed.
End Environment.
End Opcodes.
Print Assumptions primitive_host_preserves.
Print Assumptions run_preserves_from_calls.
(invariant : Host_t → Prop) (state : State) :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ opcode before, recursiveCallOpcode opcode = true →
(Z.of_N (MS.t.gas before) < 2^63)%Z → invariant (MS.t.host before) →
invariant (MS.t.host (snd (executeOpcode opcode before)))) →
(Z.of_N (MS.t.gas state) < 2^63)%Z → invariant (MS.t.host state) →
invariant (MS.t.host (snd (@generated_run Host_t F E
state))).
Proof.
intros Hrevision Hdebug Hprimitive Hcalls Hgas Hinitial.
apply (@run_preserves_from_host_instructions Host_t F E
invariant state).
- exact Hrevision.
- exact Hdebug.
- intros opcode before Hnonlocal Hbound Hbefore.
destruct (primitiveHostOpcode opcode) eqn:Hopcode.
+ apply primitive_host_preserves_at; assumption.
+ apply Hcalls; try assumption.
destruct opcode; cbn [recursiveCallOpcode machineOnlyOpcode primitiveHostOpcode] in *;
congruence.
- exact Hgas.
- exact Hinitial.
Qed.
Lemma run_preserves_from_calls
(invariant : Host_t → Prop) (state : State) :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(@V.Params Host_t F).(Vm.Make_Params_signature.debug_tstore) = false →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ opcode before, recursiveCallOpcode opcode = true →
(Z.of_N (MS.t.gas before) < 2^63)%Z → invariant (MS.t.host before) →
invariant (MS.t.host (snd (executeOpcode opcode before)))) →
(Z.of_N (MS.t.gas state) < 2^63)%Z → invariant (MS.t.host state) →
invariant (MS.t.host (snd (@generated_run Host_t F E
state))).
Proof.
intros Hrevision Hdebug Hprimitive Hcalls Hgas Hinitial.
apply run_preserves_from_calls_at; try assumption.
apply primitive_frame_at. exact Hprimitive.
Qed.
End Environment.
End Opcodes.
Print Assumptions primitive_host_preserves.
Print Assumptions run_preserves_from_calls.