Library QedkConcrete.blockreservewindow
Delayed configuration through actual block execution
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.
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)).
Theorem process_blocks_reserve_trace verify blocks :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
∀ world post,
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ∧
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
stringmaps.WellFormed (W.t.accounts post) ∧
A.t.code (readAccount post native) = Byte_string.Bytes.empty.
Proof.
intros Hrevision Hsignatures.
induction Hsignatures as [|block blocks Hsignatures Hrest IH]; intros world post Hmap Hcode Hrun.
- cbn [Result.List.fold_leftM] in Hrun. injection Hrun as <-.
∃ nil. split; [reflexivity|]. split; [constructor|]. split; assumption.
- change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next blocks) = inl post) in Hrun.
destruct (processBlock verify world block) as [next|error] eqn:Hstep; [|discriminate Hrun].
pose proof (@process_block_reserve_storage F
verify world block
Hrevision Hmap Hcode Hsignatures) as Hstorage.
cbn zeta in Hstorage.
rewrite Hstep in Hstorage.
destruct Hstorage as [HnextMap [HnextNonce [HnextCode [_ [updates Hupdates]]]]].
destruct (IH next post HnextMap HnextCode Hrun) as [trace [Hheights [Htrace [HpostMap HpostCode]]]].
∃ ((height block, updates) :: trace). split.
+ cbn [Lists.List.map fst]. rewrite Hheights. reflexivity.
+ split; [econstructor; eassumption|]. split; assumption.
Qed.
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.
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)).
Theorem process_blocks_reserve_trace verify blocks :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
∀ world post,
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ∧
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
stringmaps.WellFormed (W.t.accounts post) ∧
A.t.code (readAccount post native) = Byte_string.Bytes.empty.
Proof.
intros Hrevision Hsignatures.
induction Hsignatures as [|block blocks Hsignatures Hrest IH]; intros world post Hmap Hcode Hrun.
- cbn [Result.List.fold_leftM] in Hrun. injection Hrun as <-.
∃ nil. split; [reflexivity|]. split; [constructor|]. split; assumption.
- change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next blocks) = inl post) in Hrun.
destruct (processBlock verify world block) as [next|error] eqn:Hstep; [|discriminate Hrun].
pose proof (@process_block_reserve_storage F
verify world block
Hrevision Hmap Hcode Hsignatures) as Hstorage.
cbn zeta in Hstorage.
rewrite Hstep in Hstorage.
destruct Hstorage as [HnextMap [HnextNonce [HnextCode [_ [updates Hupdates]]]]].
destruct (IH next post HnextMap HnextCode Hrun) as [trace [Hheights [Htrace [HpostMap HpostCode]]]].
∃ ((height block, updates) :: trace). split.
+ cbn [Lists.List.map fst]. rewrite Hheights. reflexivity.
+ split; [econstructor; eassumption|]. split; assumption.
Qed.
Within the K-block unknown window, even a setting that lowers the
threshold cannot invalidate the snapshot used to admit a later fee.
The result includes empty blocks and does not require settings to be
made by transaction senders.
Theorem process_blocks_configured_window verify blocks world post :
(@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 block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ∧
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
∀ query target,
Forall (fun block ⇒ (height block ≤ target < height block + 3)%N) blocks →
Forall (fun step ⇒ Forall
(fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) (snd step)) trace →
configured post target query = configured world target query.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Hrun.
destruct (process_blocks_reserve_trace verify blocks Hrevision Hsignatures world post Hmap Hcode Hrun)
as [trace [Hheights [Htrace _]]].
∃ trace. split; [exact Hheights|]. split; [exact Htrace|].
intros query target Htimes Hslots.
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)).
pose proof (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes) as Hmapped.
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
assert (Hsafe : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N ∧
Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) (snd step)) trace).
{ apply Forall_forall. intros step Hin. split.
- apply Forall_forall with (x := step) in HtraceTimes; assumption.
- apply Forall_forall with (x := step) in Hslots; assumption. }
pose proof (reserve_trace_threshold _ _ _ query target Hstorage Hwords Htrace Hsafe) as Hthreshold.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
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))).
(@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 block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
∃ trace,
Lists.List.map fst trace = Lists.List.map height blocks ∧
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
∀ query target,
Forall (fun block ⇒ (height block ≤ target < height block + 3)%N) blocks →
Forall (fun step ⇒ Forall
(fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) (snd step)) trace →
configured post target query = configured world target query.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hcode Hstorage Hwords Hsignatures Hrun.
destruct (process_blocks_reserve_trace verify blocks Hrevision Hsignatures world post Hmap Hcode Hrun)
as [trace [Hheights [Htrace _]]].
∃ trace. split; [exact Hheights|]. split; [exact Htrace|].
intros query target Htimes Hslots.
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)).
pose proof (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes) as Hmapped.
exact (eq_ind_r (Forall (fun n ⇒ (n ≤ target < n + 3)%N)) Hmapped Hheights). }
assert (Hsafe : Forall (fun step ⇒ (fst step ≤ target < fst step + 3)%N ∧
Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) (snd step)) trace).
{ apply Forall_forall. intros step Hin. split.
- apply Forall_forall with (x := step) in HtraceTimes; assumption.
- apply Forall_forall with (x := step) in Hslots; assumption. }
pose proof (reserve_trace_threshold _ _ _ query target Hstorage Hwords Htrace Hsafe) as Hthreshold.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
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))).
This form makes no collision-freedom assumption. If the snapshot's
delayed threshold differs after concrete block execution, the proof
exhibits a finite setting witness containing a different account whose
encoded record overlaps the queried account's record.
Theorem process_blocks_configuration_change_has_collision verify blocks world post 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 block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
Forall (fun block ⇒ (height block ≤ target < height block + 3)%N) blocks →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
configured post target query ≠ configured world target query →
∃ trace block updates addr value i j,
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
List.In (block, 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 Htimes Hrun Hchanged.
destruct (process_blocks_reserve_trace verify blocks Hrevision Hsignatures world post Hmap Hcode 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)).
pose proof (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes) as Hmapped.
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 [Hthreshold|Hcollision].
- exfalso. apply Hchanged. unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
- destruct Hcollision as [n [updates [addr [value [i [j Hcollision]]]]]].
∃ trace, n, updates, addr, value, i, j. split; assumption.
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 block ⇒ Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block)) blocks →
Forall (fun block ⇒ (height block ≤ target < height block + 3)%N) blocks →
Result.List.fold_leftM (processBlock verify) world blocks = inl post →
configured post target query ≠ configured world target query →
∃ trace block updates addr value i j,
traceRelation (A.t.storage (readAccount world native)) trace (A.t.storage (readAccount post native)) ∧
List.In (block, 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 Htimes Hrun Hchanged.
destruct (process_blocks_reserve_trace verify blocks Hrevision Hsignatures world post Hmap Hcode 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)).
pose proof (proj2 (Forall_map height (fun n ⇒ (n ≤ target < n + 3)%N) blocks) Htimes) as Hmapped.
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 [Hthreshold|Hcollision].
- exfalso. apply Hchanged. unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
- destruct Hcollision as [n [updates [addr [value [i [j Hcollision]]]]]].
∃ trace, n, updates, addr, value, i, j. split; assumption.
Qed.
End Execution.