Library QedkConcrete.vmcallwords
Nonnegative values at recursive VM calls
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmmachinewords QedkConcrete.vmcallframe
QedkConcrete.vmcreateframe QedkConcrete.vmbytewords QedkConcrete.vmhostframe
QedkConcrete.vmboundedframe QedkConcrete.wordrange QedkConcrete.vminvariant.
Require Import MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress.
Set Default Goal Selector "!".
Section Opcodes.
Context {Host_t : Set} {F : @MonadVM.Vm.Make.FArgs Host_t}.
Context `{U0 : RocqOfOCaml.Basics.Unreachable Z.t}.
Context `{U1 :
RocqOfOCaml.Basics.Unreachable (RocqOfOCaml.OCamlSeq.t int)}.
Context `{U2 : RocqOfOCaml.Basics.Unreachable RocqOfOCaml.OCamlInt32.t}.
Context `{U3 : RocqOfOCaml.Basics.Unreachable MonadVM.Uint64.t}.
Context `{U4 :
RocqOfOCaml.Basics.Unreachable MonadVM.Support.UintN.t}.
Context `{U5 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.U256.Repr.t}.
Context `{U7 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.Integer.t}.
Context `{U8 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.I256.t}.
Context `{U9 : RocqOfOCaml.Basics.Unreachable MonadVM.Gas.t}.
Context `{U10 :
RocqOfOCaml.Basics.Unreachable MonadVM.Delegation.Address.t}.
Context `{U11 :
RocqOfOCaml.Basics.Unreachable MonadVM.Chain.Ethereum.Address.t}.
Context `{U12 :
RocqOfOCaml.Basics.Unreachable MonadVM.Byte_string.Bytes.t}.
Context `{U13 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.M.Option.t Host_t F MonadVM.Numeric.U256.t)}.
Context `{U15 : RocqOfOCaml.Basics.Unreachable unit}.
Context `{U16 : RocqOfOCaml.Basics.Unreachable string}.
Context `{U17 :
RocqOfOCaml.Basics.Unreachable (option MonadVM.Numeric.U256.t)}.
Context `{U18 : RocqOfOCaml.Basics.Unreachable (option string)}.
Context `{U19 :
RocqOfOCaml.Basics.Unreachable
(list MonadVM.Byte_string.Bytes.t)}.
Context `{U20 : RocqOfOCaml.Basics.Unreachable (list int)}.
Context `{U21 : RocqOfOCaml.Basics.Unreachable int}.
Context `{U22 : RocqOfOCaml.Basics.Unreachable ascii}.
Context `{U23 : RocqOfOCaml.Basics.Unreachable (int × int)}.
Context `{U24 :
RocqOfOCaml.Basics.Unreachable
(Z.t → MonadVM.Numeric.U256.t)}.
Context `{U25 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Support.UintN.t → MonadVM.Support.UintN.t)}.
Context `{U26 :
RocqOfOCaml.Basics.Unreachable
(unit → RocqOfOCaml.OCamlSeq.node int)}.
Context `{U27 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.opcode_impl Host_t F)}.
Context `{U28 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Numeric.IntegerBase.(MonadVM.Numeric.Make.Make_result.t)}.
Context `{U31 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.t)}.
Context `{U32 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Numeric.U256.t → MonadVM.Numeric.U256.t →
@MonadVM.Vm.Make.Memory.t Host_t F →
@MonadVM.Vm.Make.M.Option.t Host_t F
(@MonadVM.Vm.Make.Memory.t Host_t F))}.
Context `{U33 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.Memory.t Host_t F →
MonadVM.Support.UintN.t)}.
Let State := @MonadVM.Vm.Make.MachineState.t Host_t F.
Context (invariant : Host_t → Prop).
Definition preservesBoundedWordsHost {A : Set} (action : @V.M.t Host_t F A) :=
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z →
machineWords invariant state → invariant (MS.t.host (snd (action state))).
Lemma bounded_host_from_words {A : Set} (action : @V.M.t Host_t F A) :
preservesBoundedHost invariant action → preservesBoundedWordsHost action.
Proof.
intros Haction state Hgas [_ [_ [Hhost _]]]. apply Haction; assumption.
Qed.
Lemma words_frame_bind_prefix {A B : Set} (P : A → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
machineSafe invariant P action → gas_nonincreasing action →
(∀ value, P value → preservesBoundedWordsHost (next value)) →
preservesBoundedWordsHost (@V.M.op_letdollar Host_t F A B action next).
Proof.
intros Haction Hgas Hnext state Hbound Hwords.
pose proof (Haction state Hwords) as Hprefix.
change (invariant (MS.t.host (snd
(match action state with
| (inl value, middle) ⇒ next value middle
| (inr error, middle) ⇒ (inr error, middle)
end)))).
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.
- exact (proj1 (proj2 (proj2 (proj1 Hprefix)))).
Qed.
Section Environment.
Context {E : @V.Executor.FArgs Host_t F}.
Ltac safe_pops :=
lazymatch goal with
| |- machineSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒ apply safe_fmap; safe_pops
| |- machineSafe _ _ (@V.pop _ _) ⇒ apply safe_pop
| |- machineSafe _ _ (@V.pop2 _ _) ⇒ apply safe_pop2
| |- machineSafe _ _ (@V.pop3 _ _) ⇒ apply safe_pop3
end.
Ltac child_value_nonnegative :=
first [assumption
| match goal with H : wordRange ?v |- (0 ≤ ?v)%Z ⇒ exact (proj1 H) end
| change (0 ≤ 0)%Z; lia].
Ltac word_call_wrapper Hprimitive Hchild :=
lazymatch goal with
| |- preservesBoundedWordsHost (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply words_frame_bind_prefix;
[safe_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;
word_call_wrapper Hprimitive Hchild
| _ ⇒ apply bounded_host_from_words, call_opcode_preserves_at_value;
[exact Hprimitive|intros msg Hgas Hsent; apply Hchild;
[exact Hgas|rewrite Hsent; child_value_nonnegative]]
end.
Lemma call_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.call Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.call. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma callcode_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.callcode Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.callcode. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma staticcall_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.staticcall Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.staticcall. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma delegatecall_preserves_with_nonnegative_child_values :
(0 ≤ U.to_z (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))))%Z →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hentry Hprimitive Hchild. unfold V.Executor.delegatecall. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma create_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
- unfold V.Executor.extend_memory_to. solve_host_invariant.
- apply extend_memory_to_nonincreasing.
- intro memoryGas. apply bounded_frame_bind_prefix.
+ solve_host_invariant.
+ apply spend_nonincreasing.
+ intros []. apply bounded_frame_bind_suffix.
× apply generic_create_preserves_at_value; [exact Hprimitive|].
intros msg Hgas Hsent. apply Hchild; [exact Hgas|].
rewrite Hsent. exact (proj1 Hvalue).
× intros []. solve_host_invariant.
Qed.
Lemma create2_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create2 Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create2.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
eapply words_frame_bind_prefix.
- apply safe_fmap, safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
+ unfold V.Executor.extend_memory_to. solve_host_invariant.
+ apply extend_memory_to_nonincreasing.
+ intro memoryGas. apply bounded_frame_bind_prefix.
× solve_host_invariant.
× apply spend_nonincreasing.
× intros []. apply bounded_frame_bind_suffix.
{ apply generic_create_preserves_at_value; [exact Hprimitive|].
intros msg Hgas Hsent. apply Hchild; [exact Hgas|].
rewrite Hsent. exact (proj1 Hvalue). }
intros []. solve_host_invariant.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmmachinewords QedkConcrete.vmcallframe
QedkConcrete.vmcreateframe QedkConcrete.vmbytewords QedkConcrete.vmhostframe
QedkConcrete.vmboundedframe QedkConcrete.wordrange QedkConcrete.vminvariant.
Require Import MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress.
Set Default Goal Selector "!".
Section Opcodes.
Context {Host_t : Set} {F : @MonadVM.Vm.Make.FArgs Host_t}.
Context `{U0 : RocqOfOCaml.Basics.Unreachable Z.t}.
Context `{U1 :
RocqOfOCaml.Basics.Unreachable (RocqOfOCaml.OCamlSeq.t int)}.
Context `{U2 : RocqOfOCaml.Basics.Unreachable RocqOfOCaml.OCamlInt32.t}.
Context `{U3 : RocqOfOCaml.Basics.Unreachable MonadVM.Uint64.t}.
Context `{U4 :
RocqOfOCaml.Basics.Unreachable MonadVM.Support.UintN.t}.
Context `{U5 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.U256.Repr.t}.
Context `{U7 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.Integer.t}.
Context `{U8 :
RocqOfOCaml.Basics.Unreachable MonadVM.Numeric.I256.t}.
Context `{U9 : RocqOfOCaml.Basics.Unreachable MonadVM.Gas.t}.
Context `{U10 :
RocqOfOCaml.Basics.Unreachable MonadVM.Delegation.Address.t}.
Context `{U11 :
RocqOfOCaml.Basics.Unreachable MonadVM.Chain.Ethereum.Address.t}.
Context `{U12 :
RocqOfOCaml.Basics.Unreachable MonadVM.Byte_string.Bytes.t}.
Context `{U13 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.M.Option.t Host_t F MonadVM.Numeric.U256.t)}.
Context `{U15 : RocqOfOCaml.Basics.Unreachable unit}.
Context `{U16 : RocqOfOCaml.Basics.Unreachable string}.
Context `{U17 :
RocqOfOCaml.Basics.Unreachable (option MonadVM.Numeric.U256.t)}.
Context `{U18 : RocqOfOCaml.Basics.Unreachable (option string)}.
Context `{U19 :
RocqOfOCaml.Basics.Unreachable
(list MonadVM.Byte_string.Bytes.t)}.
Context `{U20 : RocqOfOCaml.Basics.Unreachable (list int)}.
Context `{U21 : RocqOfOCaml.Basics.Unreachable int}.
Context `{U22 : RocqOfOCaml.Basics.Unreachable ascii}.
Context `{U23 : RocqOfOCaml.Basics.Unreachable (int × int)}.
Context `{U24 :
RocqOfOCaml.Basics.Unreachable
(Z.t → MonadVM.Numeric.U256.t)}.
Context `{U25 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Support.UintN.t → MonadVM.Support.UintN.t)}.
Context `{U26 :
RocqOfOCaml.Basics.Unreachable
(unit → RocqOfOCaml.OCamlSeq.node int)}.
Context `{U27 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.opcode_impl Host_t F)}.
Context `{U28 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Numeric.IntegerBase.(MonadVM.Numeric.Make.Make_result.t)}.
Context `{U31 :
RocqOfOCaml.Basics.Unreachable
MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.t)}.
Context `{U32 :
RocqOfOCaml.Basics.Unreachable
(MonadVM.Numeric.U256.t → MonadVM.Numeric.U256.t →
@MonadVM.Vm.Make.Memory.t Host_t F →
@MonadVM.Vm.Make.M.Option.t Host_t F
(@MonadVM.Vm.Make.Memory.t Host_t F))}.
Context `{U33 :
RocqOfOCaml.Basics.Unreachable
(@MonadVM.Vm.Make.Memory.t Host_t F →
MonadVM.Support.UintN.t)}.
Let State := @MonadVM.Vm.Make.MachineState.t Host_t F.
Context (invariant : Host_t → Prop).
Definition preservesBoundedWordsHost {A : Set} (action : @V.M.t Host_t F A) :=
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z →
machineWords invariant state → invariant (MS.t.host (snd (action state))).
Lemma bounded_host_from_words {A : Set} (action : @V.M.t Host_t F A) :
preservesBoundedHost invariant action → preservesBoundedWordsHost action.
Proof.
intros Haction state Hgas [_ [_ [Hhost _]]]. apply Haction; assumption.
Qed.
Lemma words_frame_bind_prefix {A B : Set} (P : A → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
machineSafe invariant P action → gas_nonincreasing action →
(∀ value, P value → preservesBoundedWordsHost (next value)) →
preservesBoundedWordsHost (@V.M.op_letdollar Host_t F A B action next).
Proof.
intros Haction Hgas Hnext state Hbound Hwords.
pose proof (Haction state Hwords) as Hprefix.
change (invariant (MS.t.host (snd
(match action state with
| (inl value, middle) ⇒ next value middle
| (inr error, middle) ⇒ (inr error, middle)
end)))).
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.
- exact (proj1 (proj2 (proj2 (proj1 Hprefix)))).
Qed.
Section Environment.
Context {E : @V.Executor.FArgs Host_t F}.
Ltac safe_pops :=
lazymatch goal with
| |- machineSafe _ _ (@V.M.op_ltdollargt _ _ _ _ _ _) ⇒ apply safe_fmap; safe_pops
| |- machineSafe _ _ (@V.pop _ _) ⇒ apply safe_pop
| |- machineSafe _ _ (@V.pop2 _ _) ⇒ apply safe_pop2
| |- machineSafe _ _ (@V.pop3 _ _) ⇒ apply safe_pop3
end.
Ltac child_value_nonnegative :=
first [assumption
| match goal with H : wordRange ?v |- (0 ≤ ?v)%Z ⇒ exact (proj1 H) end
| change (0 ≤ 0)%Z; lia].
Ltac word_call_wrapper Hprimitive Hchild :=
lazymatch goal with
| |- preservesBoundedWordsHost (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply words_frame_bind_prefix;
[safe_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;
word_call_wrapper Hprimitive Hchild
| _ ⇒ apply bounded_host_from_words, call_opcode_preserves_at_value;
[exact Hprimitive|intros msg Hgas Hsent; apply Hchild;
[exact Hgas|rewrite Hsent; child_value_nonnegative]]
end.
Lemma call_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.call Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.call. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma callcode_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.callcode Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.callcode. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma staticcall_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.staticcall Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.staticcall. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma delegatecall_preserves_with_nonnegative_child_values :
(0 ≤ U.to_z (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))))%Z →
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hentry Hprimitive Hchild. unfold V.Executor.delegatecall. word_call_wrapper Hprimitive Hchild.
Qed.
Lemma create_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
- unfold V.Executor.extend_memory_to. solve_host_invariant.
- apply extend_memory_to_nonincreasing.
- intro memoryGas. apply bounded_frame_bind_prefix.
+ solve_host_invariant.
+ apply spend_nonincreasing.
+ intros []. apply bounded_frame_bind_suffix.
× apply generic_create_preserves_at_value; [exact Hprimitive|].
intros msg Hgas Hsent. apply Hchild; [exact Hgas|].
rewrite Hsent. exact (proj1 Hvalue).
× intros []. solve_host_invariant.
Qed.
Lemma create2_preserves_with_nonnegative_child_values :
PrimitiveHostFrame (@V.Host Host_t F) invariant →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create2 Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create2.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
eapply words_frame_bind_prefix.
- apply safe_fmap, safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
+ unfold V.Executor.extend_memory_to. solve_host_invariant.
+ apply extend_memory_to_nonincreasing.
+ intro memoryGas. apply bounded_frame_bind_prefix.
× solve_host_invariant.
× apply spend_nonincreasing.
× intros []. apply bounded_frame_bind_suffix.
{ apply generic_create_preserves_at_value; [exact Hprimitive|].
intros msg Hgas Hsent. apply Hchild; [exact Hgas|].
rewrite Hsent. exact (proj1 Hvalue). }
intros []. solve_host_invariant.
Qed.
The nondebit induction needs both facts simultaneously: the transfer is
nonnegative, and it originates at this execution account. Word bounds
alone do not identify whose balance the child can spend.
Ltac word_call_origin_wrapper Hprimitive Hchild :=
lazymatch goal with
| |- preservesBoundedWordsHost (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply words_frame_bind_prefix;
[safe_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;
word_call_origin_wrapper Hprimitive Hchild
| _ ⇒ apply bounded_host_from_words, call_opcode_preserves_at_context;
[exact Hprimitive|intros msg Hgas Hsent [Hkind [Hsender Hrecipient]]; apply Hchild;
[exact Hgas|rewrite Hsent; child_value_nonnegative|
unfold childCallFrom; rewrite Hkind;
first [exact Hsender|exact Hrecipient|split; assumption]]]
end.
Lemma call_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.call Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.call. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma callcode_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.callcode Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.callcode. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma staticcall_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.staticcall Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.staticcall. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma delegatecall_preserves_words_from_self :
(0 ≤ U.to_z (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))))%Z →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hentry Hprimitive Hchild. unfold V.Executor.delegatecall. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma create_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
- unfold V.Executor.extend_memory_to. solve_host_invariant.
- apply extend_memory_to_nonincreasing.
- intro memoryGas. apply bounded_frame_bind_prefix.
+ solve_host_invariant.
+ apply spend_nonincreasing.
+ intros []. apply bounded_frame_bind_suffix.
× apply generic_create_preserves_at_context; [exact Hprimitive|].
intros msg Hgas Hsent [Hkind Hsender]. apply Hchild.
-- exact Hgas.
-- rewrite Hsent. exact (proj1 Hvalue).
-- unfold childCallFrom; rewrite Hkind; exact Hsender.
× intros []. solve_host_invariant.
Qed.
Lemma create2_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create2 Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create2.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
eapply words_frame_bind_prefix.
- apply safe_fmap, safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
+ unfold V.Executor.extend_memory_to. solve_host_invariant.
+ apply extend_memory_to_nonincreasing.
+ intro memoryGas. apply bounded_frame_bind_prefix.
× solve_host_invariant.
× apply spend_nonincreasing.
× intros []. apply bounded_frame_bind_suffix.
{ apply generic_create_preserves_at_context; [exact Hprimitive|].
intros msg Hgas Hsent [Hkind Hsender]. apply Hchild.
- exact Hgas.
- rewrite Hsent. exact (proj1 Hvalue).
- unfold childCallFrom; rewrite Hkind; exact Hsender. }
intros []. solve_host_invariant.
Qed.
Lemma words_frame_bind_between {A B : Set} (pre post : Host_t → Prop) (P : A → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
(∀ h, pre h → post h) →
machineSafe pre P action → gas_nonincreasing action →
(∀ value, P value → ∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z →
machineWords pre state → post (MS.t.host (snd (next value state)))) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.M.op_letdollar Host_t F A B action next state))).
Proof.
intros Hweaken Haction Hgas Hnext state Hbound Hwords.
pose proof (Haction state Hwords) as Hprefix.
change (post (MS.t.host (snd
(match action state with
| (inl value, middle) ⇒ next value middle
| (inr error, middle) ⇒ (inr error, middle)
end)))).
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.
- apply Hweaken. exact (proj1 (proj2 (proj2 (proj1 Hprefix)))).
Qed.
Ltac word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild :=
lazymatch goal with
| |- context [@V.M.op_letdollar _ _ _ _ _ _] ⇒
eapply words_frame_bind_between with (pre := pre) (post := post);
[exact Hweaken | safe_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;
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild
| _ ⇒ intros state Hgas Hwords;
apply call_opcode_protects_empty_recipient with (pre := pre) (post := post) (query := query);
[exact Hweaken|exact Hpre|exact Hpost|exact Hempty|
intros msg Hbound Hsent [Hkind [Hsender Hrecipient]] Hcode;
apply Hchild;
[exact Hbound|rewrite Hsent; child_value_nonnegative|
unfold childCallFrom; rewrite Hkind; exact Hsender|exact Hcode]
|exact Hgas|exact (proj1 (proj2 (proj2 Hwords)))]
end.
lazymatch goal with
| |- preservesBoundedWordsHost (@V.M.op_letdollar _ _ _ _ _ _) ⇒
eapply words_frame_bind_prefix;
[safe_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;
word_call_origin_wrapper Hprimitive Hchild
| _ ⇒ apply bounded_host_from_words, call_opcode_preserves_at_context;
[exact Hprimitive|intros msg Hgas Hsent [Hkind [Hsender Hrecipient]]; apply Hchild;
[exact Hgas|rewrite Hsent; child_value_nonnegative|
unfold childCallFrom; rewrite Hkind;
first [exact Hsender|exact Hrecipient|split; assumption]]]
end.
Lemma call_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.call Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.call. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma callcode_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.callcode Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.callcode. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma staticcall_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.staticcall Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.staticcall. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma delegatecall_preserves_words_from_self :
(0 ≤ U.to_z (V.ExecutionEnvironment.t.value
((@V.Executor.C Host_t F E).(V.Executor_C_signature.execution_environment))))%Z →
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.delegatecall Host_t F E).
Proof.
intros Hentry Hprimitive Hchild. unfold V.Executor.delegatecall. word_call_origin_wrapper Hprimitive Hchild.
Qed.
Lemma create_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
- unfold V.Executor.extend_memory_to. solve_host_invariant.
- apply extend_memory_to_nonincreasing.
- intro memoryGas. apply bounded_frame_bind_prefix.
+ solve_host_invariant.
+ apply spend_nonincreasing.
+ intros []. apply bounded_frame_bind_suffix.
× apply generic_create_preserves_at_context; [exact Hprimitive|].
intros msg Hgas Hsent [Hkind Hsender]. apply Hchild.
-- exact Hgas.
-- rewrite Hsent. exact (proj1 Hvalue).
-- unfold childCallFrom; rewrite Hkind; exact Hsender.
× intros []. solve_host_invariant.
Qed.
Lemma create2_preserves_words_from_self :
PrimitiveHostFrameAt (@V.Host Host_t F) invariant (@V.Executor.self Host_t F E) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
childCallFrom (@V.Executor.self Host_t F E) msg →
preservesCallback invariant ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
preservesBoundedWordsHost (@V.Executor.create2 Host_t F E).
Proof.
intros Hprimitive Hchild. unfold V.Executor.create2.
eapply words_frame_bind_prefix; [apply safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue _]. cbn [fst] in Hvalue.
eapply words_frame_bind_prefix.
- apply safe_fmap, safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. apply bounded_host_from_words.
apply bounded_frame_bind_prefix.
+ unfold V.Executor.extend_memory_to. solve_host_invariant.
+ apply extend_memory_to_nonincreasing.
+ intro memoryGas. apply bounded_frame_bind_prefix.
× solve_host_invariant.
× apply spend_nonincreasing.
× intros []. apply bounded_frame_bind_suffix.
{ apply generic_create_preserves_at_context; [exact Hprimitive|].
intros msg Hgas Hsent [Hkind Hsender]. apply Hchild.
- exact Hgas.
- rewrite Hsent. exact (proj1 Hvalue).
- unfold childCallFrom; rewrite Hkind; exact Hsender. }
intros []. solve_host_invariant.
Qed.
Lemma words_frame_bind_between {A B : Set} (pre post : Host_t → Prop) (P : A → Prop)
(action : @V.M.t Host_t F A) (next : A → @V.M.t Host_t F B) :
(∀ h, pre h → post h) →
machineSafe pre P action → gas_nonincreasing action →
(∀ value, P value → ∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z →
machineWords pre state → post (MS.t.host (snd (next value state)))) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.M.op_letdollar Host_t F A B action next state))).
Proof.
intros Hweaken Haction Hgas Hnext state Hbound Hwords.
pose proof (Haction state Hwords) as Hprefix.
change (post (MS.t.host (snd
(match action state with
| (inl value, middle) ⇒ next value middle
| (inr error, middle) ⇒ (inr error, middle)
end)))).
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.
- apply Hweaken. exact (proj1 (proj2 (proj2 (proj1 Hprefix)))).
Qed.
Ltac word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild :=
lazymatch goal with
| |- context [@V.M.op_letdollar _ _ _ _ _ _] ⇒
eapply words_frame_bind_between with (pre := pre) (post := post);
[exact Hweaken | safe_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;
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild
| _ ⇒ intros state Hgas Hwords;
apply call_opcode_protects_empty_recipient with (pre := pre) (post := post) (query := query);
[exact Hweaken|exact Hpre|exact Hpost|exact Hempty|
intros msg Hbound Hsent [Hkind [Hsender Hrecipient]] Hcode;
apply Hchild;
[exact Hbound|rewrite Hsent; child_value_nonnegative|
unfold childCallFrom; rewrite Hkind; exact Hsender|exact Hcode]
|exact Hgas|exact (proj1 (proj2 (proj2 Hwords)))]
end.
The word-checked CALL variants preserve the empty-recipient restriction
as well as the sender and nonnegative value, through the actual stack
pops, memory expansion, delegation lookup and gas forwarding.
Lemma call_preserves_empty_recipient (pre post : Host_t → Prop) query :
(∀ 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%Z
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
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) →
preservesCallback post ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.Executor.call Host_t F E
state))).
Proof.
intros Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.call.
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild.
Qed.
Lemma staticcall_preserves_empty_recipient (pre post : Host_t → Prop) query :
(∀ 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%Z
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
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) →
preservesCallback post ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.Executor.staticcall Host_t F E
state))).
Proof.
intros Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.staticcall.
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild.
Qed.
End Environment.
End Opcodes.
Print Assumptions call_preserves_with_nonnegative_child_values.
Print Assumptions create2_preserves_with_nonnegative_child_values.
Print Assumptions call_preserves_words_from_self.
Print Assumptions create2_preserves_words_from_self.
Print Assumptions call_preserves_empty_recipient.
Print Assumptions staticcall_preserves_empty_recipient.
(∀ 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%Z
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
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) →
preservesCallback post ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.Executor.call Host_t F E
state))).
Proof.
intros Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.call.
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild.
Qed.
Lemma staticcall_preserves_empty_recipient (pre post : Host_t → Prop) query :
(∀ 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%Z
(@Delegation.eoa_delegated_code_length) h = (Byte_string.Bytes.empty, h)) →
(∀ msg, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
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) →
preservesCallback post ((@V.Host Host_t F).(Evmc.HOST.call) msg)) →
∀ state, (Z.of_N (MS.t.gas state) < 2^63)%Z → machineWords pre state →
post (MS.t.host (snd (@V.Executor.staticcall Host_t F E
state))).
Proof.
intros Hweaken Hpre Hpost Hempty Hchild. unfold V.Executor.staticcall.
word_call_protected_wrapper pre post query Hweaken Hpre Hpost Hempty Hchild.
Qed.
End Environment.
End Opcodes.
Print Assumptions call_preserves_with_nonnegative_child_values.
Print Assumptions create2_preserves_with_nonnegative_child_values.
Print Assumptions call_preserves_words_from_self.
Print Assumptions create2_preserves_words_from_self.
Print Assumptions call_preserves_empty_recipient.
Print Assumptions staticcall_preserves_empty_recipient.