Library QedkConcrete.transactionsupply
Reducing transaction supply safety to its actual Host call
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionformat QedkConcrete.transactionfees
QedkConcrete.supply QedkConcrete.validation QedkConcrete.emptyinghistory
QedkConcrete.authorization QedkConcrete.hostaccountformat QedkConcrete.worldaccounts
QedkConcrete.credits QedkConcrete.reservewrites.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Definition callSupplyViolation
(call : Evmc.Message.t → S.t → Evmc.Result.t × S.t) : Prop :=
∃ before msg,
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (call msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionformat QedkConcrete.transactionfees
QedkConcrete.supply QedkConcrete.validation QedkConcrete.emptyinghistory
QedkConcrete.authorization QedkConcrete.hostaccountformat QedkConcrete.worldaccounts
QedkConcrete.credits QedkConcrete.reservewrites.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Definition callSupplyViolation
(call : Evmc.Message.t → S.t → Evmc.Result.t × S.t) : Prop :=
∃ before msg,
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (call msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Finite account maps make supply safety decidable. This lets the fold
proof locate a failing step constructively, without classical choice.
Local Lemma accounts_wellformed_dec (accounts : list (string × A.t)) :
{stringmaps.WellFormed accounts} + {¬ stringmaps.WellFormed accounts}.
Proof.
induction accounts as [|[addr account] tail IH].
- left. constructor.
- destruct IH as [Htail|Htail].
2: { right. intro H. apply Htail. exact (proj1 (Sorted.Sorted_inv H)). }
destruct tail as [|[next value] rest].
+ left. constructor; constructor.
+ destruct (Basics.String.ltb_spec addr next) as [Hlt|Hlt].
× left. constructor; [exact Htail|constructor; exact Hlt].
× right. intro H. apply Sorted.Sorted_inv in H. destruct H as [_ Hhead].
inversion Hhead. contradiction.
Defined.
Local Lemma supply_safety_dec (world : W.t) (limit : Z) :
{balanceInvariant world ∧ totalBalance world ≤ limit} +
{¬ (balanceInvariant world ∧ totalBalance world ≤ limit)}.
Proof.
unfold balanceInvariant, nonnegativeBalances.
destruct (accounts_wellformed_dec (W.t.accounts world)) as [Hwf|Hwf];
[|right; tauto].
destruct (Forall_dec (fun entry ⇒ 0 ≤ U.to_z (A.t.balance (snd entry)))
(fun entry ⇒ Z_le_dec 0 (U.to_z (A.t.balance (snd entry)))) (W.t.accounts world))
as [Hnonnegative|Hnonnegative]; [|right; tauto].
destruct (Z_lt_dec (totalBalance world) (2^256)) as [Hbound|Hbound]; [|right; tauto].
destruct (Z_le_dec (totalBalance world) limit) as [Hlimit|Hlimit]; [left|right]; tauto.
Defined.
Section Execution.
Context {F : E.FArgs}.
Lemma bump_counters_accounts s addresses :
W.t.accounts (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)) =
W.t.accounts (S.t.world_state s).
Proof.
unfold E.bump_emptying_transaction_counters.
cbn beta iota zeta delta [S.t.with_world_state S.t.world_state].
apply counter_writes_accounts.
Qed.
Lemma bump_counters_balance_invariant s addresses :
balanceInvariant (S.t.world_state s) →
balanceInvariant (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)).
Proof.
unfold balanceInvariant, nonnegativeBalances, totalBalance.
rewrite bump_counters_accounts. trivial.
Qed.
Lemma bump_counters_total s addresses :
totalBalance (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)) =
totalBalance (S.t.world_state s).
Proof. unfold totalBalance. rewrite bump_counters_accounts. reflexivity. Qed.
Lemma delete_accounts_supply block addresses :
balanceInvariant (B.t.world_state block) →
let after := OCamlSeq.fold_left
(fun s addr ⇒ State.op_pointcaretlparenrparenltminus s
(@B.account_opt None addr) None) block addresses in
balanceInvariant (B.t.world_state after) ∧
totalBalance (B.t.world_state after) ≤ totalBalance (B.t.world_state block).
Proof.
revert block. induction addresses as [|addr addresses IH]; intros block Hinitial.
{ split; [exact Hinitial|apply Z.le_refl]. }
cbn [OCamlSeq.fold_left].
pose proof (@delete_account_preserves_invariant (B.t.world_state block) addr Hinitial)
as [Hnext Htotal].
specialize (IH (State.op_pointcaretlparenrparenltminus block
(@B.account_opt None addr) None) Hnext).
split; [exact (proj1 IH)|]. eapply Z.le_trans; [exact (proj2 IH)|exact Htotal].
Qed.
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
{stringmaps.WellFormed accounts} + {¬ stringmaps.WellFormed accounts}.
Proof.
induction accounts as [|[addr account] tail IH].
- left. constructor.
- destruct IH as [Htail|Htail].
2: { right. intro H. apply Htail. exact (proj1 (Sorted.Sorted_inv H)). }
destruct tail as [|[next value] rest].
+ left. constructor; constructor.
+ destruct (Basics.String.ltb_spec addr next) as [Hlt|Hlt].
× left. constructor; [exact Htail|constructor; exact Hlt].
× right. intro H. apply Sorted.Sorted_inv in H. destruct H as [_ Hhead].
inversion Hhead. contradiction.
Defined.
Local Lemma supply_safety_dec (world : W.t) (limit : Z) :
{balanceInvariant world ∧ totalBalance world ≤ limit} +
{¬ (balanceInvariant world ∧ totalBalance world ≤ limit)}.
Proof.
unfold balanceInvariant, nonnegativeBalances.
destruct (accounts_wellformed_dec (W.t.accounts world)) as [Hwf|Hwf];
[|right; tauto].
destruct (Forall_dec (fun entry ⇒ 0 ≤ U.to_z (A.t.balance (snd entry)))
(fun entry ⇒ Z_le_dec 0 (U.to_z (A.t.balance (snd entry)))) (W.t.accounts world))
as [Hnonnegative|Hnonnegative]; [|right; tauto].
destruct (Z_lt_dec (totalBalance world) (2^256)) as [Hbound|Hbound]; [|right; tauto].
destruct (Z_le_dec (totalBalance world) limit) as [Hlimit|Hlimit]; [left|right]; tauto.
Defined.
Section Execution.
Context {F : E.FArgs}.
Lemma bump_counters_accounts s addresses :
W.t.accounts (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)) =
W.t.accounts (S.t.world_state s).
Proof.
unfold E.bump_emptying_transaction_counters.
cbn beta iota zeta delta [S.t.with_world_state S.t.world_state].
apply counter_writes_accounts.
Qed.
Lemma bump_counters_balance_invariant s addresses :
balanceInvariant (S.t.world_state s) →
balanceInvariant (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)).
Proof.
unfold balanceInvariant, nonnegativeBalances, totalBalance.
rewrite bump_counters_accounts. trivial.
Qed.
Lemma bump_counters_total s addresses :
totalBalance (S.t.world_state (@E.bump_emptying_transaction_counters F addresses s)) =
totalBalance (S.t.world_state s).
Proof. unfold totalBalance. rewrite bump_counters_accounts. reflexivity. Qed.
Lemma delete_accounts_supply block addresses :
balanceInvariant (B.t.world_state block) →
let after := OCamlSeq.fold_left
(fun s addr ⇒ State.op_pointcaretlparenrparenltminus s
(@B.account_opt None addr) None) block addresses in
balanceInvariant (B.t.world_state after) ∧
totalBalance (B.t.world_state after) ≤ totalBalance (B.t.world_state block).
Proof.
revert block. induction addresses as [|addr addresses IH]; intros block Hinitial.
{ split; [exact Hinitial|apply Z.le_refl]. }
cbn [OCamlSeq.fold_left].
pose proof (@delete_account_preserves_invariant (B.t.world_state block) addr Hinitial)
as [Hnext Htotal].
specialize (IH (State.op_pointcaretlparenrparenltminus block
(@B.account_opt None addr) None) Hnext).
split; [exact (proj1 IH)|]. eapply Z.le_trans; [exact (proj2 IH)|exact Htotal].
Qed.
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
The witness has the actual validated gas bound, nonnegative endowment,
and account/storage format established by the transaction prefix. These
are the entry facts needed when discharging the recursive VM obligation.
Theorem process_transaction_supply_reduction block tx post :
balanceInvariant (B.t.world_state block) →
worldFormat (B.t.world_state block) →
Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx) →
0 ≤ U.to_z (T.value tx) →
@E.process_transaction F block tx = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
∃ before msg,
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (@E.Host.call_from_eoa F
tx msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Proof.
intros Hinitial Hformat Hwidth Hvalue Hrun Hbad.
unfold E.process_transaction in Hrun.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: discriminate Hrun.
pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
(E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
pose proof (proj2 (proj2 Hinitial)) as Hsupply.
pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia))
as [Hfee Hdebit].
assert (HfeeNonnegative : 0 ≤ U.to_z (E.transaction_validation.total_fee validation)).
{ rewrite Hfee. apply N2Z.is_nonneg. }
destruct validation as [sender fee price intrinsic].
cbn [E.transaction_validation.total_fee E.transaction_validation.sender] in Hdebit, HfeeNonnegative.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
cbn beta iota zeta delta [E.transaction_validation.sender E.transaction_validation.total_fee
E.transaction_validation.intrinsic_gas E.transaction_validation.effective_gas_price] in Hrun.
match type of Hrun with context [@S.make block sender tx] ⇒
set (initial := @S.make block sender tx) in ×
end.
assert (HinitialFormat : hostFormat initial) by (apply transaction_initial_format; exact Hformat).
pose proof (@transaction_entry_format F initial sender fee (T.authorization_list tx) Hwidth HinitialFormat) as HauthFormat.
pose proof (@transaction_entry_supply F initial sender fee (T.authorization_list tx) Hinitial HfeeNonnegative Hdebit)
as [Hauth HauthTotal].
match type of Hrun with context [Result.List.fold_left ?f ?start (T.authorization_list tx)] ⇒
set (authorized := Result.List.fold_left f start (T.authorization_list tx)) in ×
end.
change (balanceInvariant (S.t.world_state (snd authorized))) in Hauth.
change (totalBalance (S.t.world_state (snd authorized)) = totalBalance (B.t.world_state block) - U.to_z fee)
in HauthTotal.
change (hostFormat (snd authorized)) in HauthFormat.
destruct authorized as [authorities prepared]. cbn beta iota zeta delta [snd] in Hauth, HauthTotal, HauthFormat, Hrun.
match type of Hrun with context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles) in ×
end.
assert (Hbefore : balanceInvariant (S.t.world_state beforeVm)).
{ change (balanceInvariant (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared))).
apply bump_counters_balance_invariant. exact Hauth. }
assert (HbeforeFormat : hostFormat beforeVm).
{ change (hostFormat (@E.bump_emptying_transaction_counters F authorities prepared)).
apply bump_counters_format. exact HauthFormat. }
assert (HbeforeTotal : totalBalance (S.t.world_state beforeVm) = totalBalance (B.t.world_state block) - U.to_z fee).
{ change (totalBalance (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) =
totalBalance (B.t.world_state block) - U.to_z fee).
rewrite bump_counters_total. exact HauthTotal. }
pose proof (validated_message_gas block tx _ (S.t.world_state beforeVm) Hvalidation) as Hgas.
match type of Hrun with context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
set (msg := message) in ×
end.
∃ beforeVm, msg. split; [exact Hgas|]. split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx); exact Hvalue. }
split; [exact HbeforeFormat|]. split; [exact Hbefore|].
destruct (E.Host.call_from_eoa tx msg beforeVm) as [result afterVm] eqn:Hcall.
cbn [snd]. intros [Hafter HafterTotal].
apply Hbad.
pose proof (bump_counters_balance_invariant afterVm (sender :: nil) Hafter) as HfinalCounters.
pose proof (bump_counters_total afterVm (sender :: nil)) as HfinalTotal.
pose proof (@beneficiary_credit_reuses_fee F block tx _
(S.t.world_state (@E.bump_emptying_transaction_counters F (sender :: nil) afterVm))
Hvalidation Hinitial HfinalCounters ltac:(cbn [E.transaction_validation.total_fee]; lia))
as [Hcredited [HcreditTotal _]].
change (@Result._return) with (fun (A B : Set) (value : A) ⇒ @inl A B value) in Hrun.
injection Hrun as <-.
cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_gas_used B.t.world_state].
change (@Result.Seq.fold_left) with (@OCamlSeq.fold_left).
match goal with |- balanceInvariant (B.t.world_state (OCamlSeq.fold_left ?f ?state ?addresses)) ∧ _ ⇒
pose proof (delete_accounts_supply state addresses Hcredited) as [Hdeleted HdeleteTotal]
end.
split; [exact Hdeleted|]. eapply Z.le_trans; [exact HdeleteTotal|exact HcreditTotal].
Qed.
balanceInvariant (B.t.world_state block) →
worldFormat (B.t.world_state block) →
Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx) →
0 ≤ U.to_z (T.value tx) →
@E.process_transaction F block tx = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
∃ before msg,
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (@E.Host.call_from_eoa F
tx msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Proof.
intros Hinitial Hformat Hwidth Hvalue Hrun Hbad.
unfold E.process_transaction in Hrun.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: discriminate Hrun.
pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
(E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
pose proof (proj2 (proj2 Hinitial)) as Hsupply.
pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia))
as [Hfee Hdebit].
assert (HfeeNonnegative : 0 ≤ U.to_z (E.transaction_validation.total_fee validation)).
{ rewrite Hfee. apply N2Z.is_nonneg. }
destruct validation as [sender fee price intrinsic].
cbn [E.transaction_validation.total_fee E.transaction_validation.sender] in Hdebit, HfeeNonnegative.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
cbn beta iota zeta delta [E.transaction_validation.sender E.transaction_validation.total_fee
E.transaction_validation.intrinsic_gas E.transaction_validation.effective_gas_price] in Hrun.
match type of Hrun with context [@S.make block sender tx] ⇒
set (initial := @S.make block sender tx) in ×
end.
assert (HinitialFormat : hostFormat initial) by (apply transaction_initial_format; exact Hformat).
pose proof (@transaction_entry_format F initial sender fee (T.authorization_list tx) Hwidth HinitialFormat) as HauthFormat.
pose proof (@transaction_entry_supply F initial sender fee (T.authorization_list tx) Hinitial HfeeNonnegative Hdebit)
as [Hauth HauthTotal].
match type of Hrun with context [Result.List.fold_left ?f ?start (T.authorization_list tx)] ⇒
set (authorized := Result.List.fold_left f start (T.authorization_list tx)) in ×
end.
change (balanceInvariant (S.t.world_state (snd authorized))) in Hauth.
change (totalBalance (S.t.world_state (snd authorized)) = totalBalance (B.t.world_state block) - U.to_z fee)
in HauthTotal.
change (hostFormat (snd authorized)) in HauthFormat.
destruct authorized as [authorities prepared]. cbn beta iota zeta delta [snd] in Hauth, HauthTotal, HauthFormat, Hrun.
match type of Hrun with context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles) in ×
end.
assert (Hbefore : balanceInvariant (S.t.world_state beforeVm)).
{ change (balanceInvariant (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared))).
apply bump_counters_balance_invariant. exact Hauth. }
assert (HbeforeFormat : hostFormat beforeVm).
{ change (hostFormat (@E.bump_emptying_transaction_counters F authorities prepared)).
apply bump_counters_format. exact HauthFormat. }
assert (HbeforeTotal : totalBalance (S.t.world_state beforeVm) = totalBalance (B.t.world_state block) - U.to_z fee).
{ change (totalBalance (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) =
totalBalance (B.t.world_state block) - U.to_z fee).
rewrite bump_counters_total. exact HauthTotal. }
pose proof (validated_message_gas block tx _ (S.t.world_state beforeVm) Hvalidation) as Hgas.
match type of Hrun with context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
set (msg := message) in ×
end.
∃ beforeVm, msg. split; [exact Hgas|]. split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx); exact Hvalue. }
split; [exact HbeforeFormat|]. split; [exact Hbefore|].
destruct (E.Host.call_from_eoa tx msg beforeVm) as [result afterVm] eqn:Hcall.
cbn [snd]. intros [Hafter HafterTotal].
apply Hbad.
pose proof (bump_counters_balance_invariant afterVm (sender :: nil) Hafter) as HfinalCounters.
pose proof (bump_counters_total afterVm (sender :: nil)) as HfinalTotal.
pose proof (@beneficiary_credit_reuses_fee F block tx _
(S.t.world_state (@E.bump_emptying_transaction_counters F (sender :: nil) afterVm))
Hvalidation Hinitial HfinalCounters ltac:(cbn [E.transaction_validation.total_fee]; lia))
as [Hcredited [HcreditTotal _]].
change (@Result._return) with (fun (A B : Set) (value : A) ⇒ @inl A B value) in Hrun.
injection Hrun as <-.
cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_gas_used B.t.world_state].
change (@Result.Seq.fold_left) with (@OCamlSeq.fold_left).
match goal with |- balanceInvariant (B.t.world_state (OCamlSeq.fold_left ?f ?state ?addresses)) ∧ _ ⇒
pose proof (delete_accounts_supply state addresses Hcredited) as [Hdeleted HdeleteTotal]
end.
split; [exact Hdeleted|]. eapply Z.le_trans; [exact HdeleteTotal|exact HcreditTotal].
Qed.
A failed supply bound for the transaction fold identifies an actual
transaction Host call with the required entry invariants. The prefix's
supply bound is proved step by step, not assumed for intermediate states.
Theorem transactions_supply_reduction block txs post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx)) txs →
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
Result.List.fold_leftM (@E.process_transaction F) block txs = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
∃ tx before msg, List.In tx txs ∧
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (@E.Host.call_from_eoa F
tx msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Proof.
intros Hrevision Htxs. revert block.
induction Htxs as [|tx txs [Hvalue Hwidth] Htxs IH]; intros block Hinitial Hformat Hrun Hbad.
- injection Hrun as <-. exfalso. apply Hbad. split; [exact Hinitial|lia].
- change (Result.op_letdollar (@E.process_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.process_transaction F) next txs) = inl post) in Hrun.
destruct (@E.process_transaction F block tx) as [next|error] eqn:Hstep.
2: discriminate Hrun.
destruct (supply_safety_dec (B.t.world_state next) (totalBalance (B.t.world_state block)))
as [[Hnext Htotal]|Hfailed].
+ assert (HnextFormat : worldFormat (B.t.world_state next)).
{ pose proof (@process_transaction_preserves_format F
block tx Hrevision Hwidth Hformat) as H.
rewrite Hstep in H. exact H. }
assert (HbadNext : ¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state next))).
{ intros [Hpost HpostTotal]. apply Hbad. split; [exact Hpost|lia]. }
destruct (IH next Hnext HnextFormat Hrun HbadNext) as [witness [before [msg [Hin Hfailure]]]].
∃ witness, before, msg. split; [right; exact Hin|exact Hfailure].
+ destruct (process_transaction_supply_reduction block tx next Hinitial Hformat Hwidth Hvalue Hstep Hfailed)
as [before [msg Hfailure]].
∃ tx, before, msg. split; [left; reflexivity|exact Hfailure].
Qed.
Lemma process_monad_system_transaction_supply_reduction block tx post :
balanceInvariant (B.t.world_state block) →
worldFormat (B.t.world_state block) →
0 ≤ U.to_z (T.value tx) →
@E.process_monad_system_transaction F block tx = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
callSupplyViolation (@E.Host.call_from_monad_system_transaction F).
Proof.
intros Hinitial Hformat Hvalue Hrun Hbad.
unfold E.process_monad_system_transaction in Hrun.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error]; [|discriminate Hrun].
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
cbv beta iota zeta in Hrun.
match type of Hrun with context [E.Host.call_from_monad_system_transaction ?message ?initial] ⇒
set (msg := message) in *; set (beforeVm := initial) in ×
end.
assert (HbeforeFormat : hostFormat beforeVm).
{ split; [|constructor].
apply write_account_format; [exact Hformat|].
apply nonce_update_format, read_account_format. exact Hformat. }
assert (HbeforeSupply : balanceInvariant (S.t.world_state beforeVm) ∧
totalBalance (S.t.world_state beforeVm) = totalBalance (B.t.world_state block)).
{ apply (account_write_preserves_supply false (B.t.world_state block) Chain.Monad.system_sender _ Hinitial).
reflexivity. }
∃ beforeVm, msg.
split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx) as [[]|[]];
change (0 ≤ 0 < 2^63); lia. }
split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx) as [[]|[]]; exact Hvalue. }
split; [exact HbeforeFormat|].
split; [exact (proj1 HbeforeSupply)|].
destruct (E.Host.call_from_monad_system_transaction msg beforeVm) as [result afterVm].
unfold Result.when_ in Hrun.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[discriminate Hrun|].
injection Hrun as <-. cbn [snd B.t.world_state].
rewrite (proj2 HbeforeSupply). exact Hbad.
Qed.
Theorem dispatched_transactions_supply_reduction block txs post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx)) txs →
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
Result.List.fold_leftM (@E.dispatch_transaction F) block txs = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
(∃ tx, List.In tx txs ∧
callSupplyViolation (@E.Host.call_from_eoa F tx)) ∨
callSupplyViolation (@E.Host.call_from_monad_system_transaction F).
Proof.
intros Hrevision Htxs. revert block.
induction Htxs as [|tx txs [Hvalue Hwidth] Htxs IH]; intros block Hinitial Hformat Hrun Hbad.
- injection Hrun as <-. exfalso. apply Hbad. split; [exact Hinitial|lia].
- change (Result.op_letdollar (@E.dispatch_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.dispatch_transaction F) next txs) = inl post) in Hrun.
destruct (@E.dispatch_transaction F block tx) as [next|error] eqn:Hstep;
[|discriminate Hrun].
destruct (supply_safety_dec (B.t.world_state next) (totalBalance (B.t.world_state block)))
as [[Hnext Htotal]|Hfailed].
+ assert (HnextFormat : worldFormat (B.t.world_state next)).
{ pose proof (@dispatch_transaction_preserves_format F
block tx Hrevision Hwidth Hformat) as H.
rewrite Hstep in H. exact H. }
assert (HbadNext : ¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state next))).
{ intros [Hpost HpostTotal]. apply Hbad. split; [exact Hpost|lia]. }
destruct (IH next Hnext HnextFormat Hrun HbadNext) as [[witness [Hin Hfailure]]|Hsys].
× left. ∃ witness. split; [right; exact Hin|exact Hfailure].
× right; exact Hsys.
+ destruct (dispatch_transaction_cases block tx next Hstep)
as [[sender [_ Hstep']] | [_ Hstep']].
× destruct (process_transaction_supply_reduction block tx next Hinitial Hformat Hwidth Hvalue Hstep' Hfailed)
as [before [msg Hfailure]].
left. ∃ tx. split; [left; reflexivity|]. ∃ before, msg. exact Hfailure.
× right. exact (process_monad_system_transaction_supply_reduction block tx next Hinitial Hformat Hvalue Hstep' Hfailed).
Qed.
Lemma system_message_supply_reduction block addr data :
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
let post := snd (@E.process_system_message F
block addr data) in
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
callSupplyViolation (@E.Host.call F).
Proof.
intros Hinitial Hformat. cbn zeta. intro Hbad.
unfold E.process_system_message in Hbad.
match type of Hbad with context [if ?b then _ else _] ⇒ destruct b end.
{ exfalso. apply Hbad. split; [exact Hinitial|apply Z.le_refl]. }
cbn beta iota zeta in Hbad.
match type of Hbad with context [E.Host.call ?message ?initial] ⇒
∃ initial, message
end.
split; [change (0 ≤ 30000000 < 2^63); lia|].
split; [change (0 ≤ 0); lia|].
split; [split; [exact Hformat|constructor]|].
split; [exact Hinitial|].
match type of Hbad with context [E.Host.call ?message ?initial] ⇒
destruct (E.Host.call message initial) as [result after]
end.
exact Hbad.
Qed.
Context {UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}
{UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx)) txs →
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
Result.List.fold_leftM (@E.process_transaction F) block txs = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
∃ tx before msg, List.In tx txs ∧
(0 ≤ Evmc.Message.t.gas msg < 2^63) ∧
0 ≤ U.to_z (Evmc.Message.t.value msg) ∧
hostFormat before ∧ balanceInvariant (S.t.world_state before) ∧
let after := snd (@E.Host.call_from_eoa F
tx msg before) in
¬ (balanceInvariant (S.t.world_state after) ∧
totalBalance (S.t.world_state after) ≤ totalBalance (S.t.world_state before)).
Proof.
intros Hrevision Htxs. revert block.
induction Htxs as [|tx txs [Hvalue Hwidth] Htxs IH]; intros block Hinitial Hformat Hrun Hbad.
- injection Hrun as <-. exfalso. apply Hbad. split; [exact Hinitial|lia].
- change (Result.op_letdollar (@E.process_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.process_transaction F) next txs) = inl post) in Hrun.
destruct (@E.process_transaction F block tx) as [next|error] eqn:Hstep.
2: discriminate Hrun.
destruct (supply_safety_dec (B.t.world_state next) (totalBalance (B.t.world_state block)))
as [[Hnext Htotal]|Hfailed].
+ assert (HnextFormat : worldFormat (B.t.world_state next)).
{ pose proof (@process_transaction_preserves_format F
block tx Hrevision Hwidth Hformat) as H.
rewrite Hstep in H. exact H. }
assert (HbadNext : ¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state next))).
{ intros [Hpost HpostTotal]. apply Hbad. split; [exact Hpost|lia]. }
destruct (IH next Hnext HnextFormat Hrun HbadNext) as [witness [before [msg [Hin Hfailure]]]].
∃ witness, before, msg. split; [right; exact Hin|exact Hfailure].
+ destruct (process_transaction_supply_reduction block tx next Hinitial Hformat Hwidth Hvalue Hstep Hfailed)
as [before [msg Hfailure]].
∃ tx, before, msg. split; [left; reflexivity|exact Hfailure].
Qed.
Lemma process_monad_system_transaction_supply_reduction block tx post :
balanceInvariant (B.t.world_state block) →
worldFormat (B.t.world_state block) →
0 ≤ U.to_z (T.value tx) →
@E.process_monad_system_transaction F block tx = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
callSupplyViolation (@E.Host.call_from_monad_system_transaction F).
Proof.
intros Hinitial Hformat Hvalue Hrun Hbad.
unfold E.process_monad_system_transaction in Hrun.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error]; [|discriminate Hrun].
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
cbv beta iota zeta in Hrun.
match type of Hrun with context [E.Host.call_from_monad_system_transaction ?message ?initial] ⇒
set (msg := message) in *; set (beforeVm := initial) in ×
end.
assert (HbeforeFormat : hostFormat beforeVm).
{ split; [|constructor].
apply write_account_format; [exact Hformat|].
apply nonce_update_format, read_account_format. exact Hformat. }
assert (HbeforeSupply : balanceInvariant (S.t.world_state beforeVm) ∧
totalBalance (S.t.world_state beforeVm) = totalBalance (B.t.world_state block)).
{ apply (account_write_preserves_supply false (B.t.world_state block) Chain.Monad.system_sender _ Hinitial).
reflexivity. }
∃ beforeVm, msg.
split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx) as [[]|[]];
change (0 ≤ 0 < 2^63); lia. }
split.
{ unfold msg, E.prepare_message. destruct (T.call_or_create_value tx) as [[]|[]]; exact Hvalue. }
split; [exact HbeforeFormat|].
split; [exact (proj1 HbeforeSupply)|].
destruct (E.Host.call_from_monad_system_transaction msg beforeVm) as [result afterVm].
unfold Result.when_ in Hrun.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[discriminate Hrun|].
injection Hrun as <-. cbn [snd B.t.world_state].
rewrite (proj2 HbeforeSupply). exact Hbad.
Qed.
Theorem dispatched_transactions_supply_reduction block txs post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx)) txs →
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
Result.List.fold_leftM (@E.dispatch_transaction F) block txs = inl post →
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
(∃ tx, List.In tx txs ∧
callSupplyViolation (@E.Host.call_from_eoa F tx)) ∨
callSupplyViolation (@E.Host.call_from_monad_system_transaction F).
Proof.
intros Hrevision Htxs. revert block.
induction Htxs as [|tx txs [Hvalue Hwidth] Htxs IH]; intros block Hinitial Hformat Hrun Hbad.
- injection Hrun as <-. exfalso. apply Hbad. split; [exact Hinitial|lia].
- change (Result.op_letdollar (@E.dispatch_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.dispatch_transaction F) next txs) = inl post) in Hrun.
destruct (@E.dispatch_transaction F block tx) as [next|error] eqn:Hstep;
[|discriminate Hrun].
destruct (supply_safety_dec (B.t.world_state next) (totalBalance (B.t.world_state block)))
as [[Hnext Htotal]|Hfailed].
+ assert (HnextFormat : worldFormat (B.t.world_state next)).
{ pose proof (@dispatch_transaction_preserves_format F
block tx Hrevision Hwidth Hformat) as H.
rewrite Hstep in H. exact H. }
assert (HbadNext : ¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state next))).
{ intros [Hpost HpostTotal]. apply Hbad. split; [exact Hpost|lia]. }
destruct (IH next Hnext HnextFormat Hrun HbadNext) as [[witness [Hin Hfailure]]|Hsys].
× left. ∃ witness. split; [right; exact Hin|exact Hfailure].
× right; exact Hsys.
+ destruct (dispatch_transaction_cases block tx next Hstep)
as [[sender [_ Hstep']] | [_ Hstep']].
× destruct (process_transaction_supply_reduction block tx next Hinitial Hformat Hwidth Hvalue Hstep' Hfailed)
as [before [msg Hfailure]].
left. ∃ tx. split; [left; reflexivity|]. ∃ before, msg. exact Hfailure.
× right. exact (process_monad_system_transaction_supply_reduction block tx next Hinitial Hformat Hvalue Hstep' Hfailed).
Qed.
Lemma system_message_supply_reduction block addr data :
balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
let post := snd (@E.process_system_message F
block addr data) in
¬ (balanceInvariant (B.t.world_state post) ∧
totalBalance (B.t.world_state post) ≤ totalBalance (B.t.world_state block)) →
callSupplyViolation (@E.Host.call F).
Proof.
intros Hinitial Hformat. cbn zeta. intro Hbad.
unfold E.process_system_message in Hbad.
match type of Hbad with context [if ?b then _ else _] ⇒ destruct b end.
{ exfalso. apply Hbad. split; [exact Hinitial|apply Z.le_refl]. }
cbn beta iota zeta in Hbad.
match type of Hbad with context [E.Host.call ?message ?initial] ⇒
∃ initial, message
end.
split; [change (0 ≤ 30000000 < 2^63); lia|].
split; [change (0 ≤ 0); lia|].
split; [split; [exact Hformat|constructor]|].
split; [exact Hinitial|].
match type of Hbad with context [E.Host.call ?message ?initial] ⇒
destruct (E.Host.call message initial) as [result after]
end.
exact Hbad.
Qed.
Context {UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}
{UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
The entire concrete block is covered, including both system messages.
Withdrawals use the approved aggregate credit budget; fees need no added
budget. Any remaining violation is traced to a transaction or system Host
call, without postulating that either kind of call conserves supply.
Theorem process_block_supply_reduction verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
balanceInvariant world → worldFormat world →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx))
(Chain.Ethereum.Block.t.transactions block) →
Forall (fun wd ⇒ 0 ≤ Numeric.U64.to_z (Chain.Ethereum.Withdrawal.t.amount wd) < 2^64)
(Chain.Ethereum.Block.t.withdrawals block) →
let credits := Stdlib.Lists.List.fold_right (fun wd total ⇒ withdrawalWei wd + total) 0
(Chain.Ethereum.Block.t.withdrawals block) in
totalBalance world + credits < 2^256 →
@E.process_block F verify world block = inl post →
¬ (balanceInvariant post ∧ totalBalance post ≤ totalBalance world + credits) →
(∃ tx, List.In tx (Chain.Ethereum.Block.t.transactions block) ∧
callSupplyViolation (@E.Host.call_from_eoa F
tx)) ∨
callSupplyViolation (@E.Host.call_from_monad_system_transaction F) ∨
callSupplyViolation (@E.Host.call F).
Proof.
intros Hrevision Hinitial Hformat Htxs Hwithdrawals credits Hbudget Hrun Hbad.
unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalidation.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
match type of Hrun with context [B.make ?w block] ⇒ set (initial := B.make w block) in × end.
assert (HinitialFormat : worldFormat (B.t.world_state initial)) by
(apply activate_preserves_format; exact Hformat).
assert (HinitialSupply : balanceInvariant (B.t.world_state initial) ∧
totalBalance (B.t.world_state initial) = totalBalance world).
{ apply activate_preserves_supply. exact Hinitial. }
match type of Hrun with context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_supply_reduction initial addr data (proj1 HinitialSupply) HinitialFormat) as HbeaconFailure;
pose proof (system_message_preserves_format initial addr data Hrevision HinitialFormat) as HbeaconFormat;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in HbeaconFailure, HbeaconFormat, Hrun.
destruct (supply_safety_dec (B.t.world_state afterBeacon) (totalBalance (B.t.world_state initial)))
as [[Hbeacon HbeaconTotal]|HbeaconBad].
2: { right. right. apply HbeaconFailure. exact HbeaconBad. }
match type of Hrun with context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_supply_reduction afterBeacon addr data Hbeacon HbeaconFormat) as HhistoryFailure;
pose proof (system_message_preserves_format afterBeacon addr data Hrevision HbeaconFormat) as HhistoryFormat;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in HhistoryFailure, HhistoryFormat, Hrun.
destruct (supply_safety_dec (B.t.world_state afterHistory) (totalBalance (B.t.world_state afterBeacon)))
as [[Hhistory HhistoryTotal]|HhistoryBad].
2: { right. right. apply HhistoryFailure. exact HhistoryBad. }
match type of Hrun with context [Result.List.fold_leftM ?step afterHistory ?txs] ⇒
destruct (Result.List.fold_leftM step afterHistory txs) as [afterTransactions|error] eqn:Htransactions
end.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
destruct (supply_safety_dec (B.t.world_state afterTransactions) (totalBalance (B.t.world_state afterHistory)))
as [[HtxFinal HtxTotal]|HtxBad].
2: {
destruct (dispatched_transactions_supply_reduction afterHistory _ afterTransactions Hrevision Htxs
Hhistory HhistoryFormat Htransactions HtxBad) as [Heoa|Hsys].
- left. exact Heoa.
- right. left. exact Hsys.
}
assert (HremainingBudget : totalBalance (B.t.world_state afterTransactions) + credits < 2^256).
{ pose proof (proj2 HinitialSupply). lia. }
pose proof (@withdrawals_preserve_supply_bound F afterTransactions
(Chain.Ethereum.Block.t.withdrawals block) HtxFinal Hwithdrawals HremainingBudget)
as [Hpaid HpaidTotal].
match type of Hrun with context [E.validate_block ?world ?block] ⇒
destruct (E.validate_block world block) as [[]|error]
end.
2: discriminate Hrun.
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|discriminate Hrun]|]
end.
all: injection Hrun as <-; exfalso; apply Hbad; split; [exact Hpaid|].
all: change (totalBalance (B.t.world_state (OCamlList.fold_left (@E.process_withdrawal F)
afterTransactions (Chain.Ethereum.Block.t.withdrawals block))) ≤ totalBalance world + credits).
all: destruct HpaidTotal as [HpaidTotal _]; rewrite HpaidTotal; fold credits;
pose proof (proj2 HinitialSupply); lia.
Qed.
End Execution.
Print Assumptions process_transaction_supply_reduction.
Print Assumptions transactions_supply_reduction.
Print Assumptions process_block_supply_reduction.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
balanceInvariant world → worldFormat world →
Forall (fun tx ⇒ 0 ≤ U.to_z (T.value tx) ∧ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx))
(Chain.Ethereum.Block.t.transactions block) →
Forall (fun wd ⇒ 0 ≤ Numeric.U64.to_z (Chain.Ethereum.Withdrawal.t.amount wd) < 2^64)
(Chain.Ethereum.Block.t.withdrawals block) →
let credits := Stdlib.Lists.List.fold_right (fun wd total ⇒ withdrawalWei wd + total) 0
(Chain.Ethereum.Block.t.withdrawals block) in
totalBalance world + credits < 2^256 →
@E.process_block F verify world block = inl post →
¬ (balanceInvariant post ∧ totalBalance post ≤ totalBalance world + credits) →
(∃ tx, List.In tx (Chain.Ethereum.Block.t.transactions block) ∧
callSupplyViolation (@E.Host.call_from_eoa F
tx)) ∨
callSupplyViolation (@E.Host.call_from_monad_system_transaction F) ∨
callSupplyViolation (@E.Host.call F).
Proof.
intros Hrevision Hinitial Hformat Htxs Hwithdrawals credits Hbudget Hrun Hbad.
unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalidation.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
match type of Hrun with context [B.make ?w block] ⇒ set (initial := B.make w block) in × end.
assert (HinitialFormat : worldFormat (B.t.world_state initial)) by
(apply activate_preserves_format; exact Hformat).
assert (HinitialSupply : balanceInvariant (B.t.world_state initial) ∧
totalBalance (B.t.world_state initial) = totalBalance world).
{ apply activate_preserves_supply. exact Hinitial. }
match type of Hrun with context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_supply_reduction initial addr data (proj1 HinitialSupply) HinitialFormat) as HbeaconFailure;
pose proof (system_message_preserves_format initial addr data Hrevision HinitialFormat) as HbeaconFormat;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in HbeaconFailure, HbeaconFormat, Hrun.
destruct (supply_safety_dec (B.t.world_state afterBeacon) (totalBalance (B.t.world_state initial)))
as [[Hbeacon HbeaconTotal]|HbeaconBad].
2: { right. right. apply HbeaconFailure. exact HbeaconBad. }
match type of Hrun with context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_supply_reduction afterBeacon addr data Hbeacon HbeaconFormat) as HhistoryFailure;
pose proof (system_message_preserves_format afterBeacon addr data Hrevision HbeaconFormat) as HhistoryFormat;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in HhistoryFailure, HhistoryFormat, Hrun.
destruct (supply_safety_dec (B.t.world_state afterHistory) (totalBalance (B.t.world_state afterBeacon)))
as [[Hhistory HhistoryTotal]|HhistoryBad].
2: { right. right. apply HhistoryFailure. exact HhistoryBad. }
match type of Hrun with context [Result.List.fold_leftM ?step afterHistory ?txs] ⇒
destruct (Result.List.fold_leftM step afterHistory txs) as [afterTransactions|error] eqn:Htransactions
end.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
destruct (supply_safety_dec (B.t.world_state afterTransactions) (totalBalance (B.t.world_state afterHistory)))
as [[HtxFinal HtxTotal]|HtxBad].
2: {
destruct (dispatched_transactions_supply_reduction afterHistory _ afterTransactions Hrevision Htxs
Hhistory HhistoryFormat Htransactions HtxBad) as [Heoa|Hsys].
- left. exact Heoa.
- right. left. exact Hsys.
}
assert (HremainingBudget : totalBalance (B.t.world_state afterTransactions) + credits < 2^256).
{ pose proof (proj2 HinitialSupply). lia. }
pose proof (@withdrawals_preserve_supply_bound F afterTransactions
(Chain.Ethereum.Block.t.withdrawals block) HtxFinal Hwithdrawals HremainingBudget)
as [Hpaid HpaidTotal].
match type of Hrun with context [E.validate_block ?world ?block] ⇒
destruct (E.validate_block world block) as [[]|error]
end.
2: discriminate Hrun.
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|discriminate Hrun]|]
end.
all: injection Hrun as <-; exfalso; apply Hbad; split; [exact Hpaid|].
all: change (totalBalance (B.t.world_state (OCamlList.fold_left (@E.process_withdrawal F)
afterTransactions (Chain.Ethereum.Block.t.withdrawals block))) ≤ totalBalance world + credits).
all: destruct HpaidTotal as [HpaidTotal _]; rewrite HpaidTotal; fold credits;
pose proof (proj2 HinitialSupply); lia.
Qed.
End Execution.
Print Assumptions process_transaction_supply_reduction.
Print Assumptions transactions_supply_reduction.
Print Assumptions process_block_supply_reduction.