Library SetcodeConcrete.adoptionguard
The actual Host enforces the sender-or-zero-reserve migration rule
From Stdlib Require Import String Bool ZArith NArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Host SetcodeConcrete.rules.
Set Default Goal Selector "!".
Module H := Host.Make.
Module S := State.TransactionState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module Addr := Chain.Ethereum.Address.
Local Abbreviation codeAt := (fun world a ⇒ A.t.code
(State.op_pointcaretlparenrparen world (W.account None a))).
Local Abbreviation heightOf := (fun state ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header (S.t.current_block state))).
Section Host.
Context {F : H.FArgs}.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Host SetcodeConcrete.rules.
Set Default Goal Selector "!".
Module H := Host.Make.
Module S := State.TransactionState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module Addr := Chain.Ethereum.Address.
Local Abbreviation codeAt := (fun world a ⇒ A.t.code
(State.op_pointcaretlparenrparen world (W.account None a))).
Local Abbreviation heightOf := (fun state ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header (S.t.current_block state))).
Section Host.
Context {F : H.FArgs}.
Every nonexceptional Host result has passed the actual adoption guard,
including a false result for an invalid source. state is the state
just before the opcode; current is its execution-context account,
not necessarily the transaction sender.
Theorem setcodefrom_checks_adoption cold warm access write reserve
current source static gas state result after :
H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
H.setcodefrom current source static gas state = (inl result, after) →
Setcode_rules.adoption_allowed
(Delegation.is_valid_delegation (codeAt (S.t.world_state state) current))
(Addr.op_eq current (S.t.tx_origin state))
(Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current) = true.
Proof.
intros Hrevision Hrun. unfold H.setcodefrom in Hrun. rewrite Hrevision in Hrun.
cbn beta iota zeta in Hrun.
destruct static; [discriminate|].
destruct (Setcode_rules.system_account current); [discriminate|].
match type of Hrun with context [if ?test then _ else _] ⇒
destruct test eqn:Hgas end; [discriminate|].
match type of Hrun with context [if negb ?allowed then _ else _] ⇒
destruct (negb allowed) eqn:Hallowed end; [discriminate|].
apply Bool.negb_false_iff in Hallowed. exact Hallowed.
Qed.
current source static gas state result after :
H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
H.setcodefrom current source static gas state = (inl result, after) →
Setcode_rules.adoption_allowed
(Delegation.is_valid_delegation (codeAt (S.t.world_state state) current))
(Addr.op_eq current (S.t.tx_origin state))
(Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current) = true.
Proof.
intros Hrevision Hrun. unfold H.setcodefrom in Hrun. rewrite Hrevision in Hrun.
cbn beta iota zeta in Hrun.
destruct static; [discriminate|].
destruct (Setcode_rules.system_account current); [discriminate|].
match type of Hrun with context [if ?test then _ else _] ⇒
destruct test eqn:Hgas end; [discriminate|].
match type of Hrun with context [if negb ?allowed then _ else _] ⇒
destruct (negb allowed) eqn:Hallowed end; [discriminate|].
apply Bool.negb_false_iff in Hallowed. exact Hallowed.
Qed.
A delegated nonsender cannot successfully use the opcode while its
active reserve is positive. The conclusion reads the actual pre-opcode
reserve configuration, not an assumed or predicted configuration.
Corollary relayed_setcodefrom_requires_zero_reserve cold warm access write reserve
current source static gas state result after :
H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
Delegation.is_valid_delegation (codeAt (S.t.world_state state) current) = true →
Addr.op_eq current (S.t.tx_origin state) = false →
H.setcodefrom current source static gas state = (inl result, after) →
Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current = 0%Z.
Proof.
intros Hrevision Hdelegated Hsender Hrun.
pose proof (setcodefrom_checks_adoption cold warm access write reserve
current source static gas state result after Hrevision Hrun) as Hguard.
change (Setcode_rules.adoption_allowed
(Delegation.is_valid_delegation (codeAt (S.t.world_state state) current))
(Addr.op_eq current (S.t.tx_origin state))
(Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current) = true) in Hguard.
cbn beta in Hguard.
rewrite Hdelegated, Hsender in Hguard.
now apply rules.relayed_delegated_adoption_requires_zero in Hguard.
Qed.
End Host.
Print Assumptions relayed_setcodefrom_requires_zero_reserve.
current source static gas state result after :
H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
Delegation.is_valid_delegation (codeAt (S.t.world_state state) current) = true →
Addr.op_eq current (S.t.tx_origin state) = false →
H.setcodefrom current source static gas state = (inl result, after) →
Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current = 0%Z.
Proof.
intros Hrevision Hdelegated Hsender Hrun.
pose proof (setcodefrom_checks_adoption cold warm access write reserve
current source static gas state result after Hrevision Hrun) as Hguard.
change (Setcode_rules.adoption_allowed
(Delegation.is_valid_delegation (codeAt (S.t.world_state state) current))
(Addr.op_eq current (S.t.tx_origin state))
(Reserve_balance.user_reserve_balance (S.t.world_state state) (heightOf state) current) = true) in Hguard.
cbn beta in Hguard.
rewrite Hdelegated, Hsender in Hguard.
now apply rules.relayed_delegated_adoption_requires_zero in Hguard.
Qed.
End Host.
Print Assumptions relayed_setcodefrom_requires_zero_reserve.