Library QedkConcrete.vmcallchecked
Joint invariant at recursive CALL boundaries
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmchecked QedkConcrete.vmmachinewords
QedkConcrete.memorycomposition QedkConcrete.memorycopybounds QedkConcrete.vmsizes QedkConcrete.vmchildsizes
QedkConcrete.memorywords QedkConcrete.memorysizes QedkConcrete.wordrange QedkConcrete.vmcallframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCallHandlerProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmChildGasMerge
MonadExecutionSpecs.Termination.VmCallGas.
Require Import QedkConcrete.vmenvironmentwords QedkConcrete.vmhostframe QedkConcrete.vmboundedframe.
Require Import QedkConcrete.memorymodel.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmchecked QedkConcrete.vmmachinewords
QedkConcrete.memorycomposition QedkConcrete.memorycopybounds QedkConcrete.vmsizes QedkConcrete.vmchildsizes
QedkConcrete.memorywords QedkConcrete.memorysizes QedkConcrete.wordrange QedkConcrete.vmcallframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCallHandlerProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmChildGasMerge
MonadExecutionSpecs.Termination.VmCallGas.
Require Import QedkConcrete.vmenvironmentwords QedkConcrete.vmhostframe QedkConcrete.vmboundedframe.
Require Import QedkConcrete.memorymodel.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Input length fits an OCaml integer. Transaction validation and successful
CALL/CREATE memory extension establish this bound; native parsing cannot
then wrap its input-length counters.
Definition vmMessageBounds (msg : Evmc.Message.t) : Prop :=
0 ≤ Evmc.Message.t.gas msg < 2^63 ∧ wordRange (Evmc.Message.t.value msg) ∧
OCamlString.length (Evmc.Message.t.input_data msg) < 2^62 ∧
(∀ decoder : Basics.Unreachable Support.UintN.t,
Z.of_N (@Support.UintN.of_uint32 (Evmc.Message.t.memory_capacity msg)) < 2^32).
0 ≤ Evmc.Message.t.gas msg < 2^63 ∧ wordRange (Evmc.Message.t.value msg) ∧
OCamlString.length (Evmc.Message.t.input_data msg) < 2^62 ∧
(∀ decoder : Basics.Unreachable Support.UintN.t,
Z.of_N (@Support.UintN.of_uint32 (Evmc.Message.t.memory_capacity msg)) < 2^32).
CALL/CREATE encode a bounded capacity, so every decoder takes its normal
branch. This lets Host and VM share the invariant despite their distinct
generated fallback parameters.
Lemma encoded_capacity_all_decoders
{UI : Basics.Unreachable OCamlInt32.t} value :
Z.of_N value < 2^32 →
∀ decoder : Basics.Unreachable Support.UintN.t,
Z.of_N (@Support.UintN.of_uint32 (@Support.UintN.to_uint32 value)) < 2^32.
Proof. intros Hvalue decoder. rewrite uint32_roundtrip by exact Hvalue. exact Hvalue. Qed.
Ltac finish_call_extra :=
lazymatch goal with
| |- 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 "Unhandled CALL invariant case" g
end.
Ltac finish_call :=
lazymatch goal with
| |- checkedSafe _ _ (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply checked_safe_bind with (P := fun _ ⇒ True); [finish_call|];
let v := fresh "v" in intros v _; cbn beta iota zeta; finish_call
| |- checkedSafe _ _ (@V.M.op_coloneq _ _ _ MS.output_buffer _) ⇒
apply checked_safe_output_write; first [assumption|cbn; lia]
| |- checkedSafe _ _ (@V.M.update_field _ _ _ MS.memory _) ⇒
cbv beta iota zeta delta [V.Memory V.Memory.module V.Memory.Memory_signature.write_block_at];
apply checked_safe_write_block; apply truncated_output_length; assumption
| |- checkedSafe _ _ (@V.M.update_field _ _ _ _ _) ⇒
apply checked_safe_update_frame; let st := fresh "st" in let v := fresh "v" in
let Hi := fresh "Hinitial" in intros st v Hi; exact Hi
| |- checkedSafe _ _ (@V.M.op_exclamation _ _ _ _) ⇒
apply checked_safe_read; intros; exact I
| |- checkedSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒
apply checked_safe_fmap_ignore; finish_call
| |- checkedSafe _ _ (@V.M.when_ _ _ ?test _) ⇒
unfold V.M.when_, Monad.Make_Monad.when_; destruct test;
first [finish_call | apply checked_safe_return; exact I]
| |- checkedSafe _ _ (@V.M.HostAPI.lift _ _ _ _) ⇒
apply checked_safe_host; intros; left; split; [unfold preservesCallback in *; eauto|exact I]
| |- checkedSafe _ _ (@V.spend _ _ _) ⇒ apply checked_safe_spend
| |- checkedSafe _ _ (@V.increase_pc_and_continue _ _) ⇒ apply checked_safe_increase_pc
| |- checkedSafe _ _ (@V.M._return _ _ _ _) ⇒ apply checked_safe_return; exact I
| |- checkedSafe _ _ (@V.M.fail _ _ _ _) ⇒ apply checked_safe_fail
| |- checkedSafe _ _ (@V.push _ _ _) ⇒
apply checked_safe_push;
repeat match goal with |- wordRange (if ?test then _ else _) ⇒ destruct test end;
first [apply word_zero|apply word_one|apply vmenvironmentwords.address_word]
| |- checkedSafe _ _ (if ?test then _ else _) ⇒ destruct test; finish_call
| |- checkedSafe _ _ (match ?value with _ ⇒ _ end) ⇒ destruct value; cbn beta iota zeta; finish_call
| _ ⇒ finish_call_extra
end.
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_from_child_bounded
kind forwarded value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize :
BoundedMemory F →
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 → ∀ 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: 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_bounded H F UMem mem Hrevision (proj1 Hfits)) as Hbound;
destruct Hfits; lia
end.
Qed.
Lemma generic_call_checked_from_child
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 → ∀ 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; eapply generic_call_checked_from_child_bounded with (kind := kind) (forwarded := forwarded) (value := value) (sender := sender) (recipient := recipient) (codeAddr := codeAddr) (delegation := delegation) (static := static) (inputStart := inputStart) (inputSize := inputSize) (outputStart := outputStart) (outputSize := outputSize); eauto using eleven_bounded_memory. 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_from_child_bounded; try assumption
| |- 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_from_child_bounded
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
BoundedMemory F →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_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_bounded invariant); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input_bounded 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. all: try assumption. }
{ apply access_delegation_nonincreasing. }
intros delegation _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call. all: 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. all: try assumption. }
apply Hnext. exact Hframe.
Qed.
Lemma call_opcode_checked_from_child
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 →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static).
Proof. intros; eapply call_opcode_checked_from_child_bounded with (kind := kind) (requested := requested) (value := value) (sender := sender) (recipient := recipient) (codeAddr := codeAddr) (inputStart := inputStart) (inputSize := inputSize) (outputStart := outputStart) (outputSize := outputSize) (static := static); eauto using eleven_bounded_memory. Qed.
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_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_wrapper Hrevision Hprimitive Hchild
| _ ⇒ apply call_opcode_checked_from_child_bounded;
[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|exact Hchild]
end.
Lemma call_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma call_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply call_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma callcode_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma callcode_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply callcode_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma staticcall_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma staticcall_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply staticcall_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma delegatecall_checked_from_child_bounded :
BoundedMemory F →
wordRange (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))) →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma delegatecall_checked_from_child :
(@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))) →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply delegatecall_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
End Call.
Print Assumptions generic_call_checked_from_child.
Print Assumptions call_opcode_checked_from_child.
Print Assumptions call_checked_from_child.
Print Assumptions delegatecall_checked_from_child.
{UI : Basics.Unreachable OCamlInt32.t} value :
Z.of_N value < 2^32 →
∀ decoder : Basics.Unreachable Support.UintN.t,
Z.of_N (@Support.UintN.of_uint32 (@Support.UintN.to_uint32 value)) < 2^32.
Proof. intros Hvalue decoder. rewrite uint32_roundtrip by exact Hvalue. exact Hvalue. Qed.
Ltac finish_call_extra :=
lazymatch goal with
| |- 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 "Unhandled CALL invariant case" g
end.
Ltac finish_call :=
lazymatch goal with
| |- checkedSafe _ _ (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply checked_safe_bind with (P := fun _ ⇒ True); [finish_call|];
let v := fresh "v" in intros v _; cbn beta iota zeta; finish_call
| |- checkedSafe _ _ (@V.M.op_coloneq _ _ _ MS.output_buffer _) ⇒
apply checked_safe_output_write; first [assumption|cbn; lia]
| |- checkedSafe _ _ (@V.M.update_field _ _ _ MS.memory _) ⇒
cbv beta iota zeta delta [V.Memory V.Memory.module V.Memory.Memory_signature.write_block_at];
apply checked_safe_write_block; apply truncated_output_length; assumption
| |- checkedSafe _ _ (@V.M.update_field _ _ _ _ _) ⇒
apply checked_safe_update_frame; let st := fresh "st" in let v := fresh "v" in
let Hi := fresh "Hinitial" in intros st v Hi; exact Hi
| |- checkedSafe _ _ (@V.M.op_exclamation _ _ _ _) ⇒
apply checked_safe_read; intros; exact I
| |- checkedSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒
apply checked_safe_fmap_ignore; finish_call
| |- checkedSafe _ _ (@V.M.when_ _ _ ?test _) ⇒
unfold V.M.when_, Monad.Make_Monad.when_; destruct test;
first [finish_call | apply checked_safe_return; exact I]
| |- checkedSafe _ _ (@V.M.HostAPI.lift _ _ _ _) ⇒
apply checked_safe_host; intros; left; split; [unfold preservesCallback in *; eauto|exact I]
| |- checkedSafe _ _ (@V.spend _ _ _) ⇒ apply checked_safe_spend
| |- checkedSafe _ _ (@V.increase_pc_and_continue _ _) ⇒ apply checked_safe_increase_pc
| |- checkedSafe _ _ (@V.M._return _ _ _ _) ⇒ apply checked_safe_return; exact I
| |- checkedSafe _ _ (@V.M.fail _ _ _ _) ⇒ apply checked_safe_fail
| |- checkedSafe _ _ (@V.push _ _ _) ⇒
apply checked_safe_push;
repeat match goal with |- wordRange (if ?test then _ else _) ⇒ destruct test end;
first [apply word_zero|apply word_one|apply vmenvironmentwords.address_word]
| |- checkedSafe _ _ (if ?test then _ else _) ⇒ destruct test; finish_call
| |- checkedSafe _ _ (match ?value with _ ⇒ _ end) ⇒ destruct value; cbn beta iota zeta; finish_call
| _ ⇒ finish_call_extra
end.
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_from_child_bounded
kind forwarded value sender recipient codeAddr delegation static
inputStart inputSize outputStart outputSize :
BoundedMemory F →
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 → ∀ 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: 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_bounded H F UMem mem Hrevision (proj1 Hfits)) as Hbound;
destruct Hfits; lia
end.
Qed.
Lemma generic_call_checked_from_child
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 → ∀ 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; eapply generic_call_checked_from_child_bounded with (kind := kind) (forwarded := forwarded) (value := value) (sender := sender) (recipient := recipient) (codeAddr := codeAddr) (delegation := delegation) (static := static) (inputStart := inputStart) (inputSize := inputSize) (outputStart := outputStart) (outputSize := outputSize); eauto using eleven_bounded_memory. 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_from_child_bounded; try assumption
| |- 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_from_child_bounded
kind requested value sender recipient codeAddr
inputStart inputSize outputStart outputSize static :
BoundedMemory F →
wordRange value → 0 ≤ U.to_z inputStart → 0 ≤ U.to_z inputSize →
0 ≤ U.to_z outputStart → 0 ≤ U.to_z outputSize →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_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_bounded invariant); assumption.
- apply extend_memory_to_nonincreasing.
- intros inputGas Hinput. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input_bounded 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. all: try assumption. }
{ apply access_delegation_nonincreasing. }
intros delegation _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ expose_call_primitives. finish_call. all: 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. all: try assumption. }
apply Hnext. exact Hframe.
Qed.
Lemma call_opcode_checked_from_child
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 →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_opcode_impl Host_t F E
kind requested value sender recipient codeAddr inputStart inputSize outputStart outputSize static).
Proof. intros; eapply call_opcode_checked_from_child_bounded with (kind := kind) (requested := requested) (value := value) (sender := sender) (recipient := recipient) (codeAddr := codeAddr) (inputStart := inputStart) (inputSize := inputSize) (outputStart := outputStart) (outputSize := outputSize) (static := static); eauto using eleven_bounded_memory. Qed.
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_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_wrapper Hrevision Hprimitive Hchild
| _ ⇒ apply call_opcode_checked_from_child_bounded;
[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|exact Hchild]
end.
Lemma call_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma call_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply call_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma callcode_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma callcode_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply callcode_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma staticcall_checked_from_child_bounded :
BoundedMemory F →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma staticcall_checked_from_child :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply staticcall_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
Lemma delegatecall_checked_from_child_bounded :
BoundedMemory F →
wordRange (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))) →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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_wrapper Hrevision Hprimitive Hchild.
Qed.
Lemma delegatecall_checked_from_child :
(@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))) →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, @vmMessageBounds 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; eapply delegatecall_checked_from_child_bounded; eauto using eleven_bounded_memory. Qed.
End Call.
Print Assumptions generic_call_checked_from_child.
Print Assumptions call_opcode_checked_from_child.
Print Assumptions call_checked_from_child.
Print Assumptions delegatecall_checked_from_child.