Library SetcodeConcrete.executionsupply
Supply safety of the recursive SETCODE executor
From Stdlib Require Import ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.recursiveassembly QedkConcrete.hostframe
QedkConcrete.hostchecked QedkConcrete.hostcallchecked QedkConcrete.assemblychecked
QedkConcrete.precompilesframe QedkConcrete.vmsupplywords QedkConcrete.vmcallchecked
QedkConcrete.hashwords.
Require Import SetcodeConcrete.vmsupplyentry SetcodeConcrete.assembly.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Lemma setcode_reserve_precompile_table {F : P.FArgs} prices :
P.Revision.(Precompiles.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode prices → @reservePrecompileTable F.
Proof.
intro Hrevision. unfold reservePrecompileTable, P.monad_precompiles.
rewrite Hrevision. reflexivity.
Qed.
Module E := Execution.Make.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Context (cold warm access write reserve : N) (limit : Z).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Context (Hhash : keccak256OutputSize) (Hnative : @nativeOutputBounds args).
Local Abbreviation invariant := (hostSupplyContext args.(Host.Instantiate.ChainParams) limit).
Lemma setcode_native_table vm :
@reservePrecompileTable (@H.Precompiles_fargs
(H.Build_FArgs args.(Host.Instantiate.ChainParams) vm)).
Proof. eapply setcode_reserve_precompile_table. exact Hrevision. Qed.
Lemma vm_constructor_supply vm :
@checkedVm args limit vm → @checkedVm args limit (VmF (HostF vm)).
Proof.
intros Hvm msg code Hmsg Hcode initial Hinitial.
cbn -[Vm.Make.execute hostSupplyContext resultOutputBound].
eapply (@execute_supply_context args vm _ limit cold warm access write reserve
msg code initial); try eassumption; try reflexivity.
- eapply concrete_setcode_gas_progress; [exact Hrevision|exact Hcold|exact Hwarm].
- intros child Hchild before Hbefore.
exact (@host_constructor_checked_table args limit vm
(setcode_native_table vm) Hnative Hvm child Hchild before Hbefore).
Qed.
Theorem execution_vm_supply :
@checkedVm args limit (@Evmc.Instantiate.Vm S.t (@recursiveArgs args)).
Proof.
exact (proj1 (@recursive_assembly_checked_table args limit
setcode_native_table Hnative vm_constructor_supply)).
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Theorem execution_call_from_sender_supply tx msg initial :
vmMessageBounds msg → invariant initial →
let result := @E.Host.call_from_eoa F tx msg initial in
invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
intros Hmsg Hinitial.
apply host_checked_sound; [|exact Hinitial].
unfold E.Host.call_from_eoa.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call_from_eoa H.call_from_eoa].
eapply call_impl_preserves_checked_table.
- apply setcode_native_table.
- exact execution_vm_supply.
- intros nested addr action Hnested Hselected before _.
exact (Hnative _ nested addr action Hnested Hselected before).
- exact Hmsg.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.recursiveassembly QedkConcrete.hostframe
QedkConcrete.hostchecked QedkConcrete.hostcallchecked QedkConcrete.assemblychecked
QedkConcrete.precompilesframe QedkConcrete.vmsupplywords QedkConcrete.vmcallchecked
QedkConcrete.hashwords.
Require Import SetcodeConcrete.vmsupplyentry SetcodeConcrete.assembly.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Lemma setcode_reserve_precompile_table {F : P.FArgs} prices :
P.Revision.(Precompiles.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode prices → @reservePrecompileTable F.
Proof.
intro Hrevision. unfold reservePrecompileTable, P.monad_precompiles.
rewrite Hrevision. reflexivity.
Qed.
Module E := Execution.Make.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Context (cold warm access write reserve : N) (limit : Z).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Context (Hhash : keccak256OutputSize) (Hnative : @nativeOutputBounds args).
Local Abbreviation invariant := (hostSupplyContext args.(Host.Instantiate.ChainParams) limit).
Lemma setcode_native_table vm :
@reservePrecompileTable (@H.Precompiles_fargs
(H.Build_FArgs args.(Host.Instantiate.ChainParams) vm)).
Proof. eapply setcode_reserve_precompile_table. exact Hrevision. Qed.
Lemma vm_constructor_supply vm :
@checkedVm args limit vm → @checkedVm args limit (VmF (HostF vm)).
Proof.
intros Hvm msg code Hmsg Hcode initial Hinitial.
cbn -[Vm.Make.execute hostSupplyContext resultOutputBound].
eapply (@execute_supply_context args vm _ limit cold warm access write reserve
msg code initial); try eassumption; try reflexivity.
- eapply concrete_setcode_gas_progress; [exact Hrevision|exact Hcold|exact Hwarm].
- intros child Hchild before Hbefore.
exact (@host_constructor_checked_table args limit vm
(setcode_native_table vm) Hnative Hvm child Hchild before Hbefore).
Qed.
Theorem execution_vm_supply :
@checkedVm args limit (@Evmc.Instantiate.Vm S.t (@recursiveArgs args)).
Proof.
exact (proj1 (@recursive_assembly_checked_table args limit
setcode_native_table Hnative vm_constructor_supply)).
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Theorem execution_call_from_sender_supply tx msg initial :
vmMessageBounds msg → invariant initial →
let result := @E.Host.call_from_eoa F tx msg initial in
invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
intros Hmsg Hinitial.
apply host_checked_sound; [|exact Hinitial].
unfold E.Host.call_from_eoa.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call_from_eoa H.call_from_eoa].
eapply call_impl_preserves_checked_table.
- apply setcode_native_table.
- exact execution_vm_supply.
- intros nested addr action Hnested Hselected before _.
exact (Hnative _ nested addr action Hnested Hselected before).
- exact Hmsg.
Qed.
The system-message entry has no outer transaction reserve check, but
has the same supply and representation invariant.
Theorem execution_host_call_supply msg initial :
vmMessageBounds msg → invariant initial →
let result := @E.Host.call F msg initial in
invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
intros Hmsg Hinitial. apply host_checked_sound; [|exact Hinitial].
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
eapply call_preserves_checked_table.
- apply setcode_native_table.
- exact execution_vm_supply.
- intros nested addr action Hnested Hselected before _.
exact (Hnative _ nested addr action Hnested Hselected before).
- exact Hmsg.
Qed.
End Execution.
Print Assumptions execution_vm_supply.
Print Assumptions execution_call_from_sender_supply.
Print Assumptions execution_host_call_supply.
vmMessageBounds msg → invariant initial →
let result := @E.Host.call F msg initial in
invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
intros Hmsg Hinitial. apply host_checked_sound; [|exact Hinitial].
unfold E.Host.call.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call].
eapply call_preserves_checked_table.
- apply setcode_native_table.
- exact execution_vm_supply.
- intros nested addr action Hnested Hselected before _.
exact (Hnative _ nested addr action Hnested Hselected before).
- exact Hmsg.
Qed.
End Execution.
Print Assumptions execution_vm_supply.
Print Assumptions execution_call_from_sender_supply.
Print Assumptions execution_host_call_supply.