Library QedkConcrete.nondebithost
Uncreated-account balance protection through concrete Host calls
From Stdlib Require Import List String ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.nondebitframe QedkConcrete.nondebitcreate QedkConcrete.creationhost
QedkConcrete.creationassembly QedkConcrete.hostcode QedkConcrete.assemblychecked
QedkConcrete.precompilesframe QedkConcrete.reserveprecompileproperties
QedkConcrete.contexthostinstance QedkConcrete.vmhostframe
QedkConcrete.supplyhostinstance QedkConcrete.hostsupply QedkConcrete.supply
QedkConcrete.hostframe QedkConcrete.vmcallframe.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Local Open Scope Z_scope.
Section Host.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation frame := (@creationFrame).
Local Abbreviation preserves := preservesCreation.
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Context (vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs
(@Evmc.Instantiate.T S.t (@recursiveArgs F)))).
Local Abbreviation floor := (@uncreatedBalanceFloor).
Lemma native_preserves_uncreated_balance_table query minimum msg addr action :
@reservePrecompileTable (@H.Precompiles_fargs (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)) →
nativeDispatch vm msg addr = Some action →
preservesCallback (floor query minimum) action.
Proof.
intros Htable Hselected. unfold nativeDispatch, Precompiles.Make.try_precompile in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [pure|] eqn:Hethereum in Hselected end.
- destruct (Evmc.Message.t.delegated msg) in Hselected; inversion Hselected; subst action;
intros s Hfloor; exact Hfloor.
- unfold reservePrecompileTable in Htable. rewrite Htable in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [native|] eqn:Hnative in Hselected end.
2: discriminate.
apply precompilesframe.find_singleton_value in Hnative. subst native.
match type of Hselected with context [if ?reject then _ else _] ⇒ destruct reject in Hselected end.
+ inversion Hselected; subst action. intros s Hfloor; exact Hfloor.
+ inversion Hselected; subst action. apply uncreated_balance_floor_callback.
× intro initial. apply creation_callback, reserve_precompile_preserves_creation.
× intro limit. apply supply_callback. intros s Hinv.
match goal with |- balanceInvariant ?world ∧ _ ⇒
assert (Hsafe : balanceInvariant world ∧ totalBalance world = totalBalance (S.t.world_state s))
by (apply precompile_preserves_supply; exact Hinv)
end. destruct Hsafe as [Hafter Htotal]. split; [exact Hafter|lia].
× apply balance_floor_callback.
-- intros s Hinv.
match goal with |- balanceInvariant ?world ∧ _ ⇒
assert (Hsafe : balanceInvariant world ∧ totalBalance world = totalBalance (S.t.world_state s))
by (apply precompile_preserves_supply; exact Hinv)
end. destruct Hsafe as [Hafter Htotal]. split; [exact Hafter|lia].
-- intros s Hinv. rewrite precompile_preserves_balances by exact (proj1 Hinv). reflexivity.
Qed.
Lemma native_preserves_uncreated_balance query minimum msg addr action :
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
nativeDispatch vm msg addr = Some action →
preservesCallback (floor query minimum) action.
Proof.
intros Hrevision. apply native_preserves_uncreated_balance_table.
unfold reservePrecompileTable, Precompiles.Make.monad_precompiles.
change (@Precompiles.Make.Revision (@H.Precompiles_fargs
(H.Build_FArgs F.(Host.Instantiate.ChainParams) vm))).(Precompiles.Make_Revision_signature.revision)
with F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision).
rewrite Hrevision. reflexivity.
Qed.
Local Abbreviation processCall := (@H.process_call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation callImpl := (@H.call_impl (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.nondebitframe QedkConcrete.nondebitcreate QedkConcrete.creationhost
QedkConcrete.creationassembly QedkConcrete.hostcode QedkConcrete.assemblychecked
QedkConcrete.precompilesframe QedkConcrete.reserveprecompileproperties
QedkConcrete.contexthostinstance QedkConcrete.vmhostframe
QedkConcrete.supplyhostinstance QedkConcrete.hostsupply QedkConcrete.supply
QedkConcrete.hostframe QedkConcrete.vmcallframe.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Local Open Scope Z_scope.
Section Host.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation frame := (@creationFrame).
Local Abbreviation preserves := preservesCreation.
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Context (vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs
(@Evmc.Instantiate.T S.t (@recursiveArgs F)))).
Local Abbreviation floor := (@uncreatedBalanceFloor).
Lemma native_preserves_uncreated_balance_table query minimum msg addr action :
@reservePrecompileTable (@H.Precompiles_fargs (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)) →
nativeDispatch vm msg addr = Some action →
preservesCallback (floor query minimum) action.
Proof.
intros Htable Hselected. unfold nativeDispatch, Precompiles.Make.try_precompile in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [pure|] eqn:Hethereum in Hselected end.
- destruct (Evmc.Message.t.delegated msg) in Hselected; inversion Hselected; subst action;
intros s Hfloor; exact Hfloor.
- unfold reservePrecompileTable in Htable. rewrite Htable in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [native|] eqn:Hnative in Hselected end.
2: discriminate.
apply precompilesframe.find_singleton_value in Hnative. subst native.
match type of Hselected with context [if ?reject then _ else _] ⇒ destruct reject in Hselected end.
+ inversion Hselected; subst action. intros s Hfloor; exact Hfloor.
+ inversion Hselected; subst action. apply uncreated_balance_floor_callback.
× intro initial. apply creation_callback, reserve_precompile_preserves_creation.
× intro limit. apply supply_callback. intros s Hinv.
match goal with |- balanceInvariant ?world ∧ _ ⇒
assert (Hsafe : balanceInvariant world ∧ totalBalance world = totalBalance (S.t.world_state s))
by (apply precompile_preserves_supply; exact Hinv)
end. destruct Hsafe as [Hafter Htotal]. split; [exact Hafter|lia].
× apply balance_floor_callback.
-- intros s Hinv.
match goal with |- balanceInvariant ?world ∧ _ ⇒
assert (Hsafe : balanceInvariant world ∧ totalBalance world = totalBalance (S.t.world_state s))
by (apply precompile_preserves_supply; exact Hinv)
end. destruct Hsafe as [Hafter Htotal]. split; [exact Hafter|lia].
-- intros s Hinv. rewrite precompile_preserves_balances by exact (proj1 Hinv). reflexivity.
Qed.
Lemma native_preserves_uncreated_balance query minimum msg addr action :
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
nativeDispatch vm msg addr = Some action →
preservesCallback (floor query minimum) action.
Proof.
intros Hrevision. apply native_preserves_uncreated_balance_table.
unfold reservePrecompileTable, Precompiles.Make.monad_precompiles.
change (@Precompiles.Make.Revision (@H.Precompiles_fargs
(H.Build_FArgs F.(Host.Instantiate.ChainParams) vm))).(Precompiles.Make_Revision_signature.revision)
with F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision).
rewrite Hrevision. reflexivity.
Qed.
Local Abbreviation processCall := (@H.process_call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation callImpl := (@H.call_impl (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
This is the nested CALL path, not an arbitrary invocation of code at an
address. If the recipient is the protected address, the opcode's lookup
must have selected that address's code. The Host then reads empty code
unless the address has already been recorded as created.
Lemma process_call_preserves_uncreated_balance self query minimum msg :
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
childCallFrom self msg → self ≠ query →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, floor query minimum s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (floor query minimum) (processCall None msg).
Proof.
intros Hrevision Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial.
pose proof (child_transfer_preserves_uncreated_balance vm self query minimum msg
Horigin Hdifferent Hvalue s Hinitial) as Htransfer.
unfold H.process_call, H.M.
cbn -[H.should_transfer H.transfer_ether W.account Precompiles.Make.try_precompile
uncreatedBalanceFloor].
match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : floor query minimum (snd run)) by exact Htransfer;
destruct run as [ok middle] eqn:Hrun
end.
cbn beta iota zeta delta [snd] in Hmiddle.
destruct ok; [|exact Hmiddle].
cbn -[W.account Precompiles.Make.try_precompile uncreatedBalanceFloor].
match goal with |- context [match ?selection with Some _ ⇒ _ | None ⇒ _ end] ⇒
destruct selection as [action|] eqn:Hselected
end.
- eapply native_preserves_uncreated_balance; eassumption.
- apply Hvm; [exact Hmiddle|]. intro Hrecipient.
destruct Hmiddle as [Hinv [Hcreated|[Hempty Hfloor]]]; [right; exact Hcreated|].
left. rewrite (HcodeAddress Hrecipient). exact Hempty.
Qed.
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
childCallFrom self msg → self ≠ query →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, floor query minimum s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (floor query minimum) (processCall None msg).
Proof.
intros Hrevision Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial.
pose proof (child_transfer_preserves_uncreated_balance vm self query minimum msg
Horigin Hdifferent Hvalue s Hinitial) as Htransfer.
unfold H.process_call, H.M.
cbn -[H.should_transfer H.transfer_ether W.account Precompiles.Make.try_precompile
uncreatedBalanceFloor].
match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : floor query minimum (snd run)) by exact Htransfer;
destruct run as [ok middle] eqn:Hrun
end.
cbn beta iota zeta delta [snd] in Hmiddle.
destruct ok; [|exact Hmiddle].
cbn -[W.account Precompiles.Make.try_precompile uncreatedBalanceFloor].
match goal with |- context [match ?selection with Some _ ⇒ _ | None ⇒ _ end] ⇒
destruct selection as [action|] eqn:Hselected
end.
- eapply native_preserves_uncreated_balance; eassumption.
- apply Hvm; [exact Hmiddle|]. intro Hrecipient.
destruct Hmiddle as [Hinv [Hcreated|[Hempty Hfloor]]]; [right; exact Hcreated|].
left. rewrite (HcodeAddress Hrecipient). exact Hempty.
Qed.
The enclosing Host callback also covers failure: rollback restores the
input balance, while success keeps the bound proved for process_call.
Lemma noncreation_call_preserves_uncreated_balance self query minimum msg :
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
Evmc.Message.t.kind msg ≠ Evmc.Message.CallKind.Create →
Evmc.Message.t.kind msg ≠ Evmc.Message.CallKind.Create2 →
childCallFrom self msg → self ≠ query →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, floor query minimum s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hrevision Hcreate Hcreate2 Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial.
pose proof (process_call_preserves_uncreated_balance self query minimum msg
Hrevision Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial) as Hcore.
cbn -[H.call uncreatedBalanceFloor]. unfold H.call, H.call_impl.
destruct (Evmc.Message.t.kind msg); try contradiction.
all: cbn -[H.process_call uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hafter : floor query minimum (snd run)) by exact Hcore;
destruct run as [result after]
end.
all: cbn beta iota zeta delta [snd] in Hafter.
all: destruct result as [status gasleft refund output address]; destruct status;
cbn -[uncreatedBalanceFloor]; first [exact Hafter|exact Hinitial].
Qed.
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
Evmc.Message.t.kind msg ≠ Evmc.Message.CallKind.Create →
Evmc.Message.t.kind msg ≠ Evmc.Message.CallKind.Create2 →
childCallFrom self msg → self ≠ query →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, floor query minimum s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hrevision Hcreate Hcreate2 Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial.
pose proof (process_call_preserves_uncreated_balance self query minimum msg
Hrevision Horigin Hdifferent Hvalue HcodeAddress Hvm s Hinitial) as Hcore.
cbn -[H.call uncreatedBalanceFloor]. unfold H.call, H.call_impl.
destruct (Evmc.Message.t.kind msg); try contradiction.
all: cbn -[H.process_call uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hafter : floor query minimum (snd run)) by exact Hcore;
destruct run as [result after]
end.
all: cbn beta iota zeta delta [snd] in Hafter.
all: destruct result as [status gasleft refund output address]; destruct status;
cbn -[uncreatedBalanceFloor]; first [exact Hafter|exact Hinitial].
Qed.
Warming a creation address and retaining the creator's nonce on failure
do not spend the unrelated account's balance. Initcode may run at the
protected address only after CREATE has recorded that address.
Lemma creation_call_impl_preserves_uncreated_balance query minimum msg :
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
Evmc.Message.t.sender msg ≠ query →
preservesCallback (floor query minimum) (callImpl None msg).
Proof.
intros Hkind Hcreation Hvm Hgas Hvalue Hsender s Hinitial.
pose proof (process_create_preserves_uncreated_balance
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query minimum msg Hcreation Hvm Hgas Hvalue Hsender) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg); try (destruct Hkind; discriminate).
all: cbn -[H.process_create Addr.of_contract_creation uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hafter : floor query minimum (snd run)) by (apply Hcreate; exact Hinitial);
destruct run as [result after]
end.
all: cbn beta iota zeta delta [snd] in Hafter.
all: destruct result as [status gasleft refund output address]; destruct status;
cbn -[uncreatedBalanceFloor]; first [exact Hafter|exact Hinitial].
Qed.
Lemma creation_call_preserves_uncreated_balance query minimum msg :
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
Evmc.Message.t.sender msg ≠ query →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hkind Hcreation Hvm Hgas Hvalue Hsender s Hinitial.
pose proof (creation_call_impl_preserves_uncreated_balance query minimum msg
Hkind Hcreation Hvm Hgas Hvalue Hsender) as Himpl.
pose proof (increment_nonce_preserves_uncreated_balance
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query minimum (Evmc.Message.t.sender msg) s Hinitial) as Hnonce.
cbn -[H.call uncreatedBalanceFloor]. unfold H.call.
destruct Hkind as [Hkind|Hkind]; rewrite Hkind.
all: cbn -[H.try_increment_nonce H.call_impl uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : floor query minimum (snd run)) by exact Hnonce;
destruct run as [ok middle]
end.
all: cbn beta iota zeta delta [snd] in Hmiddle.
all: destruct ok; [apply Himpl; exact Hmiddle|exact Hmiddle].
Qed.
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
Evmc.Message.t.sender msg ≠ query →
preservesCallback (floor query minimum) (callImpl None msg).
Proof.
intros Hkind Hcreation Hvm Hgas Hvalue Hsender s Hinitial.
pose proof (process_create_preserves_uncreated_balance
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query minimum msg Hcreation Hvm Hgas Hvalue Hsender) as Hcreate.
unfold H.call_impl.
destruct (Evmc.Message.t.kind msg); try (destruct Hkind; discriminate).
all: cbn -[H.process_create Addr.of_contract_creation uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hafter : floor query minimum (snd run)) by (apply Hcreate; exact Hinitial);
destruct run as [result after]
end.
all: cbn beta iota zeta delta [snd] in Hafter.
all: destruct result as [status gasleft refund output address]; destruct status;
cbn -[uncreatedBalanceFloor]; first [exact Hafter|exact Hinitial].
Qed.
Lemma creation_call_preserves_uncreated_balance query minimum msg :
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
Evmc.Message.t.sender msg ≠ query →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hkind Hcreation Hvm Hgas Hvalue Hsender s Hinitial.
pose proof (creation_call_impl_preserves_uncreated_balance query minimum msg
Hkind Hcreation Hvm Hgas Hvalue Hsender) as Himpl.
pose proof (increment_nonce_preserves_uncreated_balance
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query minimum (Evmc.Message.t.sender msg) s Hinitial) as Hnonce.
cbn -[H.call uncreatedBalanceFloor]. unfold H.call.
destruct Hkind as [Hkind|Hkind]; rewrite Hkind.
all: cbn -[H.try_increment_nonce H.call_impl uncreatedBalanceFloor].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : floor query minimum (snd run)) by exact Hnonce;
destruct run as [ok middle]
end.
all: cbn beta iota zeta delta [snd] in Hmiddle.
all: destruct ok; [apply Himpl; exact Hmiddle|exact Hmiddle].
Qed.
All message kinds of the concrete Host constructor. The remaining VM
premise is restricted to the actual execution context: it need not
protect an address against arbitrary code executed at that address.
Theorem call_preserves_uncreated_balance self query minimum msg :
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
self ≠ query → childCallFrom self msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hrevision Hcreation Hvm Hgas Hvalue Hdifferent Horigin Htarget.
destruct (Evmc.Message.t.kind msg) eqn:Hkind.
all: first [eapply noncreation_call_preserves_uncreated_balance with (self := self);
[exact Hrevision|rewrite Hkind; discriminate|rewrite Hkind; discriminate|
exact Horigin|exact Hdifferent|exact Hvalue|
destruct Htarget as [Hbad|[Hbad|Htarget]]; try discriminate; exact Htarget|
intros code s Hfloor Hcode; apply Hvm; assumption] |
apply creation_call_preserves_uncreated_balance;
[first [left; exact Hkind|right; exact Hkind]|exact Hcreation|exact Hvm|
exact Hgas|exact Hvalue|
unfold childCallFrom in Horigin; rewrite Hkind in Horigin;
rewrite Horigin; exact Hdifferent]].
Qed.
End Host.
Print Assumptions native_preserves_uncreated_balance.
Print Assumptions process_call_preserves_uncreated_balance.
Print Assumptions noncreation_call_preserves_uncreated_balance.
Print Assumptions creation_call_preserves_uncreated_balance.
Print Assumptions call_preserves_uncreated_balance.
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
preserves (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value nested) →
∀ s, floor query minimum s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
floor query minimum (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
0 ≤ Numeric.U256.to_z (Evmc.Message.t.value msg) →
self ≠ query → childCallFrom self msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (floor query minimum) ((HostF vm).(Evmc.HOST.call) msg).
Proof.
intros Hrevision Hcreation Hvm Hgas Hvalue Hdifferent Horigin Htarget.
destruct (Evmc.Message.t.kind msg) eqn:Hkind.
all: first [eapply noncreation_call_preserves_uncreated_balance with (self := self);
[exact Hrevision|rewrite Hkind; discriminate|rewrite Hkind; discriminate|
exact Horigin|exact Hdifferent|exact Hvalue|
destruct Htarget as [Hbad|[Hbad|Htarget]]; try discriminate; exact Htarget|
intros code s Hfloor Hcode; apply Hvm; assumption] |
apply creation_call_preserves_uncreated_balance;
[first [left; exact Hkind|right; exact Hkind]|exact Hcreation|exact Hvm|
exact Hgas|exact Hvalue|
unfold childCallFrom in Horigin; rewrite Hkind in Horigin;
rewrite Horigin; exact Hdifferent]].
Qed.
End Host.
Print Assumptions native_preserves_uncreated_balance.
Print Assumptions process_call_preserves_uncreated_balance.
Print Assumptions noncreation_call_preserves_uncreated_balance.
Print Assumptions creation_call_preserves_uncreated_balance.
Print Assumptions call_preserves_uncreated_balance.