Library QedkConcrete.vmcallprotected
Checked CALL boundaries retain execution-context provenance
From Stdlib Require Import List String ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.vmcallchecked QedkConcrete.vmchecked
QedkConcrete.vmmachinewords QedkConcrete.vmmemorywords QedkConcrete.vmsizes
QedkConcrete.vmchildsizes QedkConcrete.memorywords QedkConcrete.memorysizes
QedkConcrete.wordrange QedkConcrete.vmcallframe QedkConcrete.vmhostframe
QedkConcrete.vmboundedframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCallHandlerProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmChildGasMerge
MonadExecutionSpecs.Termination.VmCallGas.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Weaken.
Context {Host_t : Set} {F : @V.FArgs Host_t}.
Lemma checked_machine_weaken (pre post : Host_t → Prop) state :
(∀ h, pre h → post h) →
checkedMachine pre state → checkedMachine post state.
Proof.
intros Hweaken [[Hstack [Hpc [Hhost Hmemory]]] Hsizes].
exact (conj (conj Hstack (conj Hpc (conj (Hweaken _ Hhost) Hmemory))) Hsizes).
Qed.
Lemma bounded_checked_bind_between {A B : Set} (pre post : Host_t → Prop)
(P : A → Prop) (Q : B → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
(∀ h, pre h → post h) →
checkedSafe pre P action → gas_nonincreasing action →
(∀ value, P value → ∀ state, Z.of_N (MS.t.gas state) < 2^63 →
checkedMachine pre state →
(checkedMachine post (snd (next value state)) ∧
match fst (next value state) with inl v ⇒ Q v | inr _ ⇒ True end) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.M.op_letdollar Host_t F A B action next state)) ∧
match fst (@V.M.op_letdollar Host_t F A B action next state) with
| inl v ⇒ Q v | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hweaken Haction Hgas Hnext state Hbound Hinitial.
destruct (Haction state Hinitial) as [Hprefix|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine post (snd
(match action state with (inl v, st) ⇒ next v st | (inr e, st) ⇒ (inr e, st) end)) ∧
match fst
(match action state with (inl v, st) ⇒ next v st | (inr e, st) ⇒ (inr e, st) end)
with inl v ⇒ Q v | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (action state) as [[value|error] middle] eqn:Hrun; cbn [fst snd] in Hprefix.
- apply Hnext; [exact (proj2 Hprefix)| |exact (proj1 Hprefix)].
pose proof (Hgas state value middle Hrun). lia.
- left. split; [eapply checked_machine_weaken; [exact Hweaken|exact (proj1 Hprefix)]|exact I].
Qed.
End Weaken.
Section Call.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context (invariant : Host_t → Prop).
Lemma generic_call_checked_at_context
kind forwarded value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Z.of_N forwarded < 2^63 → wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
0 ≤ U.to_z outputSize < 2^32 →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient ∧
match delegation with
| V.Executor.Direct _ ⇒ Evmc.Message.t.code_address msg = codeAddr ∧
Evmc.Message.t.delegated msg = false
| _ ⇒ True
end) → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
checkedSafe invariant (fun _ ⇒ True) (@V.Executor.generic_call_impl Host_t F E
kind (@U.of_uint_exn forwarded) value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize).
Proof.
intros Hrevision Hgas Hvalue Hinput HoutBound Hchild. unfold V.Executor.generic_call_impl.
eapply checked_safe_bind with (P := fun _ ⇒ True).
- apply checked_safe_output_write. cbn. lia.
- intros [] _. match goal with |- checkedSafe _ _ (if ?test then _ else _) ⇒ destruct test end.
+ finish_call.
+ eapply checked_safe_bind; [apply checked_safe_memory_read|].
intros memory [Hwords Hfits].
destruct (@read_small_input_bounded Host_t F UI inputStart inputSize
memory Hinput Hwords) as [Hlength|Hfailure].
2: { intros state Hinitial. right. exact Hfailure. }
destruct delegation; cbn beta iota zeta.
all: eapply checked_safe_bind with
(P := fun result ⇒ OCamlString.length (Evmc.Result.t.output_data result) < 2^256);
[apply checked_safe_call; apply Hchild|
intros [status gas refund output addr] Houtput; cbn [Evmc.Result.t.output_data] in Houtput;
unfold V.Executor.merge_child_gas_and_refund; finish_call].
all: try solve [repeat split; reflexivity].
all: unfold vmMessageBounds; cbn [Evmc.Message.t.gas Evmc.Message.t.value
Evmc.Message.t.input_data Evmc.Message.t.memory_capacity].
all: split; [rewrite u256_forwarded_gas_small_identity by lia; lia|].
all: split; [exact Hvalue|].
all: split; [lia|].
all: cbv beta iota zeta delta
[V.Memory V.Memory.module V.Memory.Memory_signature.available_memory_size].
all: apply (encoded_capacity_all_decoders (UI := Opaque.legacy_witness 0%Z)).
all: lazymatch goal with
| |- Z.of_N (@Mem.available_memory_size ?H ?F ?mem) < _ ⇒
pose proof (@available_nine_memory_bounded H F UMem mem Hrevision (proj1 Hfits)) as Hbound;
destruct Hfits; lia
end.
Qed.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
Ltac finish_call_extra ::=
lazymatch goal with
| |- context [@V.Executor.generic_call_impl] ⇒
apply generic_call_checked_at_context; try assumption;
intros msg Hbounds [Hkind [Hsender [Hrecipient Hdirect]]] host Hhost;
cbn in Hdirect; try destruct Hdirect as [Hcode Hdelegated];
match goal with
| Hchild : ∀ msg, vmMessageBounds msg → _ → ∀ host, _ → _ |- _ ⇒
apply Hchild; [exact Hbounds|repeat split; assumption|exact Hhost]
end
| |- checkedSafe _ _ (Monad.SIG_MONAD._return _ _) ⇒
let st := fresh "st" in let Hst := fresh "Hst" in
intros st Hst; left; split; [exact Hst|exact I]
| |- ?g ⇒ fail 1 "Unhandled CALL invariant case" g
end.
Lemma call_opcode_checked_at_context
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient) → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static).
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hprimitive Hchild. destruct Hprimitive.
unfold V.Executor.call_opcode_impl.
eapply bounded_checked_bind_prefix.
- apply (checked_safe_extend_input invariant); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input invariant); assumption.
+ apply extend_memory_to_nonincreasing.
+ intros outputGas HoutBound. eapply bounded_checked_bind_prefix.
× apply checked_safe_fmap with (P := fun _ ⇒ True). expose_call_primitives. finish_call.
× apply map_nonincreasing, access_account_nonincreasing.
× intros accessGas [accessStatus [_ ->]].
eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ unfold V.Executor.access_delegation. expose_call_primitives. finish_call; try assumption. }
{ apply access_delegation_nonincreasing. }
intros delegation _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call; try assumption. }
{ apply account_exists_nonincreasing. }
intros targetAlive _. intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
change ((checkedMachine invariant (snd (next (MS.t.gas state) state)) ∧
match fst (next (MS.t.gas state) state) with inl _ ⇒ True | inr _ ⇒ True end) ∨
badMemoryInitComparison)
end.
cbn beta.
set (transfer := andb (Evmc.Message.CallKind.op_ltgt kind
Evmc.Message.CallKind.DelegateCall)
(U.op_ltgt value (@U.zero))) in ×.
set (memoryGas := @Gas.op_plus inputGas outputGas) in ×.
match goal with |- context [@Gas.call_gas_value transfer requested
(MS.t.gas state) memoryGas ?cost] ⇒ set (extra := cost) in × end.
assert (Hextra : (100 + (if transfer then @Gas.call_value else 0) ≤ extra)%N).
{ unfold extra. pose proof (@account_access_min accessStatus) as Haccess.
destruct transfer, delegation, targetAlive;
cbn [andb negb]; unfold Gas.op_plus, Gas.zero, Support.UintN.op_plus, Support.UintN.zero; lia. }
match goal with |- context [@V.M.op_letdollar _ _ _ _ (@V.spend _ _ ?amount) ?next] ⇒
set (nextCall := next); set (spentGas := amount)
end.
destruct (@checked_safe_spend Host_t F invariant UG spentGas state Hinitial)
as [[Hframe _]|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine invariant (snd
(match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end)) ∧
match fst (match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (@V.spend Host_t F spentGas state) as [[[]|error] charged] eqn:Hspent.
2: { left. split; [exact Hframe|exact I]. }
pose proof (spend_success_exact _ _ _ Hspent) as [Hafford Hcharged].
pose proof (@call_quote_total_decreases transfer requested
(MS.t.gas state) memoryGas extra Hextra Hafford) as HgasChild.
cbn zeta in HgasChild.
assert (Hforwarded : (Z.of_N
(@Gas.call_gas_value transfer requested (MS.t.gas state) memoryGas extra)
.(Gas.call_gas.callee_available_gas) < 2^63)%Z) by lia.
assert (Hnext : checkedSafe invariant (fun _ ⇒ True) (nextCall tt)).
{ unfold nextCall, V.Executor.check_write_permissions, V.M.when_, Monad.Make_Monad.when_.
expose_call_primitives. finish_call; try assumption. }
apply Hnext. exact Hframe.
Qed.
End Call.
Ltac finish_call_extra ::=
lazymatch goal with
| |- context [@V.Executor.generic_call_impl] ⇒
lazymatch goal with |- checkedSafe ?inv _ _ ⇒
apply (generic_call_checked_at_context inv) end; try assumption;
intros msg Hbounds [Hkind [Hsender [Hrecipient Hdirect]]] host Hhost;
cbn in Hdirect; try destruct Hdirect as [Hcode Hdelegated];
match goal with
| Hchild : ∀ msg, vmMessageBounds msg → _ → ∀ host, _ → _ |- _ ⇒
apply Hchild; [exact Hbounds|repeat split; assumption|exact Hhost]
end
| |- checkedSafe _ _ (Monad.SIG_MONAD._return _ _) ⇒
let st := fresh "st" in let Hst := fresh "Hst" in
intros st Hst; left; split; [exact Hst|exact I]
| |- ?g ⇒ fail 1 "Unhandled CALL invariant case" g
end.
Section EmptyCall.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.vmcallchecked QedkConcrete.vmchecked
QedkConcrete.vmmachinewords QedkConcrete.vmmemorywords QedkConcrete.vmsizes
QedkConcrete.vmchildsizes QedkConcrete.memorywords QedkConcrete.memorysizes
QedkConcrete.wordrange QedkConcrete.vmcallframe QedkConcrete.vmhostframe
QedkConcrete.vmboundedframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCallHandlerProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmChildGasMerge
MonadExecutionSpecs.Termination.VmCallGas.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Weaken.
Context {Host_t : Set} {F : @V.FArgs Host_t}.
Lemma checked_machine_weaken (pre post : Host_t → Prop) state :
(∀ h, pre h → post h) →
checkedMachine pre state → checkedMachine post state.
Proof.
intros Hweaken [[Hstack [Hpc [Hhost Hmemory]]] Hsizes].
exact (conj (conj Hstack (conj Hpc (conj (Hweaken _ Hhost) Hmemory))) Hsizes).
Qed.
Lemma bounded_checked_bind_between {A B : Set} (pre post : Host_t → Prop)
(P : A → Prop) (Q : B → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
(∀ h, pre h → post h) →
checkedSafe pre P action → gas_nonincreasing action →
(∀ value, P value → ∀ state, Z.of_N (MS.t.gas state) < 2^63 →
checkedMachine pre state →
(checkedMachine post (snd (next value state)) ∧
match fst (next value state) with inl v ⇒ Q v | inr _ ⇒ True end) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.M.op_letdollar Host_t F A B action next state)) ∧
match fst (@V.M.op_letdollar Host_t F A B action next state) with
| inl v ⇒ Q v | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hweaken Haction Hgas Hnext state Hbound Hinitial.
destruct (Haction state Hinitial) as [Hprefix|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine post (snd
(match action state with (inl v, st) ⇒ next v st | (inr e, st) ⇒ (inr e, st) end)) ∧
match fst
(match action state with (inl v, st) ⇒ next v st | (inr e, st) ⇒ (inr e, st) end)
with inl v ⇒ Q v | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (action state) as [[value|error] middle] eqn:Hrun; cbn [fst snd] in Hprefix.
- apply Hnext; [exact (proj2 Hprefix)| |exact (proj1 Hprefix)].
pose proof (Hgas state value middle Hrun). lia.
- left. split; [eapply checked_machine_weaken; [exact Hweaken|exact (proj1 Hprefix)]|exact I].
Qed.
End Weaken.
Section Call.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context (invariant : Host_t → Prop).
Lemma generic_call_checked_at_context
kind forwarded value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Z.of_N forwarded < 2^63 → wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
0 ≤ U.to_z outputSize < 2^32 →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient ∧
match delegation with
| V.Executor.Direct _ ⇒ Evmc.Message.t.code_address msg = codeAddr ∧
Evmc.Message.t.delegated msg = false
| _ ⇒ True
end) → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
checkedSafe invariant (fun _ ⇒ True) (@V.Executor.generic_call_impl Host_t F E
kind (@U.of_uint_exn forwarded) value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize).
Proof.
intros Hrevision Hgas Hvalue Hinput HoutBound Hchild. unfold V.Executor.generic_call_impl.
eapply checked_safe_bind with (P := fun _ ⇒ True).
- apply checked_safe_output_write. cbn. lia.
- intros [] _. match goal with |- checkedSafe _ _ (if ?test then _ else _) ⇒ destruct test end.
+ finish_call.
+ eapply checked_safe_bind; [apply checked_safe_memory_read|].
intros memory [Hwords Hfits].
destruct (@read_small_input_bounded Host_t F UI inputStart inputSize
memory Hinput Hwords) as [Hlength|Hfailure].
2: { intros state Hinitial. right. exact Hfailure. }
destruct delegation; cbn beta iota zeta.
all: eapply checked_safe_bind with
(P := fun result ⇒ OCamlString.length (Evmc.Result.t.output_data result) < 2^256);
[apply checked_safe_call; apply Hchild|
intros [status gas refund output addr] Houtput; cbn [Evmc.Result.t.output_data] in Houtput;
unfold V.Executor.merge_child_gas_and_refund; finish_call].
all: try solve [repeat split; reflexivity].
all: unfold vmMessageBounds; cbn [Evmc.Message.t.gas Evmc.Message.t.value
Evmc.Message.t.input_data Evmc.Message.t.memory_capacity].
all: split; [rewrite u256_forwarded_gas_small_identity by lia; lia|].
all: split; [exact Hvalue|].
all: split; [lia|].
all: cbv beta iota zeta delta
[V.Memory V.Memory.module V.Memory.Memory_signature.available_memory_size].
all: apply (encoded_capacity_all_decoders (UI := Opaque.legacy_witness 0%Z)).
all: lazymatch goal with
| |- Z.of_N (@Mem.available_memory_size ?H ?F ?mem) < _ ⇒
pose proof (@available_nine_memory_bounded H F UMem mem Hrevision (proj1 Hfits)) as Hbound;
destruct Hfits; lia
end.
Qed.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
Ltac finish_call_extra ::=
lazymatch goal with
| |- context [@V.Executor.generic_call_impl] ⇒
apply generic_call_checked_at_context; try assumption;
intros msg Hbounds [Hkind [Hsender [Hrecipient Hdirect]]] host Hhost;
cbn in Hdirect; try destruct Hdirect as [Hcode Hdelegated];
match goal with
| Hchild : ∀ msg, vmMessageBounds msg → _ → ∀ host, _ → _ |- _ ⇒
apply Hchild; [exact Hbounds|repeat split; assumption|exact Hhost]
end
| |- checkedSafe _ _ (Monad.SIG_MONAD._return _ _) ⇒
let st := fresh "st" in let Hst := fresh "Hst" in
intros st Hst; left; split; [exact Hst|exact I]
| |- ?g ⇒ fail 1 "Unhandled CALL invariant case" g
end.
Lemma call_opcode_checked_at_context
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient) → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static).
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hprimitive Hchild. destruct Hprimitive.
unfold V.Executor.call_opcode_impl.
eapply bounded_checked_bind_prefix.
- apply (checked_safe_extend_input invariant); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input invariant); assumption.
+ apply extend_memory_to_nonincreasing.
+ intros outputGas HoutBound. eapply bounded_checked_bind_prefix.
× apply checked_safe_fmap with (P := fun _ ⇒ True). expose_call_primitives. finish_call.
× apply map_nonincreasing, access_account_nonincreasing.
× intros accessGas [accessStatus [_ ->]].
eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ unfold V.Executor.access_delegation. expose_call_primitives. finish_call; try assumption. }
{ apply access_delegation_nonincreasing. }
intros delegation _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call; try assumption. }
{ apply account_exists_nonincreasing. }
intros targetAlive _. intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
change ((checkedMachine invariant (snd (next (MS.t.gas state) state)) ∧
match fst (next (MS.t.gas state) state) with inl _ ⇒ True | inr _ ⇒ True end) ∨
badMemoryInitComparison)
end.
cbn beta.
set (transfer := andb (Evmc.Message.CallKind.op_ltgt kind
Evmc.Message.CallKind.DelegateCall)
(U.op_ltgt value (@U.zero))) in ×.
set (memoryGas := @Gas.op_plus inputGas outputGas) in ×.
match goal with |- context [@Gas.call_gas_value transfer requested
(MS.t.gas state) memoryGas ?cost] ⇒ set (extra := cost) in × end.
assert (Hextra : (100 + (if transfer then @Gas.call_value else 0) ≤ extra)%N).
{ unfold extra. pose proof (@account_access_min accessStatus) as Haccess.
destruct transfer, delegation, targetAlive;
cbn [andb negb]; unfold Gas.op_plus, Gas.zero, Support.UintN.op_plus, Support.UintN.zero; lia. }
match goal with |- context [@V.M.op_letdollar _ _ _ _ (@V.spend _ _ ?amount) ?next] ⇒
set (nextCall := next); set (spentGas := amount)
end.
destruct (@checked_safe_spend Host_t F invariant UG spentGas state Hinitial)
as [[Hframe _]|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine invariant (snd
(match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end)) ∧
match fst (match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (@V.spend Host_t F spentGas state) as [[[]|error] charged] eqn:Hspent.
2: { left. split; [exact Hframe|exact I]. }
pose proof (spend_success_exact _ _ _ Hspent) as [Hafford Hcharged].
pose proof (@call_quote_total_decreases transfer requested
(MS.t.gas state) memoryGas extra Hextra Hafford) as HgasChild.
cbn zeta in HgasChild.
assert (Hforwarded : (Z.of_N
(@Gas.call_gas_value transfer requested (MS.t.gas state) memoryGas extra)
.(Gas.call_gas.callee_available_gas) < 2^63)%Z) by lia.
assert (Hnext : checkedSafe invariant (fun _ ⇒ True) (nextCall tt)).
{ unfold nextCall, V.Executor.check_write_permissions, V.M.when_, Monad.Make_Monad.when_.
expose_call_primitives. finish_call; try assumption. }
apply Hnext. exact Hframe.
Qed.
End Call.
Ltac finish_call_extra ::=
lazymatch goal with
| |- context [@V.Executor.generic_call_impl] ⇒
lazymatch goal with |- checkedSafe ?inv _ _ ⇒
apply (generic_call_checked_at_context inv) end; try assumption;
intros msg Hbounds [Hkind [Hsender [Hrecipient Hdirect]]] host Hhost;
cbn in Hdirect; try destruct Hdirect as [Hcode Hdelegated];
match goal with
| Hchild : ∀ msg, vmMessageBounds msg → _ → ∀ host, _ → _ |- _ ⇒
apply Hchild; [exact Hbounds|repeat split; assumption|exact Hhost]
end
| |- checkedSafe _ _ (Monad.SIG_MONAD._return _ _) ⇒
let st := fresh "st" in let Hst := fresh "Hst" in
intros st Hst; left; split; [exact Hst|exact I]
| |- ?g ⇒ fail 1 "Unhandled CALL invariant case" g
end.
Section EmptyCall.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
The prefix requires empty code at the protected address. A child may
create it, so only the weaker post-invariant must survive that child.
Lemma call_opcode_checked_empty_code (pre post : Host_t → Prop)
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) codeAddr 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient ∧
Evmc.Message.t.code_address msg = codeAddr ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static state)) ∧
match fst (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hweaken Hpre Hpost Hempty Hchild.
destruct Hpre. destruct Hpost.
unfold V.Executor.call_opcode_impl.
eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
- apply (checked_safe_extend_input pre ); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
+ apply (checked_safe_extend_input pre); assumption.
+ apply extend_memory_to_nonincreasing.
+ intros outputGas HoutBound. eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
× apply checked_safe_fmap with (P := fun _ ⇒ True). expose_call_primitives. finish_call.
× apply map_nonincreasing, access_account_nonincreasing.
× intros accessGas [accessStatus [_ ->]] beforeRead Hbound Hprefix.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ ?action ?next beforeRead)) ∧ _) ∨ _ ⇒
change ((checkedMachine post (snd
(match action beforeRead with
| (inl d, middle) ⇒ next d middle
| (inr err, middle) ⇒ (inr err, middle)
end)) ∧
match fst (match action beforeRead with
| (inl d, middle) ⇒ next d middle
| (inr err, middle) ⇒ (inr err, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison)
end.
rewrite (access_delegation_empty codeAddr beforeRead
(Hempty _ (proj1 (proj2 (proj2 (proj1 Hprefix)))))).
cbn beta iota zeta delta [fst snd].
match goal with |- (checkedMachine _ (snd (?action beforeRead)) ∧ _) ∨ _ ⇒
assert (Hrest : boundedCheckedSafe post (fun _ ⇒ True) action)
end.
{ eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call; try assumption. }
{ apply account_exists_nonincreasing. }
intros targetAlive _. intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
change ((checkedMachine post (snd (next (MS.t.gas state) state)) ∧
match fst (next (MS.t.gas state) state) with inl _ ⇒ True | inr _ ⇒ True end) ∨
badMemoryInitComparison)
end.
cbn beta.
set (transfer := andb (Evmc.Message.CallKind.op_ltgt kind
Evmc.Message.CallKind.DelegateCall)
(U.op_ltgt value (@U.zero))) in ×.
set (memoryGas := @Gas.op_plus inputGas outputGas) in ×.
match goal with |- context [@Gas.call_gas_value transfer requested
(MS.t.gas state) memoryGas ?cost] ⇒ set (extra := cost) in × end.
assert (Hextra : (100 + (if transfer then @Gas.call_value else 0) ≤ extra)%N).
{ unfold extra. pose proof (@account_access_min accessStatus) as Haccess.
destruct transfer, targetAlive;
cbn [andb negb]; unfold Gas.op_plus, Gas.zero, Support.UintN.op_plus, Support.UintN.zero; lia. }
match goal with |- context [@V.M.op_letdollar _ _ _ _ (@V.spend _ _ ?amount) ?next] ⇒
set (nextCall := next); set (spentGas := amount)
end.
destruct (@checked_safe_spend Host_t F post UG spentGas state Hinitial)
as [[Hframe _]|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine post (snd
(match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end)) ∧
match fst (match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (@V.spend Host_t F spentGas state) as [[[]|error] charged] eqn:Hspent.
2: { left. split; [exact Hframe|exact I]. }
pose proof (spend_success_exact _ _ _ Hspent) as [Hafford Hcharged].
pose proof (@call_quote_total_decreases transfer requested
(MS.t.gas state) memoryGas extra Hextra Hafford) as HgasChild.
cbn zeta in HgasChild.
assert (Hforwarded : (Z.of_N
(@Gas.call_gas_value transfer requested (MS.t.gas state) memoryGas extra)
.(Gas.call_gas.callee_available_gas) < 2^63)%Z) by lia.
assert (Hnext : checkedSafe post (fun _ ⇒ True) (nextCall tt)).
{ unfold nextCall, V.Executor.check_write_permissions, V.M.when_, Monad.Make_Monad.when_.
expose_call_primitives. finish_call; try assumption. }
apply Hnext. exact Hframe. }
apply Hrest; [exact Hbound|].
eapply checked_machine_weaken; [exact Hweaken|exact Hprefix].
Qed.
Lemma call_opcode_checked_empty_recipient (pre post : Host_t → Prop)
query requested value sender recipient
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient) →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call_opcode_impl Host_t F E
Evmc.Message.CallKind.Call requested value sender recipient recipient
inputStart inputSize outputStart outputSize static state)) ∧
match fst (@V.Executor.call_opcode_impl Host_t F E
Evmc.Message.CallKind.Call requested value sender recipient recipient
inputStart inputSize outputStart outputSize static state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hweaken Hpre Hpost Hempty Hchild.
destruct (String.string_dec recipient query) as [Heq|Hneq].
- subst recipient. apply call_opcode_checked_empty_code; try assumption.
intros msg Hbounds [Hkind [Hsender [Hrecipient [Hcode Hdelegated]]]].
apply Hchild; [exact Hbounds|repeat split; assumption|intros _; split; assumption].
- intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd (?action state)) ∧ _) ∨ _ ⇒
assert (Hframe : boundedCheckedSafe post (fun _ ⇒ True) action)
end.
{ apply (call_opcode_checked_at_context post (UG := UG)); try assumption.
intros msg Hbounds [Hkind [Hsender Hrecipient]].
apply Hchild; [exact Hbounds|repeat split; assumption|].
intro Heq. exfalso. apply Hneq. congruence. }
apply Hframe; [exact Hgas|].
eapply checked_machine_weaken; [exact Hweaken|exact Hinitial].
Qed.
End EmptyCall.
Section Wrappers.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
Context (invariant : Host_t → Prop).
Context {UR : Basics.Unreachable U.Repr.t} {UC : Basics.Unreachable ascii}
{UP : Basics.Unreachable (int × int)}.
Ltac checked_pops :=
lazymatch goal with
| |- checkedSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒ apply checked_safe_fmap; checked_pops
| |- checkedSafe _ _ (@V.pop _ _) ⇒ apply checked_safe_pop
| |- checkedSafe _ _ (@V.pop2 _ _) ⇒ apply checked_safe_pop2
| |- checkedSafe _ _ (@V.pop3 _ _) ⇒ apply checked_safe_pop3
end.
Ltac checked_call_origin_wrapper Hrevision Hprimitive Hchild :=
lazymatch goal with
| |- boundedCheckedSafe _ _ (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply bounded_checked_bind_prefix;
[checked_pops | solve [eauto using map_nonincreasing, pop_nonincreasing,
pop2_nonincreasing, pop3_nonincreasing] | ];
let v := fresh "v" in let Hv := fresh "Hv" in intros v Hv;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta delta [fst snd] in Hv |- *;
repeat match goal with H : _ ∧ _ |- _ ⇒ destruct H end;
checked_call_origin_wrapper Hrevision Hprimitive Hchild
| _ ⇒ apply (call_opcode_checked_at_context invariant (UG := UG));
[exact Hrevision|first [assumption|apply word_zero|unfold wordRange in *; lia]|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
exact Hprimitive|intros msg Hbounds [Hkind [Hsender Hrecipient]];
apply Hchild; [exact Hbounds|exact Hkind|unfold childCallFrom; rewrite Hkind;
first [exact Hsender|exact Hrecipient|split; assumption]]]
end.
Lemma call_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.call Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.call.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma callcode_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.CallCode →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.callcode Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.callcode.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma staticcall_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.staticcall Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.staticcall.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma delegatecall_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))) →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.DelegateCall →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hrevision Hvalue Hprimitive Hchild. unfold V.Executor.delegatecall.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Ltac checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild :=
lazymatch goal with
| |- context [@V.M.op_letdollar _ _ _ _ _ _] ⇒
eapply bounded_checked_bind_between with (pre := pre) (post := post);
[exact Hweaken | checked_pops | solve [eauto using map_nonincreasing,
pop_nonincreasing, pop2_nonincreasing, pop3_nonincreasing] | ];
let v := fresh "value" in let Hv := fresh "Hvalue" in intros v Hv;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta delta [fst snd] in Hv |- *;
repeat match goal with H : _ ∧ _ |- _ ⇒ destruct H end;
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild
| _ ⇒ apply call_opcode_checked_empty_recipient with (query := query);
[exact Hrevision|first [assumption|apply word_zero]|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
exact Hweaken|exact Hpre|exact Hpost|exact Hempty|
intros msg Hbounds [Hkind [Hsender Hrecipient]] Hcode;
apply Hchild; [exact Hbounds|unfold childCallFrom; rewrite Hkind; exact Hsender|exact Hcode]]
end.
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) codeAddr 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = kind ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient ∧
Evmc.Message.t.code_address msg = codeAddr ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static state)) ∧
match fst (@V.Executor.call_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hweaken Hpre Hpost Hempty Hchild.
destruct Hpre. destruct Hpost.
unfold V.Executor.call_opcode_impl.
eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
- apply (checked_safe_extend_input pre ); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
+ apply (checked_safe_extend_input pre); assumption.
+ apply extend_memory_to_nonincreasing.
+ intros outputGas HoutBound. eapply bounded_checked_bind_between with (pre := pre); [exact Hweaken| | |].
× apply checked_safe_fmap with (P := fun _ ⇒ True). expose_call_primitives. finish_call.
× apply map_nonincreasing, access_account_nonincreasing.
× intros accessGas [accessStatus [_ ->]] beforeRead Hbound Hprefix.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ ?action ?next beforeRead)) ∧ _) ∨ _ ⇒
change ((checkedMachine post (snd
(match action beforeRead with
| (inl d, middle) ⇒ next d middle
| (inr err, middle) ⇒ (inr err, middle)
end)) ∧
match fst (match action beforeRead with
| (inl d, middle) ⇒ next d middle
| (inr err, middle) ⇒ (inr err, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison)
end.
rewrite (access_delegation_empty codeAddr beforeRead
(Hempty _ (proj1 (proj2 (proj2 (proj1 Hprefix)))))).
cbn beta iota zeta delta [fst snd].
match goal with |- (checkedMachine _ (snd (?action beforeRead)) ∧ _) ∨ _ ⇒
assert (Hrest : boundedCheckedSafe post (fun _ ⇒ True) action)
end.
{ eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call; try assumption. }
{ apply account_exists_nonincreasing. }
intros targetAlive _. intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
change ((checkedMachine post (snd (next (MS.t.gas state) state)) ∧
match fst (next (MS.t.gas state) state) with inl _ ⇒ True | inr _ ⇒ True end) ∨
badMemoryInitComparison)
end.
cbn beta.
set (transfer := andb (Evmc.Message.CallKind.op_ltgt kind
Evmc.Message.CallKind.DelegateCall)
(U.op_ltgt value (@U.zero))) in ×.
set (memoryGas := @Gas.op_plus inputGas outputGas) in ×.
match goal with |- context [@Gas.call_gas_value transfer requested
(MS.t.gas state) memoryGas ?cost] ⇒ set (extra := cost) in × end.
assert (Hextra : (100 + (if transfer then @Gas.call_value else 0) ≤ extra)%N).
{ unfold extra. pose proof (@account_access_min accessStatus) as Haccess.
destruct transfer, targetAlive;
cbn [andb negb]; unfold Gas.op_plus, Gas.zero, Support.UintN.op_plus, Support.UintN.zero; lia. }
match goal with |- context [@V.M.op_letdollar _ _ _ _ (@V.spend _ _ ?amount) ?next] ⇒
set (nextCall := next); set (spentGas := amount)
end.
destruct (@checked_safe_spend Host_t F post UG spentGas state Hinitial)
as [[Hframe _]|Hfailure]; [|right; exact Hfailure].
change ((checkedMachine post (snd
(match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end)) ∧
match fst (match @V.spend Host_t F spentGas state with
| (inl value, middle) ⇒ nextCall value middle
| (inr error, middle) ⇒ (inr error, middle)
end) with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison).
destruct (@V.spend Host_t F spentGas state) as [[[]|error] charged] eqn:Hspent.
2: { left. split; [exact Hframe|exact I]. }
pose proof (spend_success_exact _ _ _ Hspent) as [Hafford Hcharged].
pose proof (@call_quote_total_decreases transfer requested
(MS.t.gas state) memoryGas extra Hextra Hafford) as HgasChild.
cbn zeta in HgasChild.
assert (Hforwarded : (Z.of_N
(@Gas.call_gas_value transfer requested (MS.t.gas state) memoryGas extra)
.(Gas.call_gas.callee_available_gas) < 2^63)%Z) by lia.
assert (Hnext : checkedSafe post (fun _ ⇒ True) (nextCall tt)).
{ unfold nextCall, V.Executor.check_write_permissions, V.M.when_, Monad.Make_Monad.when_.
expose_call_primitives. finish_call; try assumption. }
apply Hnext. exact Hframe. }
apply Hrest; [exact Hbound|].
eapply checked_machine_weaken; [exact Hweaken|exact Hprefix].
Qed.
Lemma call_opcode_checked_empty_recipient (pre post : Host_t → Prop)
query requested value sender recipient
inputStart inputSize outputStart outputSize static :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call ∧ Evmc.Message.t.sender msg = sender ∧
Evmc.Message.t.recipient msg = recipient) →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call_opcode_impl Host_t F E
Evmc.Message.CallKind.Call requested value sender recipient recipient
inputStart inputSize outputStart outputSize static state)) ∧
match fst (@V.Executor.call_opcode_impl Host_t F E
Evmc.Message.CallKind.Call requested value sender recipient recipient
inputStart inputSize outputStart outputSize static state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hvalue Hstart Hsize HoutStart HoutSize Hweaken Hpre Hpost Hempty Hchild.
destruct (String.string_dec recipient query) as [Heq|Hneq].
- subst recipient. apply call_opcode_checked_empty_code; try assumption.
intros msg Hbounds [Hkind [Hsender [Hrecipient [Hcode Hdelegated]]]].
apply Hchild; [exact Hbounds|repeat split; assumption|intros _; split; assumption].
- intros state Hgas Hinitial.
match goal with |- (checkedMachine _ (snd (?action state)) ∧ _) ∨ _ ⇒
assert (Hframe : boundedCheckedSafe post (fun _ ⇒ True) action)
end.
{ apply (call_opcode_checked_at_context post (UG := UG)); try assumption.
intros msg Hbounds [Hkind [Hsender Hrecipient]].
apply Hchild; [exact Hbounds|repeat split; assumption|].
intro Heq. exfalso. apply Hneq. congruence. }
apply Hframe; [exact Hgas|].
eapply checked_machine_weaken; [exact Hweaken|exact Hinitial].
Qed.
End EmptyCall.
Section Wrappers.
Context {Host_t : Set} {F : @V.FArgs Host_t} {E : @V.Executor.FArgs Host_t F}.
Context {UI32 : Basics.Unreachable OCamlInt32.t} {UG64 : Basics.Unreachable Uint64.t}
{UN : Basics.Unreachable Support.UintN.t} {UF : Basics.Unreachable U.t}
{UZ : Basics.Unreachable Numeric.Integer.t} {UA : Basics.Unreachable Chain.Ethereum.Address.t}
{UB : Basics.Unreachable Byte_string.Bytes.t} {UU : Basics.Unreachable unit}
{US : Basics.Unreachable string} {UL : Basics.Unreachable (list Byte_string.Bytes.t)}
{ULI : Basics.Unreachable (list int)} {UI : Basics.Unreachable int}
{UB32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}
{UMem : Basics.Unreachable (@Mem.t Host_t F → Support.UintN.t)}.
Context {UG : Basics.Unreachable Gas.t} {UDel : Basics.Unreachable Delegation.Address.t}
{Ucost : Basics.Unreachable (Support.UintN.t → Support.UintN.t)}
{UE : Basics.Unreachable (U.t → U.t → @Mem.t Host_t F → option (@Mem.t Host_t F))}.
Context (invariant : Host_t → Prop).
Context {UR : Basics.Unreachable U.Repr.t} {UC : Basics.Unreachable ascii}
{UP : Basics.Unreachable (int × int)}.
Ltac checked_pops :=
lazymatch goal with
| |- checkedSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒ apply checked_safe_fmap; checked_pops
| |- checkedSafe _ _ (@V.pop _ _) ⇒ apply checked_safe_pop
| |- checkedSafe _ _ (@V.pop2 _ _) ⇒ apply checked_safe_pop2
| |- checkedSafe _ _ (@V.pop3 _ _) ⇒ apply checked_safe_pop3
end.
Ltac checked_call_origin_wrapper Hrevision Hprimitive Hchild :=
lazymatch goal with
| |- boundedCheckedSafe _ _ (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply bounded_checked_bind_prefix;
[checked_pops | solve [eauto using map_nonincreasing, pop_nonincreasing,
pop2_nonincreasing, pop3_nonincreasing] | ];
let v := fresh "v" in let Hv := fresh "Hv" in intros v Hv;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta delta [fst snd] in Hv |- *;
repeat match goal with H : _ ∧ _ |- _ ⇒ destruct H end;
checked_call_origin_wrapper Hrevision Hprimitive Hchild
| _ ⇒ apply (call_opcode_checked_at_context invariant (UG := UG));
[exact Hrevision|first [assumption|apply word_zero|unfold wordRange in *; lia]|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
exact Hprimitive|intros msg Hbounds [Hkind [Hsender Hrecipient]];
apply Hchild; [exact Hbounds|exact Hkind|unfold childCallFrom; rewrite Hkind;
first [exact Hsender|exact Hrecipient|split; assumption]]]
end.
Lemma call_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.call Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.call.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma callcode_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.CallCode →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.callcode Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.callcode.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma staticcall_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.staticcall Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.staticcall.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma delegatecall_checked_from_self :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))) →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, @vmMessageBounds msg →
Evmc.Message.t.kind msg = Evmc.Message.CallKind.DelegateCall →
childCallFrom (@V.Executor.self Host_t F E) msg → ∀ host, invariant host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(invariant (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
boundedCheckedSafe invariant (fun _ ⇒ True) (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hrevision Hvalue Hprimitive Hchild. unfold V.Executor.delegatecall.
checked_call_origin_wrapper Hrevision Hprimitive Hchild.
Qed.
Ltac checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild :=
lazymatch goal with
| |- context [@V.M.op_letdollar _ _ _ _ _ _] ⇒
eapply bounded_checked_bind_between with (pre := pre) (post := post);
[exact Hweaken | checked_pops | solve [eauto using map_nonincreasing,
pop_nonincreasing, pop2_nonincreasing, pop3_nonincreasing] | ];
let v := fresh "value" in let Hv := fresh "Hvalue" in intros v Hv;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta delta [fst snd] in Hv |- *;
repeat match goal with H : _ ∧ _ |- _ ⇒ destruct H end;
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild
| _ ⇒ apply call_opcode_checked_empty_recipient with (query := query);
[exact Hrevision|first [assumption|apply word_zero]|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
unfold wordRange, U.to_z in *; lia|unfold wordRange, U.to_z in *; lia|
exact Hweaken|exact Hpre|exact Hpost|exact Hempty|
intros msg Hbounds [Hkind [Hsender Hrecipient]] Hcode;
apply Hchild; [exact Hbounds|unfold childCallFrom; rewrite Hkind; exact Hsender|exact Hcode]]
end.
CALL and STATICCALL may reach the protected recipient only with its own
empty code. The child-message bounds and machine invariants are retained,
so the recursive VM hypothesis can require actual representation bounds.
Lemma call_checked_empty_recipient (pre post : Host_t → Prop) query :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
childCallFrom (@V.Executor.self Host_t F E) msg →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call Host_t F E
state)) ∧
match fst (@V.Executor.call Host_t F E
state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.call.
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild.
Qed.
Lemma staticcall_checked_empty_recipient (pre post : Host_t → Prop) query :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
childCallFrom (@V.Executor.self Host_t F E) msg →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.staticcall Host_t F E
state)) ∧
match fst (@V.Executor.staticcall Host_t F E
state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.staticcall.
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild.
Qed.
End Wrappers.
Print Assumptions call_opcode_checked_empty_recipient.
Print Assumptions delegatecall_checked_from_self.
Print Assumptions call_checked_empty_recipient.
Print Assumptions staticcall_checked_empty_recipient.
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
childCallFrom (@V.Executor.self Host_t F E) msg →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.call Host_t F E
state)) ∧
match fst (@V.Executor.call Host_t F E
state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.call.
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild.
Qed.
Lemma staticcall_checked_empty_recipient (pre post : Host_t → Prop) query :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
(∀ h, pre h → post h) →
PrimitiveHostFrameAt (@V.Host Host_t F) pre (@V.Executor.self Host_t F E) →
PrimitiveHostFrameAt (@V.Host Host_t F) post (@V.Executor.self Host_t F E) →
(∀ h, pre h → (@V.Host Host_t F).(Evmc.HOST.copy_code) query 0
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, @vmMessageBounds msg →
childCallFrom (@V.Executor.self Host_t F E) msg →
(Evmc.Message.t.recipient msg = query →
Evmc.Message.t.code_address msg = query ∧ Evmc.Message.t.delegated msg = false) →
∀ host, post host →
let result := (@V.Host Host_t F).(Evmc.HOST.call) msg host in
(post (snd result) ∧ OCamlString.length (Evmc.Result.t.output_data (fst result)) < 2^256) ∨
badMemoryInitComparison) →
∀ state, Z.of_N (MS.t.gas state) < 2^63 → checkedMachine pre state →
(checkedMachine post (snd (@V.Executor.staticcall Host_t F E
state)) ∧
match fst (@V.Executor.staticcall Host_t F E
state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison.
Proof.
intros Hrevision Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.staticcall.
checked_call_protected_wrapper pre post query Hrevision Hweaken Hpre Hpost Hempty Hchild.
Qed.
End Wrappers.
Print Assumptions call_opcode_checked_empty_recipient.
Print Assumptions delegatecall_checked_from_self.
Print Assumptions call_checked_empty_recipient.
Print Assumptions staticcall_checked_empty_recipient.