Library QedkConcrete.hostcallframe
Context frame through the concrete Host call paths
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.hostsupply QedkConcrete.supply QedkConcrete.worldaccounts.
Require Import MonadVM.Host QedkConcrete.hostframe QedkConcrete.hostcomposition
QedkConcrete.precompilesframe QedkConcrete.hostaccountformat QedkConcrete.vmhostframe.
Set Default Goal Selector "!".
Section Calls.
Context `{_fargs : H.FArgs}.
Local Abbreviation processCall := (@H.process_call _fargs).
Local Abbreviation callImpl := (@H.call_impl _fargs).
Local Abbreviation hostCall := (@H.call _fargs).
Local Abbreviation callFromEoa := (@H.call_from_eoa _fargs).
Lemma process_call_preserves_context from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
preservesContext (processCall from_tx msg).
Proof.
intros Hrevision Hvm. unfold H.process_call, H.M. cbn zeta.
apply context_mbind.
- destruct (H.should_transfer msg); [apply transfer_preserves_context|apply context_return].
- intros transfer_ok. destruct transfer_ok; [|apply context_return].
apply context_mbind.
+ apply context_mbind; [apply context_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_context_frame.
+ intros [addr code].
match goal with |- preservesContext (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_context (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_context from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesContext (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas s.
pose proof (process_call_preserves_context from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas)) as Hcall.
pose proof (@process_create_preserves_context _fargs
msg Hvm Hgas) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : transactionContext (snd run) = transactionContext s) by
(etransitivity; [first [apply Hcall|apply Hcreate]|reflexivity]);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try reflexivity; try exact Hcore.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [reflexivity|exact Hcore].
Qed.
Lemma call_preserves_context msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesContext (hostCall msg).
Proof.
intros Hrevision Hvm Hgas. unfold H.call, H.M.
apply context_mbind.
- match goal with |- preservesContext (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_context_frame.
+ apply context_return.
- intros noOverflow. destruct noOverflow; [|apply context_return].
apply call_impl_preserves_context; assumption.
Qed.
Lemma call_from_eoa_preserves_context tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesContext (callFromEoa tx msg).
Proof. apply call_impl_preserves_context. Qed.
Lemma process_call_preserves_supply from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesSupply (processCall from_tx msg).
Proof.
intros Hrevision Hvm Hvalue. unfold H.process_call, H.M. cbn zeta.
apply supply_mbind.
- destruct (H.should_transfer msg); [apply supply_transfer; exact Hvalue|apply supply_return].
- intros transfer_ok. destruct transfer_ok; [|apply supply_return].
apply supply_mbind.
+ apply supply_mbind; [apply supply_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_supply_frame.
+ intros [addr code].
match goal with |- preservesSupply (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_supply (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_supply from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesSupply (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas Hvalue s Hinv.
pose proof (process_call_preserves_supply from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas Hvalue) Hvalue) as Hcall.
pose proof (@process_create_preserves_supply _fargs
msg Hvm Hgas Hvalue) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : balanceInvariant (S.t.world_state (snd run)) ∧
(totalBalance (S.t.world_state (snd run)) ≤ totalBalance (S.t.world_state s))%Z) by
(lazymatch run with ?f ?st ⇒
first [exact (Hcall st Hinv)|exact (Hcreate st Hinv)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try exact Hcore; try (split; [exact Hinv|apply Z.le_refl]).
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [split; [exact Hinv|apply Z.le_refl]|exact Hcore].
Qed.
Lemma call_preserves_supply msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z → preservesSupply (hostCall msg).
Proof.
intros Hrevision Hvm Hgas Hvalue. unfold H.call, H.M.
apply supply_mbind.
- match goal with |- preservesSupply (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_supply_frame.
+ apply supply_return.
- intros noOverflow. destruct noOverflow; [|apply supply_return].
apply call_impl_preserves_supply; assumption.
Qed.
Lemma call_from_eoa_preserves_supply tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z → preservesSupply (callFromEoa tx msg).
Proof. apply call_impl_preserves_supply. Qed.
Lemma process_call_preserves_format from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
preservesCallback hostFormat (processCall from_tx msg).
Proof.
intros Hrevision Hvm. unfold H.process_call, H.M. cbn zeta.
apply format_bind.
- destruct (H.should_transfer msg); [intro; apply transfer_preserves_format|apply format_return].
- intros transfer_ok. destruct transfer_ok; [|apply format_return].
apply format_bind.
+ apply format_bind; [apply format_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_format.
+ intros [addr code].
match goal with |- preservesCallback hostFormat (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_format (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_format from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesCallback hostFormat (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas s Hformat.
pose proof (process_call_preserves_format from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas)) as Hcall.
pose proof (@process_create_preserves_format _fargs
msg Hvm Hgas) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : hostFormat (snd run)) by
(lazymatch run with ?f ?st ⇒
first [exact (Hcall st Hformat)|exact (Hcreate st Hformat)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try exact Hcore; try exact Hformat.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [exact Hformat|exact Hcore].
Qed.
Lemma call_preserves_format msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesCallback hostFormat (hostCall msg).
Proof.
intros Hrevision Hvm Hgas. unfold H.call, H.M.
apply format_bind.
- match goal with |- preservesCallback hostFormat (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_format.
+ apply format_return.
- intros noOverflow. destruct noOverflow; [|apply format_return].
apply call_impl_preserves_format; assumption.
Qed.
Lemma call_from_eoa_preserves_format tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesCallback hostFormat (callFromEoa tx msg).
Proof. apply call_impl_preserves_format. Qed.
End Calls.
Print Assumptions call_preserves_context.
Print Assumptions call_from_eoa_preserves_context.
Print Assumptions call_from_eoa_preserves_supply.
Print Assumptions call_from_eoa_preserves_format.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.hostsupply QedkConcrete.supply QedkConcrete.worldaccounts.
Require Import MonadVM.Host QedkConcrete.hostframe QedkConcrete.hostcomposition
QedkConcrete.precompilesframe QedkConcrete.hostaccountformat QedkConcrete.vmhostframe.
Set Default Goal Selector "!".
Section Calls.
Context `{_fargs : H.FArgs}.
Local Abbreviation processCall := (@H.process_call _fargs).
Local Abbreviation callImpl := (@H.call_impl _fargs).
Local Abbreviation hostCall := (@H.call _fargs).
Local Abbreviation callFromEoa := (@H.call_from_eoa _fargs).
Lemma process_call_preserves_context from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
preservesContext (processCall from_tx msg).
Proof.
intros Hrevision Hvm. unfold H.process_call, H.M. cbn zeta.
apply context_mbind.
- destruct (H.should_transfer msg); [apply transfer_preserves_context|apply context_return].
- intros transfer_ok. destruct transfer_ok; [|apply context_return].
apply context_mbind.
+ apply context_mbind; [apply context_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_context_frame.
+ intros [addr code].
match goal with |- preservesContext (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_context (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_context from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesContext (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas s.
pose proof (process_call_preserves_context from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas)) as Hcall.
pose proof (@process_create_preserves_context _fargs
msg Hvm Hgas) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : transactionContext (snd run) = transactionContext s) by
(etransitivity; [first [apply Hcall|apply Hcreate]|reflexivity]);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try reflexivity; try exact Hcore.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [reflexivity|exact Hcore].
Qed.
Lemma call_preserves_context msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesContext (hostCall msg).
Proof.
intros Hrevision Hvm Hgas. unfold H.call, H.M.
apply context_mbind.
- match goal with |- preservesContext (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_context_frame.
+ apply context_return.
- intros noOverflow. destruct noOverflow; [|apply context_return].
apply call_impl_preserves_context; assumption.
Qed.
Lemma call_from_eoa_preserves_context tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesContext ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesContext (callFromEoa tx msg).
Proof. apply call_impl_preserves_context. Qed.
Lemma process_call_preserves_supply from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesSupply (processCall from_tx msg).
Proof.
intros Hrevision Hvm Hvalue. unfold H.process_call, H.M. cbn zeta.
apply supply_mbind.
- destruct (H.should_transfer msg); [apply supply_transfer; exact Hvalue|apply supply_return].
- intros transfer_ok. destruct transfer_ok; [|apply supply_return].
apply supply_mbind.
+ apply supply_mbind; [apply supply_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_supply_frame.
+ intros [addr code].
match goal with |- preservesSupply (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_supply (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_supply from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z →
preservesSupply (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas Hvalue s Hinv.
pose proof (process_call_preserves_supply from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas Hvalue) Hvalue) as Hcall.
pose proof (@process_create_preserves_supply _fargs
msg Hvm Hgas Hvalue) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : balanceInvariant (S.t.world_state (snd run)) ∧
(totalBalance (S.t.world_state (snd run)) ≤ totalBalance (S.t.world_state s))%Z) by
(lazymatch run with ?f ?st ⇒
first [exact (Hcall st Hinv)|exact (Hcreate st Hinv)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try exact Hcore; try (split; [exact Hinv|apply Z.le_refl]).
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [split; [exact Hinv|apply Z.le_refl]|exact Hcore].
Qed.
Lemma call_preserves_supply msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z → preservesSupply (hostCall msg).
Proof.
intros Hrevision Hvm Hgas Hvalue. unfold H.call, H.M.
apply supply_mbind.
- match goal with |- preservesSupply (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_supply_frame.
+ apply supply_return.
- intros noOverflow. destruct noOverflow; [|apply supply_return].
apply call_impl_preserves_supply; assumption.
Qed.
Lemma call_from_eoa_preserves_supply tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value nested))%Z →
preservesSupply ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
(0 ≤ U.to_z (Evmc.Message.t.value msg))%Z → preservesSupply (callFromEoa tx msg).
Proof. apply call_impl_preserves_supply. Qed.
Lemma process_call_preserves_format from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ code, preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) msg code)) →
preservesCallback hostFormat (processCall from_tx msg).
Proof.
intros Hrevision Hvm. unfold H.process_call, H.M. cbn zeta.
apply format_bind.
- destruct (H.should_transfer msg); [intro; apply transfer_preserves_format|apply format_return].
- intros transfer_ok. destruct transfer_ok; [|apply format_return].
apply format_bind.
+ apply format_bind; [apply format_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code);
solve_format.
+ intros [addr code].
match goal with |- preservesCallback hostFormat (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@try_precompile_preserves_format (@H.Precompiles_fargs _fargs) msg addr action Hrevision Hselected).
× apply Hvm.
Qed.
Lemma call_impl_preserves_format from_tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesCallback hostFormat (callImpl from_tx msg).
Proof.
intros Hrevision Hvm Hgas s Hformat.
pose proof (process_call_preserves_format from_tx msg Hrevision
(fun code ⇒ Hvm msg code Hgas)) as Hcall.
pose proof (@process_create_preserves_format _fargs
msg Hvm Hgas) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : hostFormat (snd run)) by
(lazymatch run with ?f ?st ⇒
first [exact (Hcall st Hformat)|exact (Hcreate st Hformat)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try exact Hcore; try exact Hformat.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked
end.
all: destruct dipped; cbn; [exact Hformat|exact Hcore].
Qed.
Lemma call_preserves_format msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesCallback hostFormat (hostCall msg).
Proof.
intros Hrevision Hvm Hgas. unfold H.call, H.M.
apply format_bind.
- match goal with |- preservesCallback hostFormat (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_format.
+ apply format_return.
- intros noOverflow. destruct noOverflow; [|apply format_return].
apply call_impl_preserves_format; assumption.
Qed.
Lemma call_from_eoa_preserves_format tx msg :
(@H.ChainParams _fargs).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
preservesCallback hostFormat ((@H.Vm _fargs).(Evmc.Vm.SIG.execute) nested code)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z → preservesCallback hostFormat (callFromEoa tx msg).
Proof. apply call_impl_preserves_format. Qed.
End Calls.
Print Assumptions call_preserves_context.
Print Assumptions call_from_eoa_preserves_context.
Print Assumptions call_from_eoa_preserves_supply.
Print Assumptions call_from_eoa_preserves_format.