Library QedkConcrete.blocknumbers
Block heights derived from concrete validation
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionchecked
QedkConcrete.transactionsupply QedkConcrete.transactionformat
QedkConcrete.executionchecked QedkConcrete.assemblychecked
QedkConcrete.hashwords QedkConcrete.wordrange QedkConcrete.credits
QedkConcrete.reservewrites QedkConcrete.hostaccountformat QedkConcrete.supply.
Require Import QedkConcrete.blocktransactionentry.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module B := State.BlockState.
Module W := State.WorldState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation params := args.(Host.Instantiate.ChainParams).
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)}.
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 processBlock := (@E.process_block F).
Local Abbreviation height := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header block)).
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionchecked
QedkConcrete.transactionsupply QedkConcrete.transactionformat
QedkConcrete.executionchecked QedkConcrete.assemblychecked
QedkConcrete.hashwords QedkConcrete.wordrange QedkConcrete.credits
QedkConcrete.reservewrites QedkConcrete.hostaccountformat QedkConcrete.supply.
Require Import QedkConcrete.blocktransactionentry.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module B := State.BlockState.
Module W := State.WorldState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation params := args.(Host.Instantiate.ChainParams).
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)}.
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 processBlock := (@E.process_block F).
Local Abbreviation height := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header block)).
The ordering invariant uses zero for an empty history. Validation uses
its own generated opaque default in that case; no property of that
exceptional value, other than its natural-number height, is needed.
Local Abbreviation parentHeight := (fun world ⇒
match W.t.history world with [] ⇒ 0%N | parent :: _ ⇒ height parent end).
Local Abbreviation validationParentHeight := (fun world block ⇒
height (@Result.List.hd Chain.Ethereum.Block.t
(@E._rocq_fallback_validate_block_0 F block) (W.t.history world))).
Lemma validated_block_number world block :
@E.validate_block F world block = inl tt →
height block = (validationParentHeight world block + 1)%N.
Proof.
intro Hvalid. unfold E.validate_block in Hvalid. cbn zeta in Hvalid.
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hvalid.
change (@Result.when_) with (fun (Error : Set) (condition : bool) (failure : unit + Error) ⇒
if condition then failure else inl tt) in Hvalid.
match type of Hvalid with context [Support.UintN.op_ltgt ?n ?parent] ⇒
destruct (Support.UintN.op_ltgt n parent) eqn:Hnumber
end.
- discriminate Hvalid.
- apply Bool.negb_false_iff in Hnumber. apply N.eqb_eq in Hnumber. exact Hnumber.
Qed.
Lemma validated_block_later world block :
@E.validate_block F world block = inl tt →
(parentHeight world < height block)%N.
Proof.
intro Hvalid. pose proof (validated_block_number world block Hvalid) as Hnumber.
cbv beta in Hnumber |- ×.
destruct (W.t.history world) as [|parent rest].
- cbn in Hnumber |- ×. lia.
- change (height block = (height parent + 1)%N) in Hnumber. cbn. lia.
Qed.
Lemma transactions_current_block block txs post :
Result.List.fold_leftM (@E.process_transaction F) block txs = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
revert block. induction txs as [|tx txs IH]; intros block Hrun.
- injection Hrun as <-. reflexivity.
- 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;
[|discriminate Hrun].
rewrite (IH next Hrun). exact (process_transaction_current_block block tx next Hstep).
Qed.
Lemma dispatched_transactions_current_block block txs post :
Result.List.fold_leftM (@E.dispatch_transaction F) block txs = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
revert block. induction txs as [|tx txs IH]; intros block Hrun.
- injection Hrun as <-. reflexivity.
- 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].
rewrite (IH next Hrun). exact (dispatch_transaction_current_block block tx next Hstep).
Qed.
Lemma withdrawals_current_block block withdrawals :
B.t.current_block (Result.List.fold_left (@E.process_withdrawal F) block withdrawals) =
B.t.current_block block.
Proof.
revert block. induction withdrawals as [|withdrawal withdrawals IH]; intro block.
- reflexivity.
- change (B.t.current_block (Result.List.fold_left (@E.process_withdrawal F)
(@E.process_withdrawal F block withdrawal) withdrawals) = B.t.current_block block).
rewrite IH. reflexivity.
Qed.
Lemma process_block_success_validated verify world block post :
processBlock verify world block = inl post →
@E.validate_block F world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid;
[reflexivity|discriminate Hrun].
Qed.
Lemma process_block_transaction_error_validated verify world block details :
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
@E.validate_block F world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
- reflexivity.
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (@validate_block_no_transaction_error F world block details Hvalid).
Qed.
Theorem process_block_numbers verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inl post →
height block = (validationParentHeight world block + 1)%N ∧ parentHeight post = height block.
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid; [|discriminate Hrun].
pose proof (validated_block_number world block Hvalid) as Hnumber.
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
assert (Hentry : B.t.current_block entry = block) by
(exact (@block_transaction_entry_header F world block));
destruct (Result.List.fold_leftM step entry txs) as [after|error] eqn:Htxs
end.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
pose proof (dispatched_transactions_current_block _ _ _ Htxs) as Hcurrent.
rewrite Hentry in Hcurrent.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
destruct (E.validate_block w b) as [[]|error] eqn:HfinalValid;
[pose proof (validated_block_number w b HfinalValid) as HfinalNumber|]
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 <-; split; [exact Hnumber|].
all: change (height (B.finalize_current_block
(Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))) = height block).
all: change (height (B.t.current_block
(Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))) = height block).
all: rewrite withdrawals_current_block, Hcurrent; reflexivity.
Qed.
Theorem process_block_transaction_error_number verify world block details :
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
height block = (validationParentHeight world block + 1)%N.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
- exact (validated_block_number world block Hvalid).
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (@validate_block_no_transaction_error F world block details Hvalid).
Qed.
Lemma result_fold_leftM_app {X Y Err : Set} (step : X → Y → X + Err) first last start :
Result.List.fold_leftM step start (first ++ last) =
match Result.List.fold_leftM step start first with
| inl middle ⇒ Result.List.fold_leftM step middle last | inr error ⇒ inr error end.
Proof.
revert start. induction first as [|value first IH]; intro start; [reflexivity|].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next (first ++ last)) =
match Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next first) with
| inl middle ⇒ Result.List.fold_leftM step middle last | inr error ⇒ inr error end).
destruct (step start value) as [next|error]; [exact (IH next)|reflexivity].
Qed.
Theorem process_blocks_numbers verify blocks :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
∀ world post, Result.List.fold_leftM (processBlock verify) world blocks = inl post →
Forall (fun block ⇒ (height block ≤ parentHeight post)%N) blocks ∧
(parentHeight world ≤ parentHeight post)%N.
Proof.
intro Hrevision. induction blocks as [|block blocks IH]; intros world post Hrun.
- injection Hrun as <-. split; [constructor|lia].
- change (Result.op_letdollar (processBlock verify world block)
(fun reached ⇒ Result.List.fold_leftM (processBlock verify) reached blocks) = inl post) in Hrun.
destruct (processBlock verify world block) as [reached|error] eqn:Hstep; [|discriminate Hrun].
destruct (process_block_numbers verify world block reached Hrevision Hstep) as [Hnumber Hreached].
pose proof (validated_block_later world block
(process_block_success_validated verify world block reached Hstep)) as Hlater.
destruct (IH reached post Hrun) as [Hblocks Hlast].
split; [constructor; [lia|exact Hblocks]|lia].
Qed.
match W.t.history world with [] ⇒ 0%N | parent :: _ ⇒ height parent end).
Local Abbreviation validationParentHeight := (fun world block ⇒
height (@Result.List.hd Chain.Ethereum.Block.t
(@E._rocq_fallback_validate_block_0 F block) (W.t.history world))).
Lemma validated_block_number world block :
@E.validate_block F world block = inl tt →
height block = (validationParentHeight world block + 1)%N.
Proof.
intro Hvalid. unfold E.validate_block in Hvalid. cbn zeta in Hvalid.
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hvalid.
change (@Result.when_) with (fun (Error : Set) (condition : bool) (failure : unit + Error) ⇒
if condition then failure else inl tt) in Hvalid.
match type of Hvalid with context [Support.UintN.op_ltgt ?n ?parent] ⇒
destruct (Support.UintN.op_ltgt n parent) eqn:Hnumber
end.
- discriminate Hvalid.
- apply Bool.negb_false_iff in Hnumber. apply N.eqb_eq in Hnumber. exact Hnumber.
Qed.
Lemma validated_block_later world block :
@E.validate_block F world block = inl tt →
(parentHeight world < height block)%N.
Proof.
intro Hvalid. pose proof (validated_block_number world block Hvalid) as Hnumber.
cbv beta in Hnumber |- ×.
destruct (W.t.history world) as [|parent rest].
- cbn in Hnumber |- ×. lia.
- change (height block = (height parent + 1)%N) in Hnumber. cbn. lia.
Qed.
Lemma transactions_current_block block txs post :
Result.List.fold_leftM (@E.process_transaction F) block txs = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
revert block. induction txs as [|tx txs IH]; intros block Hrun.
- injection Hrun as <-. reflexivity.
- 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;
[|discriminate Hrun].
rewrite (IH next Hrun). exact (process_transaction_current_block block tx next Hstep).
Qed.
Lemma dispatched_transactions_current_block block txs post :
Result.List.fold_leftM (@E.dispatch_transaction F) block txs = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
revert block. induction txs as [|tx txs IH]; intros block Hrun.
- injection Hrun as <-. reflexivity.
- 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].
rewrite (IH next Hrun). exact (dispatch_transaction_current_block block tx next Hstep).
Qed.
Lemma withdrawals_current_block block withdrawals :
B.t.current_block (Result.List.fold_left (@E.process_withdrawal F) block withdrawals) =
B.t.current_block block.
Proof.
revert block. induction withdrawals as [|withdrawal withdrawals IH]; intro block.
- reflexivity.
- change (B.t.current_block (Result.List.fold_left (@E.process_withdrawal F)
(@E.process_withdrawal F block withdrawal) withdrawals) = B.t.current_block block).
rewrite IH. reflexivity.
Qed.
Lemma process_block_success_validated verify world block post :
processBlock verify world block = inl post →
@E.validate_block F world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid;
[reflexivity|discriminate Hrun].
Qed.
Lemma process_block_transaction_error_validated verify world block details :
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
@E.validate_block F world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
- reflexivity.
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (@validate_block_no_transaction_error F world block details Hvalid).
Qed.
Theorem process_block_numbers verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inl post →
height block = (validationParentHeight world block + 1)%N ∧ parentHeight post = height block.
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid; [|discriminate Hrun].
pose proof (validated_block_number world block Hvalid) as Hnumber.
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
assert (Hentry : B.t.current_block entry = block) by
(exact (@block_transaction_entry_header F world block));
destruct (Result.List.fold_leftM step entry txs) as [after|error] eqn:Htxs
end.
2: discriminate Hrun.
cbn beta iota zeta in Hrun.
pose proof (dispatched_transactions_current_block _ _ _ Htxs) as Hcurrent.
rewrite Hentry in Hcurrent.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
destruct (E.validate_block w b) as [[]|error] eqn:HfinalValid;
[pose proof (validated_block_number w b HfinalValid) as HfinalNumber|]
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 <-; split; [exact Hnumber|].
all: change (height (B.finalize_current_block
(Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))) = height block).
all: change (height (B.t.current_block
(Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))) = height block).
all: rewrite withdrawals_current_block, Hcurrent; reflexivity.
Qed.
Theorem process_block_transaction_error_number verify world block details :
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
height block = (validationParentHeight world block + 1)%N.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
- exact (validated_block_number world block Hvalid).
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (@validate_block_no_transaction_error F world block details Hvalid).
Qed.
Lemma result_fold_leftM_app {X Y Err : Set} (step : X → Y → X + Err) first last start :
Result.List.fold_leftM step start (first ++ last) =
match Result.List.fold_leftM step start first with
| inl middle ⇒ Result.List.fold_leftM step middle last | inr error ⇒ inr error end.
Proof.
revert start. induction first as [|value first IH]; intro start; [reflexivity|].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next (first ++ last)) =
match Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next first) with
| inl middle ⇒ Result.List.fold_leftM step middle last | inr error ⇒ inr error end).
destruct (step start value) as [next|error]; [exact (IH next)|reflexivity].
Qed.
Theorem process_blocks_numbers verify blocks :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
∀ world post, Result.List.fold_leftM (processBlock verify) world blocks = inl post →
Forall (fun block ⇒ (height block ≤ parentHeight post)%N) blocks ∧
(parentHeight world ≤ parentHeight post)%N.
Proof.
intro Hrevision. induction blocks as [|block blocks IH]; intros world post Hrun.
- injection Hrun as <-. split; [constructor|lia].
- change (Result.op_letdollar (processBlock verify world block)
(fun reached ⇒ Result.List.fold_leftM (processBlock verify) reached blocks) = inl post) in Hrun.
destruct (processBlock verify world block) as [reached|error] eqn:Hstep; [|discriminate Hrun].
destruct (process_block_numbers verify world block reached Hrevision Hstep) as [Hnumber Hreached].
pose proof (validated_block_later world block
(process_block_success_validated verify world block reached Hstep)) as Hlater.
destruct (IH reached post Hrun) as [Hblocks Hlast].
split; [constructor; [lia|exact Hblocks]|lia].
Qed.
A prefix before a transaction-validation error cannot contain a block
with a bad number: that would have stopped execution with a block error.
This derives chronological order even though reserve admission itself
does not validate headers.
Theorem reached_block_follows_previous verify blocks world before block after reached details :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
Result.List.fold_leftM (processBlock verify) world blocks = inr (Execution.Error.Invalid_transaction details) →
Forall (fun earlier ⇒ (height earlier < height block)%N) before.
Proof.
intros Hrevision Hsplit Hprefix Hrun.
rewrite Hsplit, result_fold_leftM_app, Hprefix in Hrun.
change (Result.op_letdollar (processBlock verify reached block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next after) =
inr (Execution.Error.Invalid_transaction details)) in Hrun.
assert (Hnumber : (parentHeight reached < height block)%N).
{ destruct (processBlock verify reached block) as [post|error] eqn:Hstep.
- apply validated_block_later. exact (process_block_success_validated verify reached block post Hstep).
- cbn in Hrun. injection Hrun as Heq. subst error.
apply validated_block_later. exact (process_block_transaction_error_validated verify reached block details Hstep). }
destruct (process_blocks_numbers verify before Hrevision world reached Hprefix) as [Hnumbers _].
eapply Forall_impl; [|exact Hnumbers]. intros earlier Hle. cbv beta in Hnumber, Hle |- ×. lia.
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
Result.List.fold_leftM (processBlock verify) world blocks = inr (Execution.Error.Invalid_transaction details) →
Forall (fun earlier ⇒ (height earlier < height block)%N) before.
Proof.
intros Hrevision Hsplit Hprefix Hrun.
rewrite Hsplit, result_fold_leftM_app, Hprefix in Hrun.
change (Result.op_letdollar (processBlock verify reached block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next after) =
inr (Execution.Error.Invalid_transaction details)) in Hrun.
assert (Hnumber : (parentHeight reached < height block)%N).
{ destruct (processBlock verify reached block) as [post|error] eqn:Hstep.
- apply validated_block_later. exact (process_block_success_validated verify reached block post Hstep).
- cbn in Hrun. injection Hrun as Heq. subst error.
apply validated_block_later. exact (process_block_transaction_error_validated verify reached block details Hstep). }
destruct (process_blocks_numbers verify before Hrevision world reached Hprefix) as [Hnumbers _].
eapply Forall_impl; [|exact Hnumbers]. intros earlier Hle. cbv beta in Hnumber, Hle |- ×. lia.
Qed.
Reaching a transaction requires successful preceding blocks and validation
of its block header, not success of the transaction or the rest of its
block. These facts already fix the order of every earlier block.
Lemma reached_window_block_number verify before :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
∀ world reached last,
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached last = inl tt →
∀ prefix current suffix middle,
before ++ (last :: nil) = prefix ++ current :: suffix →
Result.List.fold_leftM (processBlock verify) world prefix = inl middle →
height current = (validationParentHeight middle current + 1)%N.
Proof.
intro Hrevision. induction before as [|block before IH];
intros world reached last Hrun Hvalid prefix current suffix middle Hsplit Hprefix.
- cbn [app] in Hsplit. injection Hrun as <-.
destruct prefix as [|head tail].
+ cbn [app] in Hsplit. injection Hsplit as <- Hsuffix.
injection Hprefix as <-. exact (validated_block_number world last Hvalid).
+ cbn [app] in Hsplit. injection Hsplit as Hhead Htail.
destruct tail; discriminate Htail.
- change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next before) = inl reached) in Hrun.
destruct (processBlock verify world block) as [next|error] eqn:Hstep; [|discriminate Hrun].
destruct prefix as [|head tail].
+ cbn [app] in Hsplit. injection Hsplit as <- Hsuffix.
injection Hprefix as <-.
exact (proj1 (process_block_numbers verify world block next Hrevision Hstep)).
+ cbn [app] in Hsplit. injection Hsplit as <- Htail.
change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next tail) = inl middle) in Hprefix.
rewrite Hstep in Hprefix.
exact (IH next reached last Hrun Hvalid tail current suffix middle Htail Hprefix).
Qed.
Theorem reached_window_block_follows_previous verify before world reached last prefix current suffix middle :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached last = inl tt →
before ++ (last :: nil) = prefix ++ current :: suffix →
Result.List.fold_leftM (processBlock verify) world prefix = inl middle →
Forall (fun earlier ⇒ (height earlier < height current)%N) prefix.
Proof.
intros Hrevision Hrun Hvalid Hsplit Hprefix.
pose proof (reached_window_block_number verify before Hrevision world reached last Hrun Hvalid
prefix current suffix middle Hsplit Hprefix) as Hnumber.
destruct (process_blocks_numbers verify prefix Hrevision world middle Hprefix) as [Hnumbers _].
assert (Hlater : (parentHeight middle < height current)%N).
{ cbv beta in Hnumber |- ×.
destruct (W.t.history middle) as [|parent rest].
- cbn in Hnumber |- ×. lia.
- change (height current = (height parent + 1)%N) in Hnumber. cbn. lia. }
eapply Forall_impl; [|exact Hnumbers]. intros earlier Hle. cbv beta in Hnumber, Hle |- ×. lia.
Qed.
End Execution.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
∀ world reached last,
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached last = inl tt →
∀ prefix current suffix middle,
before ++ (last :: nil) = prefix ++ current :: suffix →
Result.List.fold_leftM (processBlock verify) world prefix = inl middle →
height current = (validationParentHeight middle current + 1)%N.
Proof.
intro Hrevision. induction before as [|block before IH];
intros world reached last Hrun Hvalid prefix current suffix middle Hsplit Hprefix.
- cbn [app] in Hsplit. injection Hrun as <-.
destruct prefix as [|head tail].
+ cbn [app] in Hsplit. injection Hsplit as <- Hsuffix.
injection Hprefix as <-. exact (validated_block_number world last Hvalid).
+ cbn [app] in Hsplit. injection Hsplit as Hhead Htail.
destruct tail; discriminate Htail.
- change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next before) = inl reached) in Hrun.
destruct (processBlock verify world block) as [next|error] eqn:Hstep; [|discriminate Hrun].
destruct prefix as [|head tail].
+ cbn [app] in Hsplit. injection Hsplit as <- Hsuffix.
injection Hprefix as <-.
exact (proj1 (process_block_numbers verify world block next Hrevision Hstep)).
+ cbn [app] in Hsplit. injection Hsplit as <- Htail.
change (Result.op_letdollar (processBlock verify world block)
(fun next ⇒ Result.List.fold_leftM (processBlock verify) next tail) = inl middle) in Hprefix.
rewrite Hstep in Hprefix.
exact (IH next reached last Hrun Hvalid tail current suffix middle Htail Hprefix).
Qed.
Theorem reached_window_block_follows_previous verify before world reached last prefix current suffix middle :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached last = inl tt →
before ++ (last :: nil) = prefix ++ current :: suffix →
Result.List.fold_leftM (processBlock verify) world prefix = inl middle →
Forall (fun earlier ⇒ (height earlier < height current)%N) prefix.
Proof.
intros Hrevision Hrun Hvalid Hsplit Hprefix.
pose proof (reached_window_block_number verify before Hrevision world reached last Hrun Hvalid
prefix current suffix middle Hsplit Hprefix) as Hnumber.
destruct (process_blocks_numbers verify prefix Hrevision world middle Hprefix) as [Hnumbers _].
assert (Hlater : (parentHeight middle < height current)%N).
{ cbv beta in Hnumber |- ×.
destruct (W.t.history middle) as [|parent rest].
- cbn in Hnumber |- ×. lia.
- change (height current = (height parent + 1)%N) in Hnumber. cbn. lia. }
eapply Forall_impl; [|exact Hnumbers]. intros earlier Hle. cbv beta in Hnumber, Hle |- ×. lia.
Qed.
End Execution.