Library QedkConcrete.blockprefixstorage
Reserve configuration at reached transaction prefixes
From Stdlib Require Import List String ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.protectedstorageboundary
QedkConcrete.protectedstorage QedkConcrete.protectedstoragenative
QedkConcrete.executionreservestorage QedkConcrete.transactionhistory
QedkConcrete.hostframe QedkConcrete.worldaccounts QedkConcrete.validation
QedkConcrete.emptyinghistory QedkConcrete.authorizationcode
QedkConcrete.transactionfinalize QedkConcrete.transactionsupply
QedkConcrete.transactionchecked QedkConcrete.hostcode QedkConcrete.reservestorage.
Require Import QedkConcrete.transactionreservestorage QedkConcrete.reservewindowtrace
QedkConcrete.hoststoragewords QedkConcrete.reserveencoding.
Require Import QedkConcrete.blocktransactionentry QedkConcrete.hostcode
QedkConcrete.blockreservewindow.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Module E := Execution.Make.
Module B := State.BlockState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation reachable := (@reachableReserveStorage).
Local Abbreviation worldProtected := (@worldProtectedStorage native).
Local Abbreviation protected := (@protectedStorage native).
Local Abbreviation blockNumber := (fun b ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block b))).
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)}.
Local Abbreviation prefix := (@transactionPrefix F).
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}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Local Abbreviation writes := (@reserveStorageWrites).
Local Abbreviation readConfig := (@Reserve_balance.stored_config).
Local Abbreviation slotsDisjoint := (@reserveencoding.configSlotsDisjoint).
Local Abbreviation active := (@Reserve_config.active).
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
Local Abbreviation traceRelation := (@reserveStorageTrace).
Local Abbreviation processBlock := (@E.process_block F).
Local Abbreviation height := (fun block ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block)).
Local Abbreviation blockEntry := (@blockTransactionEntry F).
Local Abbreviation dispatchTransaction := (@E.dispatch_transaction F).
Lemma block_entry_reserve_storage world block :
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (height block) (A.t.storage (readAccount world native)) (height block))
(B.t.world_state (blockEntry world block)).
Proof using F.
intros Hmap Hempty Hrevision. unfold blockTransactionEntry. cbn zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
set (initialStorage := A.t.storage (readAccount world native)).
set (n := height block).
assert (Hinitial : worldProtected (reachable n initialStorage n) (B.t.world_state initial)).
{ pose proof (@active_account world Hmap) as [Hstorage Hnonce].
split; [apply account_write_wellformed; exact Hmap|].
split; [exact Hnonce|]. split.
- change (A.t.code (readAccount (B.t.world_state initial) native) = Byte_string.Bytes.empty).
unfold initial. cbn [B.make B.t.world_state].
unfold Reserve_balance.activate_precompile. cbv beta zeta.
change (A.t.code (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some false) native)
(A.t.with_nonce (Numeric.U64.max (A.t.nonce (readAccount world native))
(@Numeric.U64.one)) (readAccount world native))) native) = Byte_string.Bytes.empty).
cbv beta. rewrite account_write_same_code by (first [exact Hmap|reflexivity]). exact Hempty.
- split; [reflexivity|]. ∃ nil. unfold initial. cbn [B.make B.t.world_state].
match goal with |- ?relation ?output ⇒ change (output = initialStorage) in Hstorage end.
rewrite Hstorage. constructor. }
assert (HinitialNumber : blockNumber initial = n) by reflexivity.
assert (Hinitial' : worldProtected (reachable (blockNumber initial) initialStorage (blockNumber initial))
(B.t.world_state initial)) by (rewrite HinitialNumber; exact Hinitial).
match goal with |- context [E.process_system_message initial ?systemAddr ?systemData] ⇒
pose proof (@system_message_only_reserve_settings F
initial systemAddr systemData initialStorage Hrevision Hinitial') as Hbeacon;
pose proof (@system_message_current_block F
initial systemAddr systemData) as HbeaconCurrent;
destruct (E.process_system_message initial systemAddr systemData) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon, HbeaconCurrent |- ×.
assert (HbeaconNumber : blockNumber afterBeacon = n).
{ cbv beta. rewrite HbeaconCurrent. exact HinitialNumber. }
assert (Hbeacon' : worldProtected (reachable (blockNumber afterBeacon) initialStorage (blockNumber afterBeacon))
(B.t.world_state afterBeacon)).
{ rewrite HbeaconNumber. rewrite HinitialNumber in Hbeacon. exact Hbeacon. }
match goal with |- context [E.process_system_message afterBeacon ?systemAddr ?systemData] ⇒
pose proof (@system_message_only_reserve_settings F
afterBeacon systemAddr systemData initialStorage Hrevision Hbeacon') as Hhistory
end.
cbv beta in Hhistory. rewrite HbeaconNumber in Hhistory. exact Hhistory.
Qed.
Theorem block_prefix_reserve_storage world block txs reached :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Result.List.fold_leftM dispatchTransaction (blockEntry world block) txs = inl reached →
∃ updates, worldProtected
(writes (height block) (A.t.storage (readAccount world native)) updates) (B.t.world_state reached).
Proof.
intros Hrevision Hmap Hempty Hsignatures Hrun.
pose proof (block_entry_reserve_storage world block Hmap Hempty Hrevision) as Hinitial.
pose proof (@block_transaction_entry_header F
world block) as HentryHeader.
assert (Hinitial' : worldProtected (reachable (blockNumber (blockEntry world block))
(A.t.storage (readAccount world native)) (blockNumber (blockEntry world block)))
(B.t.world_state (blockEntry world block))).
{ cbv beta. rewrite HentryHeader. exact Hinitial. }
pose proof (@dispatched_transactions_only_reserve_settings F
(blockEntry world block) txs
(A.t.storage (readAccount world native)) Hrevision Hinitial'
ltac:(intros tx state validation Hin Hvalidation;
apply (@signature_exclusions_for_prefix F state tx validation native);
[apply Forall_forall with (x := tx) in Hsignatures; assumption|exact Hvalidation])) as Hpost.
rewrite Hrun in Hpost. destruct Hpost as [_ [HpostMap [Hnonce [Hcode [_ [updates Hwrites]]]]]].
cbv beta in Hwrites. rewrite HentryHeader in Hwrites.
∃ updates. split; [exact HpostMap|]. split; [exact Hnonce|]. split; assumption.
Qed.
Import ListNotations.
Theorem window_prefix_reserve_trace verify blocks world reached block txs state :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ++ [(height block)] ∧
traceRelation (A.t.storage (readAccount world native)) trace
(A.t.storage (readAccount (B.t.world_state state) native)).
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun.
destruct (@process_blocks_reserve_trace F
verify blocks Hrevision Hsignatures world reached Hmap Hcode Hblocks)
as [trace [Hheights [Htrace [HreachedMap HreachedCode]]]].
destruct (block_prefix_reserve_storage reached block txs state Hrevision HreachedMap HreachedCode Htxs Hrun)
as [updates [_ [_ [_ Hwrites]]]].
∃ (trace ++ [(height block, updates)]). split.
- rewrite map_app. cbn [Lists.List.map fst]. rewrite Hheights. reflexivity.
- eapply reserve_trace_app; [exact Htrace|]. econstructor; [exact Hwrites|constructor].
Qed.
Local Abbreviation key := (fun addr offset ⇒ @Numeric.U256.to_repr (@Numeric.U256.op_plus (@Reserve_balance.config_slot addr)
(@Numeric.U256.of_int offset))).
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.protectedstorageboundary
QedkConcrete.protectedstorage QedkConcrete.protectedstoragenative
QedkConcrete.executionreservestorage QedkConcrete.transactionhistory
QedkConcrete.hostframe QedkConcrete.worldaccounts QedkConcrete.validation
QedkConcrete.emptyinghistory QedkConcrete.authorizationcode
QedkConcrete.transactionfinalize QedkConcrete.transactionsupply
QedkConcrete.transactionchecked QedkConcrete.hostcode QedkConcrete.reservestorage.
Require Import QedkConcrete.transactionreservestorage QedkConcrete.reservewindowtrace
QedkConcrete.hoststoragewords QedkConcrete.reserveencoding.
Require Import QedkConcrete.blocktransactionentry QedkConcrete.hostcode
QedkConcrete.blockreservewindow.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Module E := Execution.Make.
Module B := State.BlockState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation reachable := (@reachableReserveStorage).
Local Abbreviation worldProtected := (@worldProtectedStorage native).
Local Abbreviation protected := (@protectedStorage native).
Local Abbreviation blockNumber := (fun b ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block b))).
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)}.
Local Abbreviation prefix := (@transactionPrefix F).
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}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Local Abbreviation writes := (@reserveStorageWrites).
Local Abbreviation readConfig := (@Reserve_balance.stored_config).
Local Abbreviation slotsDisjoint := (@reserveencoding.configSlotsDisjoint).
Local Abbreviation active := (@Reserve_config.active).
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
Local Abbreviation traceRelation := (@reserveStorageTrace).
Local Abbreviation processBlock := (@E.process_block F).
Local Abbreviation height := (fun block ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block)).
Local Abbreviation blockEntry := (@blockTransactionEntry F).
Local Abbreviation dispatchTransaction := (@E.dispatch_transaction F).
Lemma block_entry_reserve_storage world block :
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (height block) (A.t.storage (readAccount world native)) (height block))
(B.t.world_state (blockEntry world block)).
Proof using F.
intros Hmap Hempty Hrevision. unfold blockTransactionEntry. cbn zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
set (initialStorage := A.t.storage (readAccount world native)).
set (n := height block).
assert (Hinitial : worldProtected (reachable n initialStorage n) (B.t.world_state initial)).
{ pose proof (@active_account world Hmap) as [Hstorage Hnonce].
split; [apply account_write_wellformed; exact Hmap|].
split; [exact Hnonce|]. split.
- change (A.t.code (readAccount (B.t.world_state initial) native) = Byte_string.Bytes.empty).
unfold initial. cbn [B.make B.t.world_state].
unfold Reserve_balance.activate_precompile. cbv beta zeta.
change (A.t.code (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some false) native)
(A.t.with_nonce (Numeric.U64.max (A.t.nonce (readAccount world native))
(@Numeric.U64.one)) (readAccount world native))) native) = Byte_string.Bytes.empty).
cbv beta. rewrite account_write_same_code by (first [exact Hmap|reflexivity]). exact Hempty.
- split; [reflexivity|]. ∃ nil. unfold initial. cbn [B.make B.t.world_state].
match goal with |- ?relation ?output ⇒ change (output = initialStorage) in Hstorage end.
rewrite Hstorage. constructor. }
assert (HinitialNumber : blockNumber initial = n) by reflexivity.
assert (Hinitial' : worldProtected (reachable (blockNumber initial) initialStorage (blockNumber initial))
(B.t.world_state initial)) by (rewrite HinitialNumber; exact Hinitial).
match goal with |- context [E.process_system_message initial ?systemAddr ?systemData] ⇒
pose proof (@system_message_only_reserve_settings F
initial systemAddr systemData initialStorage Hrevision Hinitial') as Hbeacon;
pose proof (@system_message_current_block F
initial systemAddr systemData) as HbeaconCurrent;
destruct (E.process_system_message initial systemAddr systemData) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon, HbeaconCurrent |- ×.
assert (HbeaconNumber : blockNumber afterBeacon = n).
{ cbv beta. rewrite HbeaconCurrent. exact HinitialNumber. }
assert (Hbeacon' : worldProtected (reachable (blockNumber afterBeacon) initialStorage (blockNumber afterBeacon))
(B.t.world_state afterBeacon)).
{ rewrite HbeaconNumber. rewrite HinitialNumber in Hbeacon. exact Hbeacon. }
match goal with |- context [E.process_system_message afterBeacon ?systemAddr ?systemData] ⇒
pose proof (@system_message_only_reserve_settings F
afterBeacon systemAddr systemData initialStorage Hrevision Hbeacon') as Hhistory
end.
cbv beta in Hhistory. rewrite HbeaconNumber in Hhistory. exact Hhistory.
Qed.
Theorem block_prefix_reserve_storage world block txs reached :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Result.List.fold_leftM dispatchTransaction (blockEntry world block) txs = inl reached →
∃ updates, worldProtected
(writes (height block) (A.t.storage (readAccount world native)) updates) (B.t.world_state reached).
Proof.
intros Hrevision Hmap Hempty Hsignatures Hrun.
pose proof (block_entry_reserve_storage world block Hmap Hempty Hrevision) as Hinitial.
pose proof (@block_transaction_entry_header F
world block) as HentryHeader.
assert (Hinitial' : worldProtected (reachable (blockNumber (blockEntry world block))
(A.t.storage (readAccount world native)) (blockNumber (blockEntry world block)))
(B.t.world_state (blockEntry world block))).
{ cbv beta. rewrite HentryHeader. exact Hinitial. }
pose proof (@dispatched_transactions_only_reserve_settings F
(blockEntry world block) txs
(A.t.storage (readAccount world native)) Hrevision Hinitial'
ltac:(intros tx state validation Hin Hvalidation;
apply (@signature_exclusions_for_prefix F state tx validation native);
[apply Forall_forall with (x := tx) in Hsignatures; assumption|exact Hvalidation])) as Hpost.
rewrite Hrun in Hpost. destruct Hpost as [_ [HpostMap [Hnonce [Hcode [_ [updates Hwrites]]]]]].
cbv beta in Hwrites. rewrite HentryHeader in Hwrites.
∃ updates. split; [exact HpostMap|]. split; [exact Hnonce|]. split; assumption.
Qed.
Import ListNotations.
Theorem window_prefix_reserve_trace verify blocks world reached block txs state :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ++ [(height block)] ∧
traceRelation (A.t.storage (readAccount world native)) trace
(A.t.storage (readAccount (B.t.world_state state) native)).
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun.
destruct (@process_blocks_reserve_trace F
verify blocks Hrevision Hsignatures world reached Hmap Hcode Hblocks)
as [trace [Hheights [Htrace [HreachedMap HreachedCode]]]].
destruct (block_prefix_reserve_storage reached block txs state Hrevision HreachedMap HreachedCode Htxs Hrun)
as [updates [_ [_ [_ Hwrites]]]].
∃ (trace ++ [(height block, updates)]). split.
- rewrite map_app. cbn [Lists.List.map fst]. rewrite Hheights. reflexivity.
- eapply reserve_trace_app; [exact Htrace|]. econstructor; [exact Hwrites|constructor].
Qed.
Local Abbreviation key := (fun addr offset ⇒ @Numeric.U256.to_repr (@Numeric.U256.op_plus (@Reserve_balance.config_slot addr)
(@Numeric.U256.of_int offset))).
A possible disagreement at a candidate's entry is reduced to overlapping
configuration slots, not assumed away as a VM property. This includes
earlier complete blocks and the already processed part of the candidate's
block. Neither the candidate nor the rest of its block must succeed.
Theorem window_prefix_configuration_or_collision verify blocks world reached block txs state query target :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
storageWords (A.t.storage (readAccount world native)) →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Forall (fun b ⇒ (height b ≤ target < height b + 3)%N) blocks →
(height block ≤ target < height block + 3)%N →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
configured (B.t.world_state state) target query = configured world target query ∨
∃ trace n updates addr value i j,
traceRelation (A.t.storage (readAccount world native)) trace
(A.t.storage (readAccount (B.t.world_state state) native)) ∧
List.In (n, updates) trace ∧ List.In (addr,value) updates ∧ addr ≠ query ∧
(0 ≤ i < 3)%Z ∧ (0 ≤ j < 3)%Z ∧ key addr i = key query j.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Htxs Htimes Htime Hblocks Hrun.
destruct (window_prefix_reserve_trace verify blocks world reached block txs state
Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun) as [trace [Hheights Htrace]].
assert (HtraceTimes : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N) trace).
{ apply (proj1 (Forall_map fst (fun n ⇒ (n ≤ target < n + 3)%N) trace)).
assert (Hmapped : Forall (fun n ⇒ (n ≤ target < n + 3)%N)
(Lists.List.map height blocks ++ [height block])).
{ apply Forall_app. split.
- exact (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes).
- constructor; [exact Htime|constructor]. }
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
destruct (reserve_trace_threshold_or_collision _ _ _ query target Hstorage Hwords Htrace HtraceTimes)
as [Heq|Hcollision].
- left. unfold Reserve_balance.user_reserve_balance. f_equal. exact Heq.
- right. destruct Hcollision as [n [updates [addr [value [i [j Hcollision]]]]]].
∃ trace, n, updates, addr, value, i, j. split; assumption.
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
storageWords (A.t.storage (readAccount world native)) →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Forall (fun b ⇒ (height b ≤ target < height b + 3)%N) blocks →
(height block ≤ target < height block + 3)%N →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
configured (B.t.world_state state) target query = configured world target query ∨
∃ trace n updates addr value i j,
traceRelation (A.t.storage (readAccount world native)) trace
(A.t.storage (readAccount (B.t.world_state state) native)) ∧
List.In (n, updates) trace ∧ List.In (addr,value) updates ∧ addr ≠ query ∧
(0 ≤ i < 3)%Z ∧ (0 ≤ j < 3)%Z ∧ key addr i = key query j.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Htxs Htimes Htime Hblocks Hrun.
destruct (window_prefix_reserve_trace verify blocks world reached block txs state
Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun) as [trace [Hheights Htrace]].
assert (HtraceTimes : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N) trace).
{ apply (proj1 (Forall_map fst (fun n ⇒ (n ≤ target < n + 3)%N) trace)).
assert (Hmapped : Forall (fun n ⇒ (n ≤ target < n + 3)%N)
(Lists.List.map height blocks ++ [height block])).
{ apply Forall_app. split.
- exact (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes).
- constructor; [exact Htime|constructor]. }
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
destruct (reserve_trace_threshold_or_collision _ _ _ query target Hstorage Hwords Htrace HtraceTimes)
as [Heq|Hcollision].
- left. unfold Reserve_balance.user_reserve_balance. f_equal. exact Heq.
- right. destruct Hcollision as [n [updates [addr [value [i [j Hcollision]]]]]].
∃ trace, n, updates, addr, value, i, j. split; assumption.
Qed.
Every setting in this prefix is too recent to change the queried threshold.
This also holds if different addresses share a complete configuration
record: they cannot bypass its activation delay.
Theorem window_prefix_configuration verify blocks world reached block txs state query target :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
storageWords (A.t.storage (readAccount world native)) →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Forall (fun b ⇒ (height b ≤ target < height b + 3)%N) blocks →
(height block ≤ target < height block + 3)%N →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
configured (B.t.world_state state) target query = configured world target query.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Htxs Htimes Htime Hblocks Hrun.
destruct (window_prefix_reserve_trace verify blocks world reached block txs state
Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun) as [trace [Hheights Htrace]].
assert (HtraceTimes : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N) trace).
{ apply (proj1 (Forall_map fst (fun n ⇒ (n ≤ target < n + 3)%N) trace)).
assert (Hmapped : Forall (fun n ⇒ (n ≤ target < n + 3)%N)
(Lists.List.map height blocks ++ [height block])).
{ apply Forall_app. split.
- exact (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes).
- constructor; [exact Htime|constructor]. }
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
pose proof (reserve_trace_threshold_any_account _ _ _ query target
Hstorage Hwords Htrace HtraceTimes) as Heq.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Heq.
Qed.
End Execution.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
storageWords (A.t.storage (readAccount world native)) →
Forall (fun b ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions b)) blocks →
Forall (fun tx ⇒ @signaturesAvoidAddress F tx native) txs →
Forall (fun b ⇒ (height b ≤ target < height b + 3)%N) blocks →
(height block ≤ target < height block + 3)%N →
Result.List.fold_leftM (processBlock verify) world blocks = inl reached →
Result.List.fold_leftM dispatchTransaction (blockEntry reached block) txs = inl state →
configured (B.t.world_state state) target query = configured world target query.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Htxs Htimes Htime Hblocks Hrun.
destruct (window_prefix_reserve_trace verify blocks world reached block txs state
Hrevision Hmap Hcode Hsignatures Htxs Hblocks Hrun) as [trace [Hheights Htrace]].
assert (HtraceTimes : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N) trace).
{ apply (proj1 (Forall_map fst (fun n ⇒ (n ≤ target < n + 3)%N) trace)).
assert (Hmapped : Forall (fun n ⇒ (n ≤ target < n + 3)%N)
(Lists.List.map height blocks ++ [height block])).
{ apply Forall_app. split.
- exact (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes).
- constructor; [exact Htime|constructor]. }
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
pose proof (reserve_trace_threshold_any_account _ _ _ query target
Hstorage Hwords Htrace HtraceTimes) as Heq.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Heq.
Qed.
End Execution.