Library QedkConcrete.executionnocalls
System bytecode in the assembled concrete executor
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.hostnocalls QedkConcrete.supplyhostinstance
QedkConcrete.hostsupply QedkConcrete.precompilesframe QedkConcrete.assemblychecked.
Require Import MonadVM.Execution QedkConcrete.systemcode QedkConcrete.systemvmentry
QedkConcrete.nondebitframe QedkConcrete.hostframe QedkConcrete.hostcode
QedkConcrete.vmhostframe QedkConcrete.creationassembly
QedkConcrete.contexthostinstance QedkConcrete.vmsupplywords
QedkConcrete.vmcallchecked QedkConcrete.hashwords QedkConcrete.executioncreation.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Import ListNotations.
Module E := Execution.Make.
Module V := Vm.Make.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Context (limit : Z).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation invariant := (hostSupplyContext args.(Host.Instantiate.ChainParams) limit).
Lemma execution_vm_constructor_call_free vm (property : S.t → Prop) msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true →
PrimitiveHostFrameAt (HostF vm) property (Evmc.Message.t.recipient msg) →
invariant initial → property initial →
property (snd ((VmF (HostF vm)).(Evmc.Vm.SIG.execute) msg code initial)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hprimitive Hinitial Hproperty.
cbn -[Vm.Make.execute].
eapply (@execute_call_free_preserves args vm _ limit);
try solve [lazymatch goal with |- Basics.Unreachable _ ⇒
apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat end].
- exact Hrevision.
- reflexivity.
- exact Hhash.
- exact (proj2 Hinitial).
- exact Hmsg.
- exact Hcode.
- exact Hnocalls.
- exact Hprimitive.
- exact (proj1 Hinitial).
- exact Hproperty.
Qed.
Theorem execution_vm_call_free_preserves (property : S.t → Prop) msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true →
(∀ vm, PrimitiveHostFrameAt (HostF vm) property (Evmc.Message.t.recipient msg)) →
invariant initial → property initial →
property (snd (@Host.Instantiate.Vm.execute args msg code initial)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hprimitive Hinitial Hproperty.
change (property (snd ((@Evmc.Instantiate.Vm S.t (@recursiveArgs args))
.(Evmc.Vm.SIG.execute) msg code initial))).
unfold Evmc.Instantiate.Vm, Evmc.Instantiate._recursive_modules_Host_Vm.
generalize Evmc.Instantiate.recursive_module_fuel.
intros [|[|fuel]].
- exact Hproperty.
- cbn [recursive_module_unroll Evmc.Instantiate.recursive_module_seed fst snd].
apply execution_vm_constructor_call_free; try assumption. apply Hprimitive.
- cbn [recursive_module_unroll fst snd].
apply execution_vm_constructor_call_free; try assumption. apply Hprimitive.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.hostnocalls QedkConcrete.supplyhostinstance
QedkConcrete.hostsupply QedkConcrete.precompilesframe QedkConcrete.assemblychecked.
Require Import MonadVM.Execution QedkConcrete.systemcode QedkConcrete.systemvmentry
QedkConcrete.nondebitframe QedkConcrete.hostframe QedkConcrete.hostcode
QedkConcrete.vmhostframe QedkConcrete.creationassembly
QedkConcrete.contexthostinstance QedkConcrete.vmsupplywords
QedkConcrete.vmcallchecked QedkConcrete.hashwords QedkConcrete.executioncreation.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Import ListNotations.
Module E := Execution.Make.
Module V := Vm.Make.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Context (limit : Z).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation invariant := (hostSupplyContext args.(Host.Instantiate.ChainParams) limit).
Lemma execution_vm_constructor_call_free vm (property : S.t → Prop) msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true →
PrimitiveHostFrameAt (HostF vm) property (Evmc.Message.t.recipient msg) →
invariant initial → property initial →
property (snd ((VmF (HostF vm)).(Evmc.Vm.SIG.execute) msg code initial)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hprimitive Hinitial Hproperty.
cbn -[Vm.Make.execute].
eapply (@execute_call_free_preserves args vm _ limit);
try solve [lazymatch goal with |- Basics.Unreachable _ ⇒
apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat end].
- exact Hrevision.
- reflexivity.
- exact Hhash.
- exact (proj2 Hinitial).
- exact Hmsg.
- exact Hcode.
- exact Hnocalls.
- exact Hprimitive.
- exact (proj1 Hinitial).
- exact Hproperty.
Qed.
Theorem execution_vm_call_free_preserves (property : S.t → Prop) msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true →
(∀ vm, PrimitiveHostFrameAt (HostF vm) property (Evmc.Message.t.recipient msg)) →
invariant initial → property initial →
property (snd (@Host.Instantiate.Vm.execute args msg code initial)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hprimitive Hinitial Hproperty.
change (property (snd ((@Evmc.Instantiate.Vm S.t (@recursiveArgs args))
.(Evmc.Vm.SIG.execute) msg code initial))).
unfold Evmc.Instantiate.Vm, Evmc.Instantiate._recursive_modules_Host_Vm.
generalize Evmc.Instantiate.recursive_module_fuel.
intros [|[|fuel]].
- exact Hproperty.
- cbn [recursive_module_unroll Evmc.Instantiate.recursive_module_seed fst snd].
apply execution_vm_constructor_call_free; try assumption. apply Hprimitive.
- cbn [recursive_module_unroll fst snd].
apply execution_vm_constructor_call_free; try assumption. apply Hprimitive.
Qed.
Unlike the arbitrary-bytecode nondebit theorem, this permits the
protected account to be delegated. No instruction can call into it.
Corollary execution_vm_call_free_nondebit msg code initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → Evmc.Message.t.recipient msg ≠ query →
invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hdifferent Hinitial.
pose proof (execution_vm_call_free_preserves
(@balanceFloor query (Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))))) msg code initial
Hrevision Hhash Hmsg Hcode Hnocalls
(fun vm ⇒ concrete_primitives_preserve_other_balance vm _ _ _ Hdifferent)
Hinitial (conj (proj1 (proj1 (proj1 Hinitial))) (Z.le_refl _))) as Hfloor.
exact (proj2 Hfloor).
Qed.
Corollary execution_vm_call_free_creation_set msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → invariant initial →
S.t.accounts_created_in_current_transaction
(snd (@Host.Instantiate.Vm.execute args msg code initial)) =
S.t.accounts_created_in_current_transaction initial.
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hinitial.
apply execution_vm_call_free_preserves with
(property := fun s ⇒ S.t.accounts_created_in_current_transaction s =
S.t.accounts_created_in_current_transaction initial); try assumption.
- intro vm. apply primitive_frame_at, concrete_primitives_preserve_creation_set.
- reflexivity.
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → Evmc.Message.t.recipient msg ≠ query →
invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hdifferent Hinitial.
pose proof (execution_vm_call_free_preserves
(@balanceFloor query (Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))))) msg code initial
Hrevision Hhash Hmsg Hcode Hnocalls
(fun vm ⇒ concrete_primitives_preserve_other_balance vm _ _ _ Hdifferent)
Hinitial (conj (proj1 (proj1 (proj1 Hinitial))) (Z.le_refl _))) as Hfloor.
exact (proj2 Hfloor).
Qed.
Corollary execution_vm_call_free_creation_set msg code initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → invariant initial →
S.t.accounts_created_in_current_transaction
(snd (@Host.Instantiate.Vm.execute args msg code initial)) =
S.t.accounts_created_in_current_transaction initial.
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hinitial.
apply execution_vm_call_free_preserves with
(property := fun s ⇒ S.t.accounts_created_in_current_transaction s =
S.t.accounts_created_in_current_transaction initial); try assumption.
- intro vm. apply primitive_frame_at, concrete_primitives_preserve_creation_set.
- reflexivity.
Qed.
At a system-message entry the creation set is empty. Without CREATE,
it stays empty, so no account's code can be installed or replaced.
Corollary execution_vm_call_free_code msg code initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → invariant initial →
S.t.accounts_created_in_current_transaction initial = [] →
A.t.code (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query)) =
A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None query)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hinitial Hempty.
pose proof (execution_vm_call_free_creation_set msg code initial
Hrevision Hhash Hmsg Hcode Hnocalls Hinitial) as Hset.
destruct (@execution_vm_preserves_creation F
msg code Hrevision (proj1 Hmsg) initial
(proj1 (proj1 (proj1 (proj1 Hinitial))))) as [_ Hframe].
apply (noncreated_code _ _ Hframe). rewrite Hset, Hempty. intro Hbad. inversion Hbad.
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg → OCamlString.length code < 2^256 →
callFreeBytes code = true → invariant initial →
S.t.accounts_created_in_current_transaction initial = [] →
A.t.code (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query)) =
A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None query)).
Proof.
intros Hrevision Hhash Hmsg Hcode Hnocalls Hinitial Hempty.
pose proof (execution_vm_call_free_creation_set msg code initial
Hrevision Hhash Hmsg Hcode Hnocalls Hinitial) as Hset.
destruct (@execution_vm_preserves_creation F
msg code Hrevision (proj1 Hmsg) initial
(proj1 (proj1 (proj1 (proj1 Hinitial))))) as [_ Hframe].
apply (noncreated_code _ _ Hframe). rewrite Hset, Hempty. intro Hbad. inversion Hbad.
Qed.
This instantiates the syntactic check with the prescribed runtime code.
Delegation of query is unrestricted. execution_system_call_nondebit
below also covers the Host entry's zero-value transfer and rollback.
Corollary execution_vm_prescribed_system_code_nondebit msg code initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
(code = beaconRootsCode ∨ code = historyStorageCode) →
Evmc.Message.t.recipient msg ≠ query → invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hcode Hdifferent Hinitial.
apply execution_vm_call_free_nondebit; try assumption.
- destruct Hcode as [Hcode|Hcode]; subst code; vm_compute; reflexivity.
- destruct Hcode as [Hcode|Hcode]; subst code;
[apply beaconRootsCode_call_free|apply historyStorageCode_call_free].
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
(code = beaconRootsCode ∨ code = historyStorageCode) →
Evmc.Message.t.recipient msg ≠ query → invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@Host.Instantiate.Vm.execute args msg code initial)))
(@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hcode Hdifferent Hinitial.
apply execution_vm_call_free_nondebit; try assumption.
- destruct Hcode as [Hcode|Hcode]; subst code; vm_compute; reflexivity.
- destruct Hcode as [Hcode|Hcode]; subst code;
[apply beaconRootsCode_call_free|apply historyStorageCode_call_free].
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Unlike a transaction, a system message has no reserve check to rely on.
Its zero-value root CALL and call-free code suffice to protect every other
account, regardless of delegation.
Theorem execution_system_call_nondebit msg initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
Evmc.Message.t.recipient msg ≠ query →
Evmc.Message.t.code_address msg ≠ query →
invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@E.Host.call F
msg initial))) (@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hdifferent Hneq Hinitial.
set (minimum := Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query)))).
assert (Hfloor : @balanceFloor query minimum initial).
{ split; [exact (proj1 (proj1 (proj1 Hinitial)))|apply Z.le_refl]. }
assert (Hvm : ∀ code, OCamlString.length code < 2^256 → callFreeBytes code = true →
∀ middle, invariant middle → @balanceFloor query minimum middle →
@balanceFloor query minimum
(snd (@Host.Instantiate.Vm.execute args msg code middle))).
{ intros code Hsize Hfree middle Hcontext Hbefore.
apply execution_vm_call_free_preserves; try assumption.
intro vm. apply concrete_primitives_preserve_other_balance. exact Hdifferent. }
pose proof (@system_call_free_balance args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit query minimum msg initial
Hneq Hrevision Hkind Hzero Hcreated Hcode) as Hhost.
assert (Hafter : @balanceFloor query minimum (snd
((HostF (@H.Vm (@Host.Instantiate.Host_fargs args))).(Evmc.HOST.call) msg initial))).
{ apply Hhost; [|exact Hinitial|exact Hfloor].
intros code Hsize Hfree middle Hcontext Hbefore.
pose proof (Hvm code Hsize Hfree middle Hcontext Hbefore) as Hresult.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hresult |- ×.
exact Hresult. }
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
exact (proj2 Hafter).
Qed.
Theorem execution_system_call_no_creation msg initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
S.t.accounts_created_in_current_transaction (snd (@E.Host.call F
msg initial)) = [].
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
apply (@system_call_free_creation_set args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit msg initial);
try assumption.
intros code Hsize Hfree middle Hcontext Hempty.
pose proof (execution_vm_call_free_creation_set msg code middle
Hrevision Hhash Hmsg Hsize Hfree Hcontext) as Hset.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hset |- ×.
etransitivity; [exact Hset|exact Hempty].
Qed.
Theorem execution_system_call_code msg initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
A.t.code (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@E.Host.call F
msg initial))) (@W.account None query)) =
A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial) (@W.account None query)).
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
pose proof (execution_system_call_no_creation msg initial Hrevision Hhash Hmsg Hkind
Hzero Hcreated Hcode Hinitial) as Hset.
destruct (@execution_host_call_preserves_creation F
msg Hrevision (proj1 Hmsg) initial
(proj1 (proj1 (proj1 (proj1 Hinitial))))) as [_ Hframe].
apply (noncreated_code _ _ Hframe).
match type of Hset with ?created = _ ⇒ change (¬ In query created) end.
rewrite Hset. intro Hbad; inversion Hbad.
Qed.
Theorem execution_system_call_supply msg initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
let after := snd (@E.Host.call F msg initial) in
supply.balanceInvariant (S.t.world_state after) ∧
supply.totalBalance (S.t.world_state after) ≤ limit.
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
cbn zeta. unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host H.functor H.Make_result.call].
apply (@system_call_free_preserves args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit
(fun st ⇒ supply.balanceInvariant (S.t.world_state st) ∧
supply.totalBalance (S.t.world_state st) ≤ limit) msg initial); try assumption.
- intros code Hsize Hfree middle Hcontext Hbefore.
pose proof (execution_vm_call_free_preserves
(fun st ⇒ supply.balanceInvariant (S.t.world_state st) ∧
supply.totalBalance (S.t.world_state st) ≤ limit) msg code middle Hrevision
Hhash Hmsg Hsize Hfree (fun vm ⇒ primitive_frame_at _ _ _
(concrete_primitives_preserve_supply vm limit)) Hcontext Hbefore) as Hresult.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hresult |- ×.
exact Hresult.
- intros action Hselected. apply supply_callback.
unfold nativeDispatch in Hselected.
match type of Hselected with ?lookup = Some _ ⇒
let rec replace_head f :=
lazymatch f with
| ?g ?arg ⇒ let g' := replace_head g in constr:(g' arg)
| _ ⇒ constr:(@try_precompile_preserves_supply)
end in
let proof := replace_head lookup in exact (proof action Hrevision Hselected)
end.
- intros before Hcontext Hbefore. apply supply_callback with
(action := @H.transfer_ether (H.Build_FArgs args.(Host.Instantiate.ChainParams)
(@H.Vm (@Host.Instantiate.Host_fargs args)))
(Evmc.Message.t.sender msg) (Evmc.Message.t.recipient msg) (Evmc.Message.t.value msg));
[apply supply_transfer; lia|exact Hbefore].
- exact (proj1 (proj1 Hinitial)).
Qed.
End Execution.
Print Assumptions execution_vm_call_free_nondebit.
Print Assumptions execution_vm_call_free_code.
Print Assumptions execution_vm_prescribed_system_code_nondebit.
Print Assumptions execution_system_call_nondebit.
Print Assumptions execution_system_call_code.
Print Assumptions execution_system_call_supply.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
Evmc.Message.t.recipient msg ≠ query →
Evmc.Message.t.code_address msg ≠ query →
invariant initial →
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query))) ≤
Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@E.Host.call F
msg initial))) (@W.account None query))).
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hdifferent Hneq Hinitial.
set (minimum := Numeric.U256.to_z (A.t.balance (State.op_pointcaretlparenrparen
(S.t.world_state initial) (@W.account None query)))).
assert (Hfloor : @balanceFloor query minimum initial).
{ split; [exact (proj1 (proj1 (proj1 Hinitial)))|apply Z.le_refl]. }
assert (Hvm : ∀ code, OCamlString.length code < 2^256 → callFreeBytes code = true →
∀ middle, invariant middle → @balanceFloor query minimum middle →
@balanceFloor query minimum
(snd (@Host.Instantiate.Vm.execute args msg code middle))).
{ intros code Hsize Hfree middle Hcontext Hbefore.
apply execution_vm_call_free_preserves; try assumption.
intro vm. apply concrete_primitives_preserve_other_balance. exact Hdifferent. }
pose proof (@system_call_free_balance args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit query minimum msg initial
Hneq Hrevision Hkind Hzero Hcreated Hcode) as Hhost.
assert (Hafter : @balanceFloor query minimum (snd
((HostF (@H.Vm (@Host.Instantiate.Host_fargs args))).(Evmc.HOST.call) msg initial))).
{ apply Hhost; [|exact Hinitial|exact Hfloor].
intros code Hsize Hfree middle Hcontext Hbefore.
pose proof (Hvm code Hsize Hfree middle Hcontext Hbefore) as Hresult.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hresult |- ×.
exact Hresult. }
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
exact (proj2 Hafter).
Qed.
Theorem execution_system_call_no_creation msg initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
S.t.accounts_created_in_current_transaction (snd (@E.Host.call F
msg initial)) = [].
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
apply (@system_call_free_creation_set args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit msg initial);
try assumption.
intros code Hsize Hfree middle Hcontext Hempty.
pose proof (execution_vm_call_free_creation_set msg code middle
Hrevision Hhash Hmsg Hsize Hfree Hcontext) as Hset.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hset |- ×.
etransitivity; [exact Hset|exact Hempty].
Qed.
Theorem execution_system_call_code msg initial query :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
A.t.code (State.op_pointcaretlparenrparen
(S.t.world_state (snd (@E.Host.call F
msg initial))) (@W.account None query)) =
A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial) (@W.account None query)).
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
pose proof (execution_system_call_no_creation msg initial Hrevision Hhash Hmsg Hkind
Hzero Hcreated Hcode Hinitial) as Hset.
destruct (@execution_host_call_preserves_creation F
msg Hrevision (proj1 Hmsg) initial
(proj1 (proj1 (proj1 (proj1 Hinitial))))) as [_ Hframe].
apply (noncreated_code _ _ Hframe).
match type of Hset with ?created = _ ⇒ change (¬ In query created) end.
rewrite Hset. intro Hbad; inversion Hbad.
Qed.
Theorem execution_system_call_supply msg initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
Numeric.U256.to_z (Evmc.Message.t.value msg) = 0 →
S.t.accounts_created_in_current_transaction initial = [] →
callFreeBytes (A.t.code (State.op_pointcaretlparenrparen (S.t.world_state initial)
(@W.account None (Evmc.Message.t.code_address msg)))) = true →
invariant initial →
let after := snd (@E.Host.call F msg initial) in
supply.balanceInvariant (S.t.world_state after) ∧
supply.totalBalance (S.t.world_state after) ≤ limit.
Proof.
intros Hrevision Hhash Hmsg Hkind Hzero Hcreated Hcode Hinitial.
cbn zeta. unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host H.functor H.Make_result.call].
apply (@system_call_free_preserves args
(@H.Vm (@Host.Instantiate.Host_fargs args)) limit
(fun st ⇒ supply.balanceInvariant (S.t.world_state st) ∧
supply.totalBalance (S.t.world_state st) ≤ limit) msg initial); try assumption.
- intros code Hsize Hfree middle Hcontext Hbefore.
pose proof (execution_vm_call_free_preserves
(fun st ⇒ supply.balanceInvariant (S.t.world_state st) ∧
supply.totalBalance (S.t.world_state st) ≤ limit) msg code middle Hrevision
Hhash Hmsg Hsize Hfree (fun vm ⇒ primitive_frame_at _ _ _
(concrete_primitives_preserve_supply vm limit)) Hcontext Hbefore) as Hresult.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hresult |- ×.
exact Hresult.
- intros action Hselected. apply supply_callback.
unfold nativeDispatch in Hselected.
match type of Hselected with ?lookup = Some _ ⇒
let rec replace_head f :=
lazymatch f with
| ?g ?arg ⇒ let g' := replace_head g in constr:(g' arg)
| _ ⇒ constr:(@try_precompile_preserves_supply)
end in
let proof := replace_head lookup in exact (proof action Hrevision Hselected)
end.
- intros before Hcontext Hbefore. apply supply_callback with
(action := @H.transfer_ether (H.Build_FArgs args.(Host.Instantiate.ChainParams)
(@H.Vm (@Host.Instantiate.Host_fargs args)))
(Evmc.Message.t.sender msg) (Evmc.Message.t.recipient msg) (Evmc.Message.t.value msg));
[apply supply_transfer; lia|exact Hbefore].
- exact (proj1 (proj1 Hinitial)).
Qed.
End Execution.
Print Assumptions execution_vm_call_free_nondebit.
Print Assumptions execution_vm_call_free_code.
Print Assumptions execution_vm_prescribed_system_code_nondebit.
Print Assumptions execution_system_call_nondebit.
Print Assumptions execution_system_call_code.
Print Assumptions execution_system_call_supply.