Library QedkConcrete.hostcreatechecked
CREATE's side of the recursive supply proof
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Host QedkConcrete.hostframe QedkConcrete.hostcomposition
QedkConcrete.hostsupply QedkConcrete.hostaccountformat QedkConcrete.hostchecked
QedkConcrete.vmsupplywords QedkConcrete.vmcallchecked QedkConcrete.wordrange
QedkConcrete.hoststoragewords QedkConcrete.vmhostframe QedkConcrete.worldaccounts.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Creation.
Context {F : H.FArgs}.
Context {UN : Basics.Unreachable Support.UintN.t} {U64 : Basics.Unreachable Numeric.U64.t}
{UF : Basics.Unreachable U.t} {UG : Basics.Unreachable Gas.t}
{UA : Basics.Unreachable Addr.t} {UB : Basics.Unreachable Byte_string.Bytes.t}
{UU : Basics.Unreachable unit} {US : Basics.Unreachable string}
{UI : Basics.Unreachable int} {UC : Basics.Unreachable ascii}
{U64i : Basics.Unreachable int64}
{U32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}.
Context (limit : Z).
Local Abbreviation invariant := (hostSupplyContext F.(H.ChainParams) limit).
Ltac creation_frame :=
apply host_checked_frame, host_supply_context_frame;
[solve_supply_frame|solve_format|solve_context_frame].
Ltac solve_creation_checked :=
lazymatch goal with
| |- hostChecked _ _ (S.M.(Monad.State.State_result.op_letdollar)
(S.M.(Monad.State.State_result.op_exclamation)
(Lens.Infix.op_pipeminusminus (@H.account F None _) A.TLens.code)) _) ⇒
eapply host_checked_bind with (P := fun code ⇒ OCamlString.length code < 2^62);
[apply read_account_code_checked|];
let code := fresh "code" in let Hcode := fresh "Hcode" in
intros code Hcode; cbn beta iota zeta; solve_creation_checked
| |- hostChecked _ _ (S.M.(Monad.State.State_result.op_letdollar) ?action ?next) ⇒
let nextType := type of next in
lazymatch nextType with
| Evmc.Result.t → _ ⇒
eapply host_checked_bind with (P := resultOutputBound);
[solve_creation_checked|];
let result := fresh "result" in let Houtput := fresh "Houtput" in
intros result Houtput; cbn beta iota zeta; solve_creation_checked
| _ ⇒
eapply host_checked_bind with (P := fun _ ⇒ True);
[creation_frame|];
let value := fresh "value" in intros value _;
cbn beta iota zeta; solve_creation_checked
end
| |- hostChecked _ _ (S.M.(Monad.State.State_result._return) _) ⇒
apply host_checked_return;
unfold resultOutputBound in *;
cbn [Evmc.Result.failure Evmc.Result.t.output_data
Evmc.Result.t.with_create_address Evmc.Result.t.with_gas_left
Evmc.Result.t.with_output_data];
first [assumption|lia|change (0 < 2^256); lia|
match goal with |- ?g ⇒ fail 10 "Unbounded creation result" g end]
| |- hostChecked _ _ (if ?test then _ else _) ⇒
let Htest := fresh "Htest" in destruct test eqn:Htest; solve_creation_checked
| |- hostChecked _ _ (match (if ?test then _ else _) with _ ⇒ _ end) ⇒
let Htest := fresh "Htest" in destruct test eqn:Htest;
cbn beta iota zeta; solve_creation_checked
| |- hostChecked _ _ (match ?status with Evmc.Result.StatusCode.Success ⇒ _ | _ ⇒ _ end) ⇒
destruct status; solve_creation_checked
| Hvm : ∀ nested code, _ → _ → hostChecked _ _ (_ nested code)
|- hostChecked _ _ (_ ?nested ?code) ⇒
apply Hvm;
[unfold vmMessageBounds;
split; [assumption|]; split; [assumption|];
split; [change (0 < 2^62); lia|assumption]
|lia]
| |- ?g ⇒ fail 10 "Unhandled checked creation" g
end.
Lemma process_create_preserves_checked msg :
(∀ nested code, @vmMessageBounds nested → OCamlString.length code < 2^256 →
hostChecked invariant resultOutputBound ((@H.Vm F).(Evmc.Vm.SIG.execute) nested code)) →
@vmMessageBounds msg →
hostChecked invariant resultOutputBound
(@H.process_create F msg).
Proof.
intros Hvm [Hgas [Hvalue [Hdata Hcapacity]]].
assert (Hnonnegative : 0 ≤ U.to_z (Evmc.Message.t.value msg)).
{ unfold wordRange in Hvalue. exact (proj1 Hvalue). }
unfold H.process_create, H.M.
eapply host_checked_bind with (P := fun _ ⇒ True).
- apply host_checked_frame, host_supply_context_frame.
+ apply creation_address_preserves_supply.
+ apply creation_address_preserves_format.
+ apply creation_address_read_only.
- intros addr _. solve_creation_checked.
Qed.
End Creation.
Print Assumptions process_create_preserves_checked.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Host QedkConcrete.hostframe QedkConcrete.hostcomposition
QedkConcrete.hostsupply QedkConcrete.hostaccountformat QedkConcrete.hostchecked
QedkConcrete.vmsupplywords QedkConcrete.vmcallchecked QedkConcrete.wordrange
QedkConcrete.hoststoragewords QedkConcrete.vmhostframe QedkConcrete.worldaccounts.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Creation.
Context {F : H.FArgs}.
Context {UN : Basics.Unreachable Support.UintN.t} {U64 : Basics.Unreachable Numeric.U64.t}
{UF : Basics.Unreachable U.t} {UG : Basics.Unreachable Gas.t}
{UA : Basics.Unreachable Addr.t} {UB : Basics.Unreachable Byte_string.Bytes.t}
{UU : Basics.Unreachable unit} {US : Basics.Unreachable string}
{UI : Basics.Unreachable int} {UC : Basics.Unreachable ascii}
{U64i : Basics.Unreachable int64}
{U32 : Basics.Unreachable Byte_string.B32.(Byte_string.Fixed.Fixed_result.t)}.
Context (limit : Z).
Local Abbreviation invariant := (hostSupplyContext F.(H.ChainParams) limit).
Ltac creation_frame :=
apply host_checked_frame, host_supply_context_frame;
[solve_supply_frame|solve_format|solve_context_frame].
Ltac solve_creation_checked :=
lazymatch goal with
| |- hostChecked _ _ (S.M.(Monad.State.State_result.op_letdollar)
(S.M.(Monad.State.State_result.op_exclamation)
(Lens.Infix.op_pipeminusminus (@H.account F None _) A.TLens.code)) _) ⇒
eapply host_checked_bind with (P := fun code ⇒ OCamlString.length code < 2^62);
[apply read_account_code_checked|];
let code := fresh "code" in let Hcode := fresh "Hcode" in
intros code Hcode; cbn beta iota zeta; solve_creation_checked
| |- hostChecked _ _ (S.M.(Monad.State.State_result.op_letdollar) ?action ?next) ⇒
let nextType := type of next in
lazymatch nextType with
| Evmc.Result.t → _ ⇒
eapply host_checked_bind with (P := resultOutputBound);
[solve_creation_checked|];
let result := fresh "result" in let Houtput := fresh "Houtput" in
intros result Houtput; cbn beta iota zeta; solve_creation_checked
| _ ⇒
eapply host_checked_bind with (P := fun _ ⇒ True);
[creation_frame|];
let value := fresh "value" in intros value _;
cbn beta iota zeta; solve_creation_checked
end
| |- hostChecked _ _ (S.M.(Monad.State.State_result._return) _) ⇒
apply host_checked_return;
unfold resultOutputBound in *;
cbn [Evmc.Result.failure Evmc.Result.t.output_data
Evmc.Result.t.with_create_address Evmc.Result.t.with_gas_left
Evmc.Result.t.with_output_data];
first [assumption|lia|change (0 < 2^256); lia|
match goal with |- ?g ⇒ fail 10 "Unbounded creation result" g end]
| |- hostChecked _ _ (if ?test then _ else _) ⇒
let Htest := fresh "Htest" in destruct test eqn:Htest; solve_creation_checked
| |- hostChecked _ _ (match (if ?test then _ else _) with _ ⇒ _ end) ⇒
let Htest := fresh "Htest" in destruct test eqn:Htest;
cbn beta iota zeta; solve_creation_checked
| |- hostChecked _ _ (match ?status with Evmc.Result.StatusCode.Success ⇒ _ | _ ⇒ _ end) ⇒
destruct status; solve_creation_checked
| Hvm : ∀ nested code, _ → _ → hostChecked _ _ (_ nested code)
|- hostChecked _ _ (_ ?nested ?code) ⇒
apply Hvm;
[unfold vmMessageBounds;
split; [assumption|]; split; [assumption|];
split; [change (0 < 2^62); lia|assumption]
|lia]
| |- ?g ⇒ fail 10 "Unhandled checked creation" g
end.
Lemma process_create_preserves_checked msg :
(∀ nested code, @vmMessageBounds nested → OCamlString.length code < 2^256 →
hostChecked invariant resultOutputBound ((@H.Vm F).(Evmc.Vm.SIG.execute) nested code)) →
@vmMessageBounds msg →
hostChecked invariant resultOutputBound
(@H.process_create F msg).
Proof.
intros Hvm [Hgas [Hvalue [Hdata Hcapacity]]].
assert (Hnonnegative : 0 ≤ U.to_z (Evmc.Message.t.value msg)).
{ unfold wordRange in Hvalue. exact (proj1 Hvalue). }
unfold H.process_create, H.M.
eapply host_checked_bind with (P := fun _ ⇒ True).
- apply host_checked_frame, host_supply_context_frame.
+ apply creation_address_preserves_supply.
+ apply creation_address_preserves_format.
+ apply creation_address_read_only.
- intros addr _. solve_creation_checked.
Qed.
End Creation.
Print Assumptions process_create_preserves_checked.