Library QedkConcrete.vmcreateprotected
Checked CREATE messages retain their actual sender
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmchecked QedkConcrete.memorymodel QedkConcrete.memorysizes QedkConcrete.vmcallchecked
QedkConcrete.vmmachinewords QedkConcrete.vmmemorywords QedkConcrete.vmsizes
QedkConcrete.vmchildsizes QedkConcrete.memorywords QedkConcrete.wordrange
QedkConcrete.vmhostframe QedkConcrete.vmboundedframe QedkConcrete.vmcallframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmCallGas.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Creation.
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} {UG : Basics.Unreachable Gas.t}
{UDel : Basics.Unreachable Delegation.Address.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)}
{UI : Basics.Unreachable int} {UC : Basics.Unreachable ascii}
{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_create_checked_at_context_bounded kind salt value inputStart inputSize :
BoundedMemory F →
wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
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 = @V.Executor.self Host_t F E) →
∀ 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.generic_create_impl Host_t F E
kind salt value inputStart inputSize).
Proof.
intros Hrevision Hvalue Hinput Hprimitive Hchild. destruct Hprimitive.
unfold V.Executor.generic_create_impl.
eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
- finish_call.
- apply stipend_guard_nonincreasing.
- intros [] _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
+ unfold V.Executor.check_write_permissions. finish_call.
+ apply check_write_permissions_nonincreasing.
+ intros [] _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
× unfold V.M.HostAPI.get_balance, V.M.HostAPI.Base. finish_call.
× apply get_balance_nonincreasing.
× intros selfBalance _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ unfold V.Executor.access_delegation, V.M.HostAPI.copy_code,
V.M.HostAPI.access_account, V.M.HostAPI.Base. finish_call. }
{ first [apply create_delegation_guard_nonincreasing |
destruct (@V.Params Host_t F).(Vm.Make_Params_signature.revision);
try apply create_delegation_guard_nonincreasing;
match goal with |- gas_nonincreasing (@V.M.when_ _ _ ?condition _) ⇒
unfold V.M.when_; destruct condition end;
[apply fail_nonincreasing | apply return_nonincreasing]]. }
intros [] _.
match goal with |- boundedCheckedSafe _ _ (if ?test then _ else _) ⇒ destruct test end.
{ apply bounded_checked_from_unbounded. finish_call. }
intros state Hgas Hinitial.
pose proof (@create_forwarded_le (MS.t.gas state)) as Hforwarded.
change (@Support.UintN.minus_1_64th (MS.t.gas state) ≤ MS.t.gas state)%N in Hforwarded.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
set (continuation := next);
change ((checkedMachine invariant (snd
(continuation (@Support.UintN.minus_1_64th (MS.t.gas state)) state)) ∧
match fst (continuation (@Support.UintN.minus_1_64th (MS.t.gas state)) state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison)
end.
assert (Hnext : checkedSafe invariant (fun _ ⇒ True)
(continuation (@Support.UintN.minus_1_64th (MS.t.gas state)))).
{ unfold continuation. eapply checked_safe_bind with (P := fun _ ⇒ True).
- finish_call.
- intros [] _. 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 st Hst. right. exact Hfailure. }
cbn beta iota zeta.
eapply checked_safe_bind with
(P := fun result ⇒ OCamlString.length (Evmc.Result.t.output_data result) < 2^256).
+ apply checked_safe_call, Hchild.
2: { split; reflexivity. }
unfold vmMessageBounds; cbn [Evmc.Message.t.gas Evmc.Message.t.value
Evmc.Message.t.input_data Evmc.Message.t.memory_capacity].
split; [unfold Gas.to_uint64, UintN.to_uint64, UintN.to_z;
rewrite int64_unsigned_small_identity by lia; lia|].
split; [exact Hvalue|]. split; [lia|].
cbv beta iota zeta delta
[V.Memory V.Memory.module V.Memory.Memory_signature.available_memory_size].
apply (encoded_capacity_all_decoders (UI := Opaque.legacy_witness 0%Z)).
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.
+ 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. }
apply Hnext. exact Hinitial.
Unshelve. all: assumption.
Qed.
Lemma generic_create_checked_at_context kind salt value inputStart inputSize :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
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 = @V.Executor.self Host_t F E) →
∀ 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.generic_create_impl Host_t F E
kind salt value inputStart inputSize).
Proof. intros; eapply generic_create_checked_at_context_bounded; eauto using eleven_bounded_memory. Qed.
Context {UR : Basics.Unreachable U.Repr.t} {UP : Basics.Unreachable (int × int)}
{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))}.
Lemma create_checked_from_self_bounded :
BoundedMemory F →
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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.create.
eapply bounded_checked_bind_prefix; [apply checked_safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue [Hstart Hsize]]. cbn [fst snd] in Hvalue, Hstart, Hsize.
eapply bounded_checked_bind_prefix.
- apply (checked_safe_extend_input_bounded invariant);
[exact Hrevision|exact (proj1 Hstart)|exact (proj1 Hsize)].
- apply extend_memory_to_nonincreasing.
- intros memoryGas Hinput. eapply bounded_checked_bind_prefix.
+ apply checked_safe_spend; assumption.
+ apply spend_nonincreasing.
+ intros [] _. eapply bounded_checked_bind_suffix.
× apply generic_create_checked_at_context_bounded; try assumption.
intros msg Hbounds [Hkind Hsender]. apply Hchild; [exact Hbounds| |].
-- first [left; exact Hkind|right; exact Hkind].
-- unfold childCallFrom. rewrite Hkind. exact Hsender.
× intros [] _. apply checked_safe_increase_pc.
Unshelve. all: assumption.
Qed.
Lemma create_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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create Host_t F E).
Proof. intros; eapply create_checked_from_self_bounded; eauto using eleven_bounded_memory. Qed.
Lemma create2_checked_from_self_bounded :
BoundedMemory F →
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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create2 Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.create2.
eapply bounded_checked_bind_prefix; [apply checked_safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue [Hstart Hsize]]. cbn [fst snd] in Hvalue, Hstart, Hsize.
eapply bounded_checked_bind_prefix.
- apply checked_safe_fmap, checked_safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input_bounded invariant);
[exact Hrevision|exact (proj1 Hstart)|exact (proj1 Hsize)].
+ apply extend_memory_to_nonincreasing.
+ intros memoryGas Hinput. eapply bounded_checked_bind_prefix.
× apply checked_safe_spend; assumption.
× apply spend_nonincreasing.
× intros [] _. eapply bounded_checked_bind_suffix.
{ apply generic_create_checked_at_context_bounded; try assumption.
intros msg Hbounds [Hkind Hsender]. apply Hchild; [exact Hbounds| |].
-- first [left; exact Hkind|right; exact Hkind].
-- unfold childCallFrom. rewrite Hkind. exact Hsender. }
intros [] _. apply checked_safe_increase_pc.
Unshelve. all: assumption.
Qed.
Lemma create2_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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create2 Host_t F E).
Proof. intros; eapply create2_checked_from_self_bounded; eauto using eleven_bounded_memory. Qed.
End Creation.
Print Assumptions generic_create_checked_at_context.
Print Assumptions create_checked_from_self.
Print Assumptions create2_checked_from_self.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Vm QedkConcrete.vmchecked QedkConcrete.memorymodel QedkConcrete.memorysizes QedkConcrete.vmcallchecked
QedkConcrete.vmmachinewords QedkConcrete.vmmemorywords QedkConcrete.vmsizes
QedkConcrete.vmchildsizes QedkConcrete.memorywords QedkConcrete.wordrange
QedkConcrete.vmhostframe QedkConcrete.vmboundedframe QedkConcrete.vmcallframe.
Require Import MonadExecutionSpecs.Termination.VmUnsignedGas
MonadExecutionSpecs.Termination.VmOpcodeProgress
MonadExecutionSpecs.Termination.VmCreateHandlerProgress
MonadExecutionSpecs.Termination.VmCallGas.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Creation.
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} {UG : Basics.Unreachable Gas.t}
{UDel : Basics.Unreachable Delegation.Address.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)}
{UI : Basics.Unreachable int} {UC : Basics.Unreachable ascii}
{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_create_checked_at_context_bounded kind salt value inputStart inputSize :
BoundedMemory F →
wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
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 = @V.Executor.self Host_t F E) →
∀ 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.generic_create_impl Host_t F E
kind salt value inputStart inputSize).
Proof.
intros Hrevision Hvalue Hinput Hprimitive Hchild. destruct Hprimitive.
unfold V.Executor.generic_create_impl.
eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
- finish_call.
- apply stipend_guard_nonincreasing.
- intros [] _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
+ unfold V.Executor.check_write_permissions. finish_call.
+ apply check_write_permissions_nonincreasing.
+ intros [] _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
× unfold V.M.HostAPI.get_balance, V.M.HostAPI.Base. finish_call.
× apply get_balance_nonincreasing.
× intros selfBalance _. eapply bounded_checked_bind_prefix with (P := fun _ ⇒ True).
{ unfold V.Executor.access_delegation, V.M.HostAPI.copy_code,
V.M.HostAPI.access_account, V.M.HostAPI.Base. finish_call. }
{ first [apply create_delegation_guard_nonincreasing |
destruct (@V.Params Host_t F).(Vm.Make_Params_signature.revision);
try apply create_delegation_guard_nonincreasing;
match goal with |- gas_nonincreasing (@V.M.when_ _ _ ?condition _) ⇒
unfold V.M.when_; destruct condition end;
[apply fail_nonincreasing | apply return_nonincreasing]]. }
intros [] _.
match goal with |- boundedCheckedSafe _ _ (if ?test then _ else _) ⇒ destruct test end.
{ apply bounded_checked_from_unbounded. finish_call. }
intros state Hgas Hinitial.
pose proof (@create_forwarded_le (MS.t.gas state)) as Hforwarded.
change (@Support.UintN.minus_1_64th (MS.t.gas state) ≤ MS.t.gas state)%N in Hforwarded.
match goal with |- (checkedMachine _ (snd
(@V.M.op_letdollar _ _ _ _ _ ?next state)) ∧ _) ∨ _ ⇒
set (continuation := next);
change ((checkedMachine invariant (snd
(continuation (@Support.UintN.minus_1_64th (MS.t.gas state)) state)) ∧
match fst (continuation (@Support.UintN.minus_1_64th (MS.t.gas state)) state)
with inl _ ⇒ True | inr _ ⇒ True end) ∨ badMemoryInitComparison)
end.
assert (Hnext : checkedSafe invariant (fun _ ⇒ True)
(continuation (@Support.UintN.minus_1_64th (MS.t.gas state)))).
{ unfold continuation. eapply checked_safe_bind with (P := fun _ ⇒ True).
- finish_call.
- intros [] _. 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 st Hst. right. exact Hfailure. }
cbn beta iota zeta.
eapply checked_safe_bind with
(P := fun result ⇒ OCamlString.length (Evmc.Result.t.output_data result) < 2^256).
+ apply checked_safe_call, Hchild.
2: { split; reflexivity. }
unfold vmMessageBounds; cbn [Evmc.Message.t.gas Evmc.Message.t.value
Evmc.Message.t.input_data Evmc.Message.t.memory_capacity].
split; [unfold Gas.to_uint64, UintN.to_uint64, UintN.to_z;
rewrite int64_unsigned_small_identity by lia; lia|].
split; [exact Hvalue|]. split; [lia|].
cbv beta iota zeta delta
[V.Memory V.Memory.module V.Memory.Memory_signature.available_memory_size].
apply (encoded_capacity_all_decoders (UI := Opaque.legacy_witness 0%Z)).
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.
+ 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. }
apply Hnext. exact Hinitial.
Unshelve. all: assumption.
Qed.
Lemma generic_create_checked_at_context kind salt value inputStart inputSize :
(@V.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
wordRange value → 0 ≤ U.to_z inputSize < 2^32 →
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 = @V.Executor.self Host_t F E) →
∀ 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.generic_create_impl Host_t F E
kind salt value inputStart inputSize).
Proof. intros; eapply generic_create_checked_at_context_bounded; eauto using eleven_bounded_memory. Qed.
Context {UR : Basics.Unreachable U.Repr.t} {UP : Basics.Unreachable (int × int)}
{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))}.
Lemma create_checked_from_self_bounded :
BoundedMemory F →
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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.create.
eapply bounded_checked_bind_prefix; [apply checked_safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue [Hstart Hsize]]. cbn [fst snd] in Hvalue, Hstart, Hsize.
eapply bounded_checked_bind_prefix.
- apply (checked_safe_extend_input_bounded invariant);
[exact Hrevision|exact (proj1 Hstart)|exact (proj1 Hsize)].
- apply extend_memory_to_nonincreasing.
- intros memoryGas Hinput. eapply bounded_checked_bind_prefix.
+ apply checked_safe_spend; assumption.
+ apply spend_nonincreasing.
+ intros [] _. eapply bounded_checked_bind_suffix.
× apply generic_create_checked_at_context_bounded; try assumption.
intros msg Hbounds [Hkind Hsender]. apply Hchild; [exact Hbounds| |].
-- first [left; exact Hkind|right; exact Hkind].
-- unfold childCallFrom. rewrite Hkind. exact Hsender.
× intros [] _. apply checked_safe_increase_pc.
Unshelve. all: assumption.
Qed.
Lemma create_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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create Host_t F E).
Proof. intros; eapply create_checked_from_self_bounded; eauto using eleven_bounded_memory. Qed.
Lemma create2_checked_from_self_bounded :
BoundedMemory F →
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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create2 Host_t F E).
Proof.
intros Hrevision Hprimitive Hchild. unfold V.Executor.create2.
eapply bounded_checked_bind_prefix; [apply checked_safe_pop3|apply pop3_nonincreasing|].
intros [[value start] size] [Hvalue [Hstart Hsize]]. cbn [fst snd] in Hvalue, Hstart, Hsize.
eapply bounded_checked_bind_prefix.
- apply checked_safe_fmap, checked_safe_pop.
- apply map_nonincreasing, pop_nonincreasing.
- intros salt _. eapply bounded_checked_bind_prefix.
+ apply (checked_safe_extend_input_bounded invariant);
[exact Hrevision|exact (proj1 Hstart)|exact (proj1 Hsize)].
+ apply extend_memory_to_nonincreasing.
+ intros memoryGas Hinput. eapply bounded_checked_bind_prefix.
× apply checked_safe_spend; assumption.
× apply spend_nonincreasing.
× intros [] _. eapply bounded_checked_bind_suffix.
{ apply generic_create_checked_at_context_bounded; try assumption.
intros msg Hbounds [Hkind Hsender]. apply Hchild; [exact Hbounds| |].
-- first [left; exact Hkind|right; exact Hkind].
-- unfold childCallFrom. rewrite Hkind. exact Hsender. }
intros [] _. apply checked_safe_increase_pc.
Unshelve. all: assumption.
Qed.
Lemma create2_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.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
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.create2 Host_t F E).
Proof. intros; eapply create2_checked_from_self_bounded; eauto using eleven_bounded_memory. Qed.
End Creation.
Print Assumptions generic_create_checked_at_context.
Print Assumptions create_checked_from_self.
Print Assumptions create2_checked_from_self.