Library monadpure.reservebaldelayed
Single-proposer delayed reserves: shared model
Require Export monadpure.accountstate.
Set Default Goal Selector "!".
Open Scope N_scope.
Record EIP7702Authority := { del_from : option EvmAddr; del_to : EvmAddr }.
Set Default Goal Selector "!".
Open Scope N_scope.
Record EIP7702Authority := { del_from : option EvmAddr; del_to : EvmAddr }.
Processed authorization effects and protocol-derived fee metadata, not
additional sender-selected fields. The VM contracts use these fee bounds.
Record TxExtra := {
authorities : list EIP7702Authority;
indexInBlock : N;
feeFields : TxFeeFields;
storageFeeBound : N
}.
Definition Transaction : Type := block.transaction × TxExtra.
Definition TxWithHdr : Type := Transaction × BlockHeader.
Definition maxTxFee (t : TxWithHdr) : N :=
w256_to_N (block.tr_gas_limit t.1.1) ×
match feeFields t.1.2 with
| LegacyTxFee ⇒ w256_to_N (block.tr_gas_price t.1.1)
| FeeMarketTxFee cap tip ⇒
N.min cap ((match base_fee_per_gas t.2 with Some b ⇒ b | None ⇒ 0 end) + tip)
end.
Definition maxStorageFee (t : TxWithHdr) : N := storageFeeBound t.1.2.
Definition sender (t : TxWithHdr) : EvmAddr := tsender t.1.1.
Definition value (t : TxWithHdr) : N := w256_to_N (block.tr_value t.1.1).
Definition txBlockNum (t : TxWithHdr) : N := number t.2.
Definition ReserveBalUpdate : Type := list (EvmAddr × N).
Definition is_undelegation (a: EIP7702Authority) : bool :=
asbool (del_to a = 0).
Definition dels (txe: TxExtra) : list EvmAddr :=
flat_map (fun a ⇒ match del_from a with
| Some addr ⇒ if is_undelegation a then [] else [addr]
| None ⇒ []
end ) (authorities txe).
Definition undels (txe: TxExtra) : list EvmAddr :=
flat_map (fun a ⇒ match del_from a with
| Some addr ⇒ if is_undelegation a then [addr] else []
| None ⇒ []
end ) (authorities txe).
Definition addrsDelUndelByTx (tx: TxWithHdr) : list EvmAddr := (dels tx.1.2 ++undels tx.1.2).
Record ExtraAcState := {
lastTxInBlockIndex : option N;
lastDelUndelInBlockIndex : option N;
settledReserveBal : N;
pendingReserveBal : option (N × N)
}.
Definition ExtraAcStates := EvmAddr → ExtraAcState.
Definition AugmentedState : Type := StateOfAccounts × ExtraAcStates.
Definition balanceOfAcA (s : AugmentedState) (a : EvmAddr) : N := balanceOfAc s.1 a.
Definition EffReserveBals := EvmAddr → Z.
Section Delayed.
Variable K : N.
Hypothesis K_pos : 0 < K.
Definition indexWithinK (proj: ExtraAcState → option N) (state : ExtraAcStates) (tx: TxWithHdr) : bool :=
let startIndex := txBlockNum tx - (K-1) in
match proj (state (sender tx)) with
| Some index ⇒
asbool (startIndex ≤ index ≤ txBlockNum tx)
| None ⇒ false
end.
Definition existsTxWithinK (state : AugmentedState) (tx: TxWithHdr) : bool :=
indexWithinK lastTxInBlockIndex (state.2) tx.
Definition existsDelUndelTxWithinK (state : AugmentedState) (tx: TxWithHdr) : bool :=
indexWithinK lastDelUndelInBlockIndex (state.2) tx.
Definition senderNoRecentActivity
(preIntermediatesState : AugmentedState) (intermediates: list TxWithHdr) (candidateTx: TxWithHdr) : bool :=
let senderAddr := sender candidateTx in
let existsSameSenderTxInWindow :=
(existsTxWithinK preIntermediatesState candidateTx)
|| asbool (senderAddr ∈ map sender intermediates) in
let senderTouchedByDelUndel :=
asbool (senderAddr ∈ flat_map addrsDelUndelByTx intermediates) in
let consideredDelegated :=
(addrDelegated preIntermediatesState.1 senderAddr)
|| existsDelUndelTxWithinK preIntermediatesState candidateTx
|| senderTouchedByDelUndel in
(negb existsSameSenderTxInWindow) && (negb consideredDelegated).
Definition isAllowedToEmpty
(preIntermediatesState : AugmentedState) (intermediates: list TxWithHdr) (candidateTx: TxWithHdr) : bool :=
let consideredDelegated :=
(addrDelegated (preIntermediatesState.1) (sender candidateTx))
|| existsDelUndelTxWithinK preIntermediatesState candidateTx
|| asbool ((sender candidateTx) ∈ flat_map addrsDelUndelByTx (candidateTx::intermediates)) in
let existsSameSenderTxInWindow :=
(existsTxWithinK preIntermediatesState candidateTx)
|| asbool ((sender candidateTx) ∈ map sender intermediates) in
(negb consideredDelegated) && (negb existsSameSenderTxInWindow).
Definition delayedReserveBal (es: ExtraAcState) (n: N) : N :=
match pendingReserveBal es with
| Some (v, blk) ⇒
if asbool (blk + K ≤ n)
then v
else settledReserveBal es
| None ⇒ settledReserveBal es
end.
Definition delayedReserveBalOfAddr (s: ExtraAcStates) (addr : EvmAddr) (n: N) : N :=
delayedReserveBal (s addr) n.
Definition advanceEffReserveBals (s: AugmentedState) (erbs: EffReserveBals) (b: N) : EffReserveBals :=
fun addr ⇒ Z.min (erbs addr) (Z.of_N (delayedReserveBalOfAddr s.2 addr b)).
Definition isAllowedToEmptyExec
(state : AugmentedState) (tx: TxWithHdr) : bool :=
isAllowedToEmpty state [] tx.
Definition promotePendingReserveBal (es: ExtraAcState) (n: N) : ExtraAcState :=
match pendingReserveBal es with
| Some (v, blk) ⇒
if asbool (blk + K ≤ n)%N
then {|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := v;
pendingReserveBal := None;
|}
else es
| None ⇒ es
end.
Definition applyReserveBalUpdate (es: ExtraAcState) (n: N) (newRb: N) : ExtraAcState :=
match pendingReserveBal es with
| Some (_v, blk) ⇒
authorities : list EIP7702Authority;
indexInBlock : N;
feeFields : TxFeeFields;
storageFeeBound : N
}.
Definition Transaction : Type := block.transaction × TxExtra.
Definition TxWithHdr : Type := Transaction × BlockHeader.
Definition maxTxFee (t : TxWithHdr) : N :=
w256_to_N (block.tr_gas_limit t.1.1) ×
match feeFields t.1.2 with
| LegacyTxFee ⇒ w256_to_N (block.tr_gas_price t.1.1)
| FeeMarketTxFee cap tip ⇒
N.min cap ((match base_fee_per_gas t.2 with Some b ⇒ b | None ⇒ 0 end) + tip)
end.
Definition maxStorageFee (t : TxWithHdr) : N := storageFeeBound t.1.2.
Definition sender (t : TxWithHdr) : EvmAddr := tsender t.1.1.
Definition value (t : TxWithHdr) : N := w256_to_N (block.tr_value t.1.1).
Definition txBlockNum (t : TxWithHdr) : N := number t.2.
Definition ReserveBalUpdate : Type := list (EvmAddr × N).
Definition is_undelegation (a: EIP7702Authority) : bool :=
asbool (del_to a = 0).
Definition dels (txe: TxExtra) : list EvmAddr :=
flat_map (fun a ⇒ match del_from a with
| Some addr ⇒ if is_undelegation a then [] else [addr]
| None ⇒ []
end ) (authorities txe).
Definition undels (txe: TxExtra) : list EvmAddr :=
flat_map (fun a ⇒ match del_from a with
| Some addr ⇒ if is_undelegation a then [addr] else []
| None ⇒ []
end ) (authorities txe).
Definition addrsDelUndelByTx (tx: TxWithHdr) : list EvmAddr := (dels tx.1.2 ++undels tx.1.2).
Record ExtraAcState := {
lastTxInBlockIndex : option N;
lastDelUndelInBlockIndex : option N;
settledReserveBal : N;
pendingReserveBal : option (N × N)
}.
Definition ExtraAcStates := EvmAddr → ExtraAcState.
Definition AugmentedState : Type := StateOfAccounts × ExtraAcStates.
Definition balanceOfAcA (s : AugmentedState) (a : EvmAddr) : N := balanceOfAc s.1 a.
Definition EffReserveBals := EvmAddr → Z.
Section Delayed.
Variable K : N.
Hypothesis K_pos : 0 < K.
Definition indexWithinK (proj: ExtraAcState → option N) (state : ExtraAcStates) (tx: TxWithHdr) : bool :=
let startIndex := txBlockNum tx - (K-1) in
match proj (state (sender tx)) with
| Some index ⇒
asbool (startIndex ≤ index ≤ txBlockNum tx)
| None ⇒ false
end.
Definition existsTxWithinK (state : AugmentedState) (tx: TxWithHdr) : bool :=
indexWithinK lastTxInBlockIndex (state.2) tx.
Definition existsDelUndelTxWithinK (state : AugmentedState) (tx: TxWithHdr) : bool :=
indexWithinK lastDelUndelInBlockIndex (state.2) tx.
Definition senderNoRecentActivity
(preIntermediatesState : AugmentedState) (intermediates: list TxWithHdr) (candidateTx: TxWithHdr) : bool :=
let senderAddr := sender candidateTx in
let existsSameSenderTxInWindow :=
(existsTxWithinK preIntermediatesState candidateTx)
|| asbool (senderAddr ∈ map sender intermediates) in
let senderTouchedByDelUndel :=
asbool (senderAddr ∈ flat_map addrsDelUndelByTx intermediates) in
let consideredDelegated :=
(addrDelegated preIntermediatesState.1 senderAddr)
|| existsDelUndelTxWithinK preIntermediatesState candidateTx
|| senderTouchedByDelUndel in
(negb existsSameSenderTxInWindow) && (negb consideredDelegated).
Definition isAllowedToEmpty
(preIntermediatesState : AugmentedState) (intermediates: list TxWithHdr) (candidateTx: TxWithHdr) : bool :=
let consideredDelegated :=
(addrDelegated (preIntermediatesState.1) (sender candidateTx))
|| existsDelUndelTxWithinK preIntermediatesState candidateTx
|| asbool ((sender candidateTx) ∈ flat_map addrsDelUndelByTx (candidateTx::intermediates)) in
let existsSameSenderTxInWindow :=
(existsTxWithinK preIntermediatesState candidateTx)
|| asbool ((sender candidateTx) ∈ map sender intermediates) in
(negb consideredDelegated) && (negb existsSameSenderTxInWindow).
Definition delayedReserveBal (es: ExtraAcState) (n: N) : N :=
match pendingReserveBal es with
| Some (v, blk) ⇒
if asbool (blk + K ≤ n)
then v
else settledReserveBal es
| None ⇒ settledReserveBal es
end.
Definition delayedReserveBalOfAddr (s: ExtraAcStates) (addr : EvmAddr) (n: N) : N :=
delayedReserveBal (s addr) n.
Definition advanceEffReserveBals (s: AugmentedState) (erbs: EffReserveBals) (b: N) : EffReserveBals :=
fun addr ⇒ Z.min (erbs addr) (Z.of_N (delayedReserveBalOfAddr s.2 addr b)).
Definition isAllowedToEmptyExec
(state : AugmentedState) (tx: TxWithHdr) : bool :=
isAllowedToEmpty state [] tx.
Definition promotePendingReserveBal (es: ExtraAcState) (n: N) : ExtraAcState :=
match pendingReserveBal es with
| Some (v, blk) ⇒
if asbool (blk + K ≤ n)%N
then {|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := v;
pendingReserveBal := None;
|}
else es
| None ⇒ es
end.
Definition applyReserveBalUpdate (es: ExtraAcState) (n: N) (newRb: N) : ExtraAcState :=
match pendingReserveBal es with
| Some (_v, blk) ⇒
if multiple updates are applied in a single block, the latest wins
if asbool (blk = n)%N
then {|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := settledReserveBal es;
pendingReserveBal := Some (newRb, n)
|}
else es
| None ⇒
{|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := settledReserveBal es;
pendingReserveBal := Some (newRb, n)
|}
end.
Definition applyReserveBalUpdatesForAddr (es: ExtraAcState) (n: N) (addr: EvmAddr)
(updates: ReserveBalUpdate) : ExtraAcState :=
fold_left (fun st '(a, newRb) ⇒
if asbool (a = addr) then applyReserveBalUpdate st n newRb else st)
updates es.
Definition updateExtraStateBase (state : ExtraAcStates) (tx : TxWithHdr) : ExtraAcStates :=
fun a ⇒ {| lastTxInBlockIndex := if bool_decide (sender tx = a)
then Some (txBlockNum tx) else lastTxInBlockIndex (state a);
lastDelUndelInBlockIndex := if bool_decide (a ∈ addrsDelUndelByTx tx)
then Some (txBlockNum tx) else lastDelUndelInBlockIndex (state a);
settledReserveBal := settledReserveBal (state a);
pendingReserveBal := pendingReserveBal (state a) |}.
Definition updateExtraState (a: ExtraAcStates) (tx: TxWithHdr) (rbUpdate: ReserveBalUpdate) : ExtraAcStates :=
(fun addr ⇒
let oldes := (updateExtraStateBase a tx) addr in
let oldes' := promotePendingReserveBal oldes (txBlockNum tx) in
applyReserveBalUpdatesForAddr oldes' (txBlockNum tx) addr rbUpdate
).
Definition updateExtraStateNoReserve (a: ExtraAcStates) (tx: TxWithHdr) : ExtraAcStates :=
(fun addr ⇒
let oldes := updateExtraStateBase a tx addr in
promotePendingReserveBal oldes (txBlockNum tx)).
Variable evmExecTxCore : StateOfAccounts → TxWithHdr →
((StateOfAccounts × TxResult) × list EvmAddr) × ReserveBalUpdate.
Variable revertTx : StateOfAccounts → TxWithHdr → StateOfAccounts × TxResult.
Definition revertTxState (s: StateOfAccounts) (t: TxWithHdr) : StateOfAccounts :=
(revertTx s t).1.
Definition evmExecTxCoreState (s: StateOfAccounts) (t: TxWithHdr) : StateOfAccounts :=
(evmExecTxCore s t).1.1.1.
Definition finalBalSufficient (preTxState: AugmentedState) (postTxState : StateOfAccounts)
(t: TxWithHdr) (a: EvmAddr): bool :=
let ReserveBal := delayedReserveBalOfAddr preTxState.2 a (txBlockNum t) in
let erb:N := ReserveBal `min` (balanceOfAc preTxState.1 a) in
if isSC postTxState a
then true
else
if asbool (sender t =a)
then if isAllowedToEmptyExec preTxState t then true else asbool ((erb - maxTxFee t) ≤ balanceOfAc postTxState a)
else asbool (erb ≤ balanceOfAc postTxState a).
Definition allFinalBalSufficient (preTxState: AugmentedState) (postTxState : StateOfAccounts)
(changedAccounts: list EvmAddr) (t: TxWithHdr): bool:=
forallb (finalBalSufficient preTxState postTxState t) changedAccounts.
Definition execValidatedTx (s: AugmentedState) (t: TxWithHdr)
: AugmentedState × TxResult :=
let '(((postTxState, txr), changedAccounts), rbUpdate) := evmExecTxCore (s.1) t in
if (allFinalBalSufficient s postTxState changedAccounts t)
then ((postTxState, updateExtraState s.2 t rbUpdate), txr)
else
let (revState, revRes) := revertTx s.1 t in
((revState, updateExtraStateNoReserve s.2 t), revRes).
Definition validateTx (preTxState: StateOfAccounts) (tx: TxWithHdr): bool :=
asbool (maxTxFee tx ≤ balanceOfAc preTxState (sender tx)).
Definition txCannotCreateContractAtAddrs tx (eoasWithPrivateKey: list EvmAddr) :=
∀ s, let sf := (execValidatedTx s tx).1 in
∀ addr, addr ∈ eoasWithPrivateKey → isSC s.1 addr = false → isSC sf.1 addr = false.
Class EVMAssupmtions (transactions : list TxWithHdr) :=
{
balanceOfRevertSender: ∀ s tx,
maxTxFee tx ≤ balanceOfAc s (sender tx)
→ balanceOfAc (revertTxState s tx) (sender tx)
= balanceOfAc s (sender tx) - maxTxFee tx;
balanceOfRevertOther: ∀ s tx ac,
ac ≠ (sender tx)
→ balanceOfAc (revertTxState s tx) ac
= balanceOfAc s ac;
revertTxDelegationUpdCore: ∀ tx s,
let sf := (revertTxState s tx) in
(∀ ac, addrDelegated sf ac =
(addrDelegated s ac && asbool (ac ∉ (undels tx.1.2)))
|| asbool (ac ∈ (dels tx.1.2)));
execTxDelegationUpdCore: ∀ tx s,
let sf := (evmExecTxCoreState s tx) in
(∀ ac, addrDelegated sf ac =
(addrDelegated s ac && asbool (ac ∉ (undels tx.1.2)))
|| asbool (ac ∈ (dels tx.1.2)));
execTxSenderBalCore: ∀ tx s,
maxTxFee tx ≤ balanceOfAc s (sender tx) →
let sf := (evmExecTxCoreState s tx) in
addrDelegated sf (sender tx) = false
→ balanceOfAc s (sender tx) - ( maxTxFee tx + value tx + maxStorageFee tx) ≤ balanceOfAc sf (sender tx)
∨ balanceOfAc sf (sender tx) = balanceOfAc s (sender tx) - (maxTxFee tx);
then {|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := settledReserveBal es;
pendingReserveBal := Some (newRb, n)
|}
else es
| None ⇒
{|
lastTxInBlockIndex := lastTxInBlockIndex es;
lastDelUndelInBlockIndex := lastDelUndelInBlockIndex es;
settledReserveBal := settledReserveBal es;
pendingReserveBal := Some (newRb, n)
|}
end.
Definition applyReserveBalUpdatesForAddr (es: ExtraAcState) (n: N) (addr: EvmAddr)
(updates: ReserveBalUpdate) : ExtraAcState :=
fold_left (fun st '(a, newRb) ⇒
if asbool (a = addr) then applyReserveBalUpdate st n newRb else st)
updates es.
Definition updateExtraStateBase (state : ExtraAcStates) (tx : TxWithHdr) : ExtraAcStates :=
fun a ⇒ {| lastTxInBlockIndex := if bool_decide (sender tx = a)
then Some (txBlockNum tx) else lastTxInBlockIndex (state a);
lastDelUndelInBlockIndex := if bool_decide (a ∈ addrsDelUndelByTx tx)
then Some (txBlockNum tx) else lastDelUndelInBlockIndex (state a);
settledReserveBal := settledReserveBal (state a);
pendingReserveBal := pendingReserveBal (state a) |}.
Definition updateExtraState (a: ExtraAcStates) (tx: TxWithHdr) (rbUpdate: ReserveBalUpdate) : ExtraAcStates :=
(fun addr ⇒
let oldes := (updateExtraStateBase a tx) addr in
let oldes' := promotePendingReserveBal oldes (txBlockNum tx) in
applyReserveBalUpdatesForAddr oldes' (txBlockNum tx) addr rbUpdate
).
Definition updateExtraStateNoReserve (a: ExtraAcStates) (tx: TxWithHdr) : ExtraAcStates :=
(fun addr ⇒
let oldes := updateExtraStateBase a tx addr in
promotePendingReserveBal oldes (txBlockNum tx)).
Variable evmExecTxCore : StateOfAccounts → TxWithHdr →
((StateOfAccounts × TxResult) × list EvmAddr) × ReserveBalUpdate.
Variable revertTx : StateOfAccounts → TxWithHdr → StateOfAccounts × TxResult.
Definition revertTxState (s: StateOfAccounts) (t: TxWithHdr) : StateOfAccounts :=
(revertTx s t).1.
Definition evmExecTxCoreState (s: StateOfAccounts) (t: TxWithHdr) : StateOfAccounts :=
(evmExecTxCore s t).1.1.1.
Definition finalBalSufficient (preTxState: AugmentedState) (postTxState : StateOfAccounts)
(t: TxWithHdr) (a: EvmAddr): bool :=
let ReserveBal := delayedReserveBalOfAddr preTxState.2 a (txBlockNum t) in
let erb:N := ReserveBal `min` (balanceOfAc preTxState.1 a) in
if isSC postTxState a
then true
else
if asbool (sender t =a)
then if isAllowedToEmptyExec preTxState t then true else asbool ((erb - maxTxFee t) ≤ balanceOfAc postTxState a)
else asbool (erb ≤ balanceOfAc postTxState a).
Definition allFinalBalSufficient (preTxState: AugmentedState) (postTxState : StateOfAccounts)
(changedAccounts: list EvmAddr) (t: TxWithHdr): bool:=
forallb (finalBalSufficient preTxState postTxState t) changedAccounts.
Definition execValidatedTx (s: AugmentedState) (t: TxWithHdr)
: AugmentedState × TxResult :=
let '(((postTxState, txr), changedAccounts), rbUpdate) := evmExecTxCore (s.1) t in
if (allFinalBalSufficient s postTxState changedAccounts t)
then ((postTxState, updateExtraState s.2 t rbUpdate), txr)
else
let (revState, revRes) := revertTx s.1 t in
((revState, updateExtraStateNoReserve s.2 t), revRes).
Definition validateTx (preTxState: StateOfAccounts) (tx: TxWithHdr): bool :=
asbool (maxTxFee tx ≤ balanceOfAc preTxState (sender tx)).
Definition txCannotCreateContractAtAddrs tx (eoasWithPrivateKey: list EvmAddr) :=
∀ s, let sf := (execValidatedTx s tx).1 in
∀ addr, addr ∈ eoasWithPrivateKey → isSC s.1 addr = false → isSC sf.1 addr = false.
Class EVMAssupmtions (transactions : list TxWithHdr) :=
{
balanceOfRevertSender: ∀ s tx,
maxTxFee tx ≤ balanceOfAc s (sender tx)
→ balanceOfAc (revertTxState s tx) (sender tx)
= balanceOfAc s (sender tx) - maxTxFee tx;
balanceOfRevertOther: ∀ s tx ac,
ac ≠ (sender tx)
→ balanceOfAc (revertTxState s tx) ac
= balanceOfAc s ac;
revertTxDelegationUpdCore: ∀ tx s,
let sf := (revertTxState s tx) in
(∀ ac, addrDelegated sf ac =
(addrDelegated s ac && asbool (ac ∉ (undels tx.1.2)))
|| asbool (ac ∈ (dels tx.1.2)));
execTxDelegationUpdCore: ∀ tx s,
let sf := (evmExecTxCoreState s tx) in
(∀ ac, addrDelegated sf ac =
(addrDelegated s ac && asbool (ac ∉ (undels tx.1.2)))
|| asbool (ac ∈ (dels tx.1.2)));
execTxSenderBalCore: ∀ tx s,
maxTxFee tx ≤ balanceOfAc s (sender tx) →
let sf := (evmExecTxCoreState s tx) in
addrDelegated sf (sender tx) = false
→ balanceOfAc s (sender tx) - ( maxTxFee tx + value tx + maxStorageFee tx) ≤ balanceOfAc sf (sender tx)
∨ balanceOfAc sf (sender tx) = balanceOfAc s (sender tx) - (maxTxFee tx);
Only transaction signers, not arbitrary code-free addresses: a newly
created contract can selfdestruct without leaving post-state code.
As in VmSignerFrame, signer addresses represent key-controlled accounts,
excluding contract-creation collisions and protocol-only accounts such as
staking. Scoping this inherited rule weakens it; it does not constrain
contract balances or assume that execution passes the reserve check.
execTxCannotDebitNonDelegatedNonContractAccountsCore: ∀ tx s,
let sf := (evmExecTxCoreState s tx) in
∀ ac, ac ∈ map sender transactions → ac ≠ sender tx
→ (addrDelegated sf ac || isSC sf ac) = false
→ balanceOfAc s ac ≤ balanceOfAc sf ac;
changedAccountSetSound: ∀ tx s,
let '(((sf, sf_res), changedAccounts), _) := (evmExecTxCore s tx) in
(∀ ac, ac ∉ changedAccounts → sf ac = s ac);
}.
let sf := (evmExecTxCoreState s tx) in
∀ ac, ac ∈ map sender transactions → ac ≠ sender tx
→ (addrDelegated sf ac || isSC sf ac) = false
→ balanceOfAc s ac ≤ balanceOfAc sf ac;
changedAccountSetSound: ∀ tx s,
let '(((sf, sf_res), changedAccounts), _) := (evmExecTxCore s tx) in
(∀ ac, ac ∉ changedAccounts → sf ac = s ac);
}.
Lemma delayedReserveBal_promoteWithinK es (n0 n: N) :
(n0 ≤ n)%N →
(n < n0 + K)%N →
delayedReserveBal (promotePendingReserveBal es n0) n =
delayedReserveBal es n.
Proof using K K_pos.
intros Hle _Hlt.
unfold delayedReserveBal, promotePendingReserveBal.
destruct (pendingReserveBal es) as [[v blk]|] eqn:Hpend; simpl.
{ destruct (asbool (blk + K ≤ n0)%N) eqn:Hprom; simpl.
{ apply bool_decide_eq_true_1 in Hprom.
assert (blk + K ≤ n)%N by (eapply N.le_trans; [exact Hprom|exact Hle]).
rewrite bool_decide_true; [reflexivity|assumption]. }
rewrite Hpend. reflexivity. }
rewrite Hpend. reflexivity.
Qed.
Lemma delayedReserveBal_applyReserveBalUpdate_ltK es (n0 n: N) newRb :
(n < n0 + K)%N →
delayedReserveBal (applyReserveBalUpdate es n0 newRb) n = delayedReserveBal es n.
Proof using K K_pos.
intros Hlt.
unfold applyReserveBalUpdate.
destruct (pendingReserveBal es) as [[v blk]|] eqn:Hpend; simpl.
{ destruct (decide (blk = n0)) as [Hblock|Hblock].
{ rewrite bool_decide_true; [|exact Hblock].
unfold delayedReserveBal. simpl.
rewrite bool_decide_false; [|lia].
rewrite Hpend. simpl.
rewrite Hblock.
rewrite bool_decide_false; [reflexivity|lia]. }
rewrite bool_decide_false; [reflexivity|exact Hblock]. }
unfold delayedReserveBal. simpl.
rewrite bool_decide_false; [|lia].
rewrite Hpend. simpl. reflexivity.
Qed.
Lemma delayedReserveBal_applyReserveBalUpdatesForAddr_ltK es (n0 n: N) addr updates :
(n < n0 + K)%N →
delayedReserveBal (applyReserveBalUpdatesForAddr es n0 addr updates) n = delayedReserveBal es n.
Proof using K K_pos.
revert es.
induction updates as [|[a newRb] tl IH]; intros es Hlt; simpl; [reflexivity|].
case_bool_decide; simpl.
{ specialize (IH (applyReserveBalUpdate es n0 newRb) Hlt).
eapply transitivity; [exact IH|].
apply delayedReserveBal_applyReserveBalUpdate_ltK; exact Hlt. }
apply IH; exact Hlt.
Qed.
Lemma history_promote es n :
(lastTxInBlockIndex (promotePendingReserveBal es n),
lastDelUndelInBlockIndex (promotePendingReserveBal es n)) =
(lastTxInBlockIndex es, lastDelUndelInBlockIndex es).
Proof using All.
unfold promotePendingReserveBal.
destruct (pendingReserveBal es) as [[v b]|]; [case_bool_decide|]; reflexivity.
Qed.
Lemma history_apply es n a updates :
(lastTxInBlockIndex (applyReserveBalUpdatesForAddr es n a updates),
lastDelUndelInBlockIndex (applyReserveBalUpdatesForAddr es n a updates)) =
(lastTxInBlockIndex es, lastDelUndelInBlockIndex es).
Proof using All.
revert es. induction updates as [|[addr v] rest IH]; intros es; [reflexivity|].
cbn [applyReserveBalUpdatesForAddr fold_left]. case_bool_decide.
{ rewrite IH. unfold applyReserveBalUpdate.
destruct (pendingReserveBal es) as [[old b]|]; [case_bool_decide|]; reflexivity. }
apply IH.
Qed.
Lemma exec_history s tx a :
(lastTxInBlockIndex ((execValidatedTx s tx).1.2 a),
lastDelUndelInBlockIndex ((execValidatedTx s tx).1.2 a)) =
(if bool_decide (sender tx = a) then Some (txBlockNum tx)
else lastTxInBlockIndex (s.2 a),
if bool_decide (a ∈ addrsDelUndelByTx tx) then Some (txBlockNum tx)
else lastDelUndelInBlockIndex (s.2 a)).
Proof using All.
unfold execValidatedTx.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx).
{ cbn [fst snd]. unfold updateExtraState.
rewrite history_apply history_promote. reflexivity. }
destruct (revertTx s.1 tx). cbn [fst snd]. unfold updateExtraStateNoReserve.
rewrite history_promote. reflexivity.
Qed.
Lemma delayedReserveBalOfAddrWithinK s tx a n :
txBlockNum tx ≤ n → n < txBlockNum tx + K →
delayedReserveBalOfAddr (execValidatedTx s tx).1.2 a n =
delayedReserveBalOfAddr s.2 a n.
Proof using K K_pos.
intros Hle Hlt. unfold execValidatedTx.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx).
{ cbn [fst snd]. unfold updateExtraState, delayedReserveBalOfAddr.
rewrite delayedReserveBal_applyReserveBalUpdatesForAddr_ltK; [|exact Hlt].
rewrite delayedReserveBal_promoteWithinK; [|exact Hle|exact Hlt].
reflexivity. }
destruct (revertTx s.1 tx). cbn [fst snd].
unfold updateExtraStateNoReserve, delayedReserveBalOfAddr.
rewrite delayedReserveBal_promoteWithinK; [reflexivity|exact Hle|exact Hlt].
Qed.
Context {transactions : list TxWithHdr} {eas : EVMAssupmtions transactions}.
Lemma exec_delegation s tx a :
addrDelegated (execValidatedTx s tx).1.1 a =
(addrDelegated s.1 a && bool_decide (a ∉ undels tx.1.2)) ||
bool_decide (a ∈ dels tx.1.2).
Proof using All.
pose proof (execTxDelegationUpdCore tx s.1 a) as Hcore.
pose proof (revertTxDelegationUpdCore tx s.1 a) as Hrevert.
unfold evmExecTxCoreState in Hcore. unfold revertTxState in Hrevert.
unfold execValidatedTx.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx); [exact Hcore|].
destruct (revertTx s.1 tx). exact Hrevert.
Qed.
Lemma check_nondecrease pre post tx a :
balanceOfAc pre.1 a ≤ balanceOfAc post a → finalBalSufficient pre post tx a = true.
Proof using All.
intros Hbal. unfold finalBalSufficient.
destruct (isSC post a); [reflexivity|]. case_bool_decide.
{ destruct (isAllowedToEmptyExec pre tx); [reflexivity|].
apply bool_decide_eq_true_2. lia. }
apply bool_decide_eq_true_2. lia.
Qed.
Lemma exec_final_check s tx a :
maxTxFee tx ≤ balanceOfAc s.1 (sender tx) →
finalBalSufficient s (execValidatedTx s tx).1.1 tx a = true.
Proof using All.
intros Hfee. unfold execValidatedTx.
pose proof (changedAccountSetSound tx s.1) as Hframe.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx) eqn:Hcheck.
{ cbn [fst snd]. destruct (decide (a ∈ changed)) as [Hin|Hout].
{ unfold allFinalBalSufficient in Hcheck.
rewrite forallb_spec in Hcheck. apply Hcheck. exact Hin. }
apply check_nondecrease. unfold balanceOfAc. rewrite Hframe; [lia|exact Hout]. }
pose proof (balanceOfRevertSender s.1 tx Hfee) as Hsender.
pose proof (balanceOfRevertOther s.1 tx a) as Hother.
unfold revertTxState in Hsender, Hother.
destruct (revertTx s.1 tx) as [postRevert revertReceipt]. cbn [fst snd] in ×.
unfold finalBalSufficient. destruct (isSC postRevert a); [reflexivity|].
case_bool_decide as Hsame.
{ subst a. destruct (isAllowedToEmptyExec s tx); [reflexivity|].
apply bool_decide_eq_true_2. lia. }
apply bool_decide_eq_true_2. specialize (Hother ltac:(congruence)). lia.
Qed.
Lemma execTxOtherBalanceLB tx s :
maxTxFee tx ≤ balanceOfAc s.1 (sender tx) →
let sf := (execValidatedTx s tx).1 in
∀ a, a ≠ sender tx →
if isSC sf.1 a then True else
N.min (delayedReserveBalOfAddr s.2 a (txBlockNum tx)) (balanceOfAcA s a)
≤ balanceOfAcA sf a.
Proof using All.
intros Hfee sf a Hneq.
pose proof (exec_final_check s tx a Hfee) as Hcheck.
unfold finalBalSufficient in Hcheck. fold sf in Hcheck.
destruct (isSC sf.1 a); [exact I|].
rewrite bool_decide_false in Hcheck; [|congruence].
apply bool_decide_eq_true_1 in Hcheck. exact Hcheck.
Qed.
Lemma empty_sender_not_delegated s tx :
isAllowedToEmpty s [] tx = true →
addrDelegated (evmExecTxCoreState s.1 tx) (sender tx) = false.
Proof using All.
unfold isAllowedToEmpty. intros Hallowed.
apply andb_true_iff in Hallowed as [Hdel _]. apply negb_true_iff in Hdel.
apply orb_false_iff in Hdel as [Hdel Hauth].
apply orb_false_iff in Hdel as [Hdel _].
apply bool_decide_eq_false_1 in Hauth.
rewrite execTxDelegationUpdCore Hdel. simpl.
apply bool_decide_eq_false_2.
unfold addrsDelUndelByTx in Hauth. simpl in Hauth. set_solver.
Qed.
Lemma execTxSenderBal tx s :
maxTxFee tx ≤ balanceOfAc s.1 (sender tx) →
let sf := (execValidatedTx s tx).1 in
isSC sf.1 (sender tx) = false →
if isAllowedToEmpty s [] tx then
balanceOfAcA s (sender tx) - (maxTxFee tx + value tx + maxStorageFee tx)
≤ balanceOfAcA sf (sender tx) ∨
balanceOfAcA sf (sender tx) = balanceOfAcA s (sender tx) - maxTxFee tx
else N.min (delayedReserveBalOfAddr s.2 (sender tx) (txBlockNum tx))
(balanceOfAcA s (sender tx)) - maxTxFee tx ≤ balanceOfAcA sf (sender tx).
Proof using All.
intros Hfee sf Hsc. destruct (isAllowedToEmpty s [] tx) eqn:Hempty.
{ pose proof (execTxSenderBalCore tx s.1 Hfee (empty_sender_not_delegated s tx Hempty))
as Hcore.
pose proof (balanceOfRevertSender s.1 tx Hfee) as Hrevert.
unfold sf, execValidatedTx, balanceOfAcA.
unfold evmExecTxCoreState in Hcore. unfold revertTxState in Hrevert.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx); [exact Hcore|].
destruct (revertTx s.1 tx). right. exact Hrevert. }
pose proof (exec_final_check s tx (sender tx) Hfee) as Hcheck.
unfold finalBalSufficient, isAllowedToEmptyExec in Hcheck. fold sf in Hcheck.
rewrite Hsc in Hcheck.
rewrite bool_decide_true in Hcheck; [|reflexivity].
rewrite Hempty in Hcheck.
apply bool_decide_eq_true_1 in Hcheck. exact Hcheck.
Qed.
Lemma exec_non_debit s tx a :
a ∈ map sender transactions →
a ≠ sender tx → addrDelegated (execValidatedTx s tx).1.1 a = false →
isSC (execValidatedTx s tx).1.1 a = false →
balanceOfAc s.1 a ≤ balanceOfAc (execValidatedTx s tx).1.1 a.
Proof using All.
intros Hsigner Hneq.
pose proof (execTxCannotDebitNonDelegatedNonContractAccountsCore tx s.1 a Hsigner Hneq) as Hcore.
pose proof (balanceOfRevertOther s.1 tx a Hneq) as Hrevert.
unfold execValidatedTx, evmExecTxCoreState in ×.
unfold revertTxState in Hrevert.
destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient s post changed tx).
{ cbn [fst snd] in ×. intros Hdel Hsc. apply Hcore. rewrite Hdel Hsc. reflexivity. }
destruct (revertTx s.1 tx). cbn [fst snd] in ×. intros _ _. lia.
Qed.
Lemma emptyBalanceUb s tx inter candidate :
sender candidate ∈ map sender transactions →
isSC (execValidatedTx s tx).1.1 (sender candidate) = false →
isAllowedToEmpty s (tx :: inter) candidate = true →
balanceOfAc s.1 (sender candidate) ≤
balanceOfAc (execValidatedTx s tx).1.1 (sender candidate).
Proof using All.
intros Hsigner Hsc Hallowed. unfold isAllowedToEmpty in Hallowed.
apply andb_true_iff in Hallowed as [Hdel Hsend].
apply negb_true_iff, orb_false_iff in Hsend as [_ Hsend].
apply bool_decide_eq_false_1 in Hsend.
apply negb_true_iff, orb_false_iff in Hdel as [Hdel Hauth].
apply orb_false_iff in Hdel as [Hdel _].
apply bool_decide_eq_false_1 in Hauth.
eapply exec_non_debit; [exact Hsigner|simpl in Hsend; set_solver| |exact Hsc].
rewrite exec_delegation Hdel. simpl. apply bool_decide_eq_false_2.
unfold addrsDelUndelByTx in Hauth. simpl in Hauth. set_solver.
Qed.
Lemma execPreservesIsAllowedToEmpty s tx rest candidate :
(Z.of_N (txBlockNum candidate) - (Z.of_N K - 1) ≤ Z.of_N (txBlockNum tx)
≤ Z.of_N (txBlockNum candidate))%Z →
isAllowedToEmpty s (tx :: rest) candidate =
isAllowedToEmpty (execValidatedTx s tx).1 rest candidate.
Proof using All.
intros Hrange.
pose proof (f_equal fst (exec_history s tx (sender candidate))) as Htx.
pose proof (f_equal snd (exec_history s tx (sender candidate))) as Hauth.
cbn [fst snd] in Htx, Hauth.
assert (Hwithin : bool_decide (txBlockNum candidate - (K - 1) ≤ txBlockNum tx
≤ txBlockNum candidate) = true).
{ apply bool_decide_eq_true_2. lia. }
destruct (decide (sender tx = sender candidate)) as [Hsame|Hdifferent].
{ rewrite bool_decide_true in Htx; [|exact Hsame].
assert (Hmem : bool_decide (sender candidate ∈ map sender (tx :: rest)) = true).
{ apply bool_decide_eq_true_2. simpl. set_solver. }
unfold isAllowedToEmpty, existsTxWithinK, indexWithinK.
rewrite Htx Hwithin Hmem. rewrite !orb_true_r !andb_false_r. reflexivity. }
rewrite bool_decide_false in Htx; [|exact Hdifferent].
destruct (decide (sender candidate ∈ addrsDelUndelByTx tx)) as [Htouched|Huntouched].
{ rewrite bool_decide_true in Hauth; [|exact Htouched].
assert (Hmem : bool_decide (sender candidate ∈
flat_map addrsDelUndelByTx (candidate :: tx :: rest)) = true).
{ apply bool_decide_eq_true_2. simpl. set_solver. }
unfold isAllowedToEmpty, existsDelUndelTxWithinK, indexWithinK.
rewrite Hauth Hwithin Hmem. rewrite !orb_true_r. reflexivity. }
rewrite bool_decide_false in Hauth; [|exact Huntouched].
assert (Hdel : addrDelegated (execValidatedTx s tx).1.1 (sender candidate) =
addrDelegated s.1 (sender candidate)).
{ rewrite exec_delegation.
assert (HnotUndel : bool_decide (sender candidate ∉ undels tx.1.2) = true).
{ apply bool_decide_eq_true_2. unfold addrsDelUndelByTx in Huntouched. set_solver. }
assert (HnotDel : bool_decide (sender candidate ∈ dels tx.1.2) = false).
{ apply bool_decide_eq_false_2. unfold addrsDelUndelByTx in Huntouched. set_solver. }
rewrite HnotUndel HnotDel andb_true_r orb_false_r. reflexivity. }
assert (HsendMem : bool_decide (sender candidate ∈ map sender (tx :: rest)) =
bool_decide (sender candidate ∈ map sender rest)).
{ apply bool_decide_ext. simpl. set_solver. }
assert (HauthMem : bool_decide (sender candidate ∈
flat_map addrsDelUndelByTx (candidate :: tx :: rest)) =
bool_decide (sender candidate ∈ flat_map addrsDelUndelByTx (candidate :: rest))).
{ apply bool_decide_ext. simpl. set_solver. }
unfold isAllowedToEmpty, existsTxWithinK, existsDelUndelTxWithinK, indexWithinK.
rewrite Htx Hauth Hdel HsendMem HauthMem. reflexivity.
Qed.
Lemma inactiveBalanceUb s tx inter candidate :
sender candidate ∈ map sender transactions →
isSC (execValidatedTx s tx).1.1 (sender candidate) = false →
senderNoRecentActivity s (tx :: inter) candidate = true →
balanceOfAc s.1 (sender candidate) ≤
balanceOfAc (execValidatedTx s tx).1.1 (sender candidate).
Proof using All.
intros Hsigner Hsc Hallowed. unfold senderNoRecentActivity in Hallowed.
apply andb_true_iff in Hallowed as [Hsend Hdel].
apply negb_true_iff, orb_false_iff in Hsend as [_ Hsend].
apply bool_decide_eq_false_1 in Hsend.
apply negb_true_iff, orb_false_iff in Hdel as [Hdel Hauth].
apply orb_false_iff in Hdel as [Hdel _].
apply bool_decide_eq_false_1 in Hauth.
eapply exec_non_debit; [exact Hsigner|simpl in Hsend; set_solver| |exact Hsc].
rewrite exec_delegation Hdel. simpl. apply bool_decide_eq_false_2.
unfold addrsDelUndelByTx in Hauth. simpl in Hauth. set_solver.
Qed.
Lemma execPreservesSenderNoRecentActivity s tx rest candidate :
(Z.of_N (txBlockNum candidate) - (Z.of_N K - 1) ≤ Z.of_N (txBlockNum tx)
≤ Z.of_N (txBlockNum candidate))%Z →
senderNoRecentActivity s (tx :: rest) candidate =
senderNoRecentActivity (execValidatedTx s tx).1 rest candidate.
Proof using All.
intros Hrange.
pose proof (f_equal fst (exec_history s tx (sender candidate))) as Htx.
pose proof (f_equal snd (exec_history s tx (sender candidate))) as Hauth.
cbn [fst snd] in Htx, Hauth.
assert (Hwithin : bool_decide (txBlockNum candidate - (K - 1) ≤ txBlockNum tx
≤ txBlockNum candidate) = true).
{ apply bool_decide_eq_true_2. lia. }
destruct (decide (sender tx = sender candidate)) as [Hsame|Hdifferent].
{ rewrite bool_decide_true in Htx; [|exact Hsame].
assert (Hmem : bool_decide (sender candidate ∈ map sender (tx :: rest)) = true).
{ apply bool_decide_eq_true_2. simpl. set_solver. }
unfold senderNoRecentActivity, existsTxWithinK, indexWithinK.
rewrite Htx Hwithin Hmem. rewrite !orb_true_r. reflexivity. }
rewrite bool_decide_false in Htx; [|exact Hdifferent].
destruct (decide (sender candidate ∈ addrsDelUndelByTx tx)) as [Htouched|Huntouched].
{ rewrite bool_decide_true in Hauth; [|exact Htouched].
assert (Hmem : bool_decide (sender candidate ∈
flat_map addrsDelUndelByTx (tx :: rest)) = true).
{ apply bool_decide_eq_true_2. simpl. set_solver. }
unfold senderNoRecentActivity, existsDelUndelTxWithinK, indexWithinK.
rewrite Hauth Hwithin Hmem. rewrite !orb_true_r !andb_false_r. reflexivity. }
rewrite bool_decide_false in Hauth; [|exact Huntouched].
assert (Hdel : addrDelegated (execValidatedTx s tx).1.1 (sender candidate) =
addrDelegated s.1 (sender candidate)).
{ rewrite exec_delegation.
assert (HnotUndel : bool_decide (sender candidate ∉ undels tx.1.2) = true).
{ apply bool_decide_eq_true_2. unfold addrsDelUndelByTx in Huntouched. set_solver. }
assert (HnotDel : bool_decide (sender candidate ∈ dels tx.1.2) = false).
{ apply bool_decide_eq_false_2. unfold addrsDelUndelByTx in Huntouched. set_solver. }
rewrite HnotUndel HnotDel andb_true_r orb_false_r. reflexivity. }
assert (HsendMem : bool_decide (sender candidate ∈ map sender (tx :: rest)) =
bool_decide (sender candidate ∈ map sender rest)).
{ apply bool_decide_ext. simpl. set_solver. }
assert (HauthMem : bool_decide (sender candidate ∈
flat_map addrsDelUndelByTx (tx :: rest)) =
bool_decide (sender candidate ∈ flat_map addrsDelUndelByTx rest)).
{ apply bool_decide_ext. simpl. set_solver. }
unfold senderNoRecentActivity, existsTxWithinK, existsDelUndelTxWithinK, indexWithinK.
rewrite Htx Hauth Hdel HsendMem HauthMem. reflexivity.
Qed.
End Delayed.
Original consensus check, with optional budget refresh
Section Consensus.
Variable K : N.
Hypothesis K_pos : 0 < K.
Variable refreshReserve : bool.
Local Open Scope Z_scope.
Variable K : N.
Hypothesis K_pos : 0 < K.
Variable refreshReserve : bool.
Local Open Scope Z_scope.
h is the supplied execution snapshot's block height, not the candidate
height. Querying it directly also handles activation during empty blocks,
when no transaction has promoted the pending record yet.
Definition initialEffReserveBals (s : AugmentedState) (h : N) : EffReserveBals :=
fun a ⇒ Z.min (Z.of_N (balanceOfAc s.1 a))
(Z.of_N (delayedReserveBalOfAddr K s.2 a h)).
Definition remainingEffReserveBalOfSender (s : AugmentedState) (prevErb : Z)
(inter : list TxWithHdr) (tx : TxWithHdr) : Z :=
let threshold := Z.of_N (delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx)) in
let baseErb :=
if refreshReserve && senderNoRecentActivity K s inter tx
then Z.min (Z.of_N (balanceOfAc s.1 (sender tx))) threshold
else Z.min prevErb threshold in
if isAllowedToEmpty K s inter tx then
if bool_decide (maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N then
Z.min (Z.max (Z.of_N (balanceOfAc s.1 (sender tx)) - Z.of_N (maxTxFee tx) -
Z.of_N (value tx) - Z.of_N (maxStorageFee tx)) 0) threshold
else -1
else baseErb - Z.of_N (maxTxFee tx).
Fixpoint remainingEffReserveBalsL (s : AugmentedState) (budget : EffReserveBals)
(previous rest : list TxWithHdr) : EffReserveBals :=
match rest with
| [] ⇒ budget
| tx :: rest ⇒
let clamped := advanceEffReserveBals K s budget (txBlockNum tx) in
let remaining := remainingEffReserveBalOfSender s (clamped (sender tx)) previous tx in
remainingEffReserveBalsL s (updateKey clamped (sender tx) (fun _ ⇒ remaining))
(previous ++ [tx]) rest
end.
Definition consensusAcceptableTxs (s : AugmentedState) (h : N) (txs : list TxWithHdr) : Prop :=
∀ a, a ∈ map sender txs →
0 ≤ remainingEffReserveBalsL s (initialEffReserveBals s h) [] txs a.
Fixpoint blockNumsInRange (txs : list TxWithHdr) : Prop :=
match txs with
| [] ⇒ True
| tx :: rest ⇒
(∀ t, t ∈ rest → (txBlockNum tx ≤ txBlockNum t < txBlockNum tx + K)%N) ∧
blockNumsInRange rest
end.
Variable evmExecTxCore : StateOfAccounts → TxWithHdr →
((StateOfAccounts × TxResult) × list EvmAddr) × ReserveBalUpdate.
Variable revertTx : StateOfAccounts → TxWithHdr → StateOfAccounts × TxResult.
Local Notation execute := (execValidatedTx K evmExecTxCore revertTx).
Fixpoint execTxs (s : AugmentedState) (txs : list TxWithHdr)
: option (AugmentedState × list TxResult) :=
match txs with
| [] ⇒ Some (s, [])
| tx :: rest ⇒
if validateTx s.1 tx then
let '(next, receipt) := execute s tx in
match execTxs next rest with
| None ⇒ None
| Some (post, receipts) ⇒ Some (post, receipt :: receipts)
end
else None
end.
fun a ⇒ Z.min (Z.of_N (balanceOfAc s.1 a))
(Z.of_N (delayedReserveBalOfAddr K s.2 a h)).
Definition remainingEffReserveBalOfSender (s : AugmentedState) (prevErb : Z)
(inter : list TxWithHdr) (tx : TxWithHdr) : Z :=
let threshold := Z.of_N (delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx)) in
let baseErb :=
if refreshReserve && senderNoRecentActivity K s inter tx
then Z.min (Z.of_N (balanceOfAc s.1 (sender tx))) threshold
else Z.min prevErb threshold in
if isAllowedToEmpty K s inter tx then
if bool_decide (maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N then
Z.min (Z.max (Z.of_N (balanceOfAc s.1 (sender tx)) - Z.of_N (maxTxFee tx) -
Z.of_N (value tx) - Z.of_N (maxStorageFee tx)) 0) threshold
else -1
else baseErb - Z.of_N (maxTxFee tx).
Fixpoint remainingEffReserveBalsL (s : AugmentedState) (budget : EffReserveBals)
(previous rest : list TxWithHdr) : EffReserveBals :=
match rest with
| [] ⇒ budget
| tx :: rest ⇒
let clamped := advanceEffReserveBals K s budget (txBlockNum tx) in
let remaining := remainingEffReserveBalOfSender s (clamped (sender tx)) previous tx in
remainingEffReserveBalsL s (updateKey clamped (sender tx) (fun _ ⇒ remaining))
(previous ++ [tx]) rest
end.
Definition consensusAcceptableTxs (s : AugmentedState) (h : N) (txs : list TxWithHdr) : Prop :=
∀ a, a ∈ map sender txs →
0 ≤ remainingEffReserveBalsL s (initialEffReserveBals s h) [] txs a.
Fixpoint blockNumsInRange (txs : list TxWithHdr) : Prop :=
match txs with
| [] ⇒ True
| tx :: rest ⇒
(∀ t, t ∈ rest → (txBlockNum tx ≤ txBlockNum t < txBlockNum tx + K)%N) ∧
blockNumsInRange rest
end.
Variable evmExecTxCore : StateOfAccounts → TxWithHdr →
((StateOfAccounts × TxResult) × list EvmAddr) × ReserveBalUpdate.
Variable revertTx : StateOfAccounts → TxWithHdr → StateOfAccounts × TxResult.
Local Notation execute := (execValidatedTx K evmExecTxCore revertTx).
Fixpoint execTxs (s : AugmentedState) (txs : list TxWithHdr)
: option (AugmentedState × list TxResult) :=
match txs with
| [] ⇒ Some (s, [])
| tx :: rest ⇒
if validateTx s.1 tx then
let '(next, receipt) := execute s tx in
match execTxs next rest with
| None ⇒ None
| Some (post, receipts) ⇒ Some (post, receipt :: receipts)
end
else None
end.
Once an account has sent a transaction in the scanned suffix, neither
emptying nor the optional refresh can replenish its budget. Thus checking
final budgets also checks every earlier fee deduction.
Lemma previously_sent s previous tx :
sender tx ∈ map sender previous →
isAllowedToEmpty K s previous tx = false ∧
senderNoRecentActivity K s previous tx = false.
Proof using All.
intros Hin. unfold isAllowedToEmpty, senderNoRecentActivity.
rewrite (bool_decide_true _ Hin) !orb_true_r. simpl. split; [apply andb_false_r|reflexivity].
Qed.
Lemma remaining_previously_sent s rest :
∀ budget previous a, a ∈ map sender previous →
remainingEffReserveBalsL s budget previous rest a ≤ budget a.
Proof using All.
induction rest as [|tx rest IH]; intros budget previous a Hin; [simpl; lia|].
cbn [remainingEffReserveBalsL]. etransitivity.
{ apply IH. rewrite map_app. set_solver. }
unfold updateKey. destruct (decide (a = sender tx)) as [->|Hneq].
{ rewrite bool_decide_true; [|reflexivity].
destruct (previously_sent s previous tx Hin) as [Hempty Hrefresh].
unfold remainingEffReserveBalOfSender. rewrite Hempty Hrefresh andb_false_r.
unfold advanceEffReserveBals. lia. }
rewrite bool_decide_false; [|exact Hneq]. unfold advanceEffReserveBals. lia.
Qed.
Lemma accepted_head_fee s h tx rest :
consensusAcceptableTxs s h (tx :: rest) →
(maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N.
Proof using All.
intro Haccept. specialize (Haccept (sender tx) ltac:(simpl; set_solver)).
cbn [remainingEffReserveBalsL] in Haccept.
match type of Haccept with context [remainingEffReserveBalsL _ ?budget ?previous _ _] ⇒
pose proof (remaining_previously_sent s rest budget previous (sender tx)
ltac:(simpl; set_solver)) as Hle end.
unfold updateKey in Hle, Haccept. rewrite bool_decide_true in Hle; [|reflexivity].
assert (Hrem : 0 ≤ remainingEffReserveBalOfSender s
((advanceEffReserveBals K s (initialEffReserveBals s h) (txBlockNum tx)) (sender tx)) [] tx) by lia.
unfold remainingEffReserveBalOfSender, initialEffReserveBals, advanceEffReserveBals in Hrem.
destruct (isAllowedToEmpty K s [] tx).
{ destruct (bool_decide (maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N) eqn:Hfee;
[apply bool_decide_eq_true_1 in Hfee; exact Hfee|lia]. }
destruct (refreshReserve && senderNoRecentActivity K s [] tx); lia.
Qed.
Lemma reserve_at_zero es : delayedReserveBal K es 0 = settledReserveBal es.
Proof using All.
unfold delayedReserveBal. destruct (pendingReserveBal es) as [[v b]|]; [|reflexivity].
rewrite bool_decide_false; [reflexivity|lia].
Qed.
Lemma promoted_settled es n :
settledReserveBal (promotePendingReserveBal K es n) = delayedReserveBal K es n.
Proof using All.
unfold promotePendingReserveBal, delayedReserveBal.
destruct (pendingReserveBal es) as [[v b]|]; [|reflexivity].
destruct (bool_decide (b + K ≤ n)%N); reflexivity.
Qed.
Lemma updates_settled updates es n a :
settledReserveBal (applyReserveBalUpdatesForAddr es n a updates) = settledReserveBal es.
Proof using All.
revert es. induction updates as [|[addr v] rest IH]; intros es; [reflexivity|].
cbn [applyReserveBalUpdatesForAddr fold_left]. rewrite IH.
destruct (bool_decide (addr = a)); [|reflexivity].
unfold applyReserveBalUpdate. destruct (pendingReserveBal es) as [[old b]|]; [|reflexivity].
destruct (bool_decide (b = n)); reflexivity.
Qed.
Lemma reserve_after_exec_zero s tx a :
delayedReserveBalOfAddr K (execute s tx).1.2 a 0 =
delayedReserveBalOfAddr K s.2 a (txBlockNum tx).
Proof using All.
unfold execValidatedTx. destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient K s post changed tx).
{ cbn [fst snd]. unfold delayedReserveBalOfAddr. rewrite reserve_at_zero.
unfold updateExtraState. rewrite updates_settled promoted_settled.
reflexivity. }
destruct (revertTx s.1 tx). cbn [fst snd].
unfold delayedReserveBalOfAddr. rewrite reserve_at_zero.
unfold updateExtraStateNoReserve. rewrite promoted_settled. reflexivity.
Qed.
Lemma reserve_after_exec_current s tx a :
delayedReserveBalOfAddr K (execute s tx).1.2 a (txBlockNum tx) =
delayedReserveBalOfAddr K s.2 a (txBlockNum tx).
Proof using All.
apply (delayedReserveBalOfAddrWithinK K K_pos evmExecTxCore revertTx); lia.
Qed.
Lemma sender_budget_mono s newer old fresh previous later tx :
old ≤ fresh →
delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx) =
delayedReserveBalOfAddr K newer.2 (sender tx) (txBlockNum tx) →
isAllowedToEmpty K s previous tx = isAllowedToEmpty K newer later tx →
senderNoRecentActivity K s previous tx = senderNoRecentActivity K newer later tx →
(isAllowedToEmpty K s previous tx = true ∨ senderNoRecentActivity K s previous tx = true →
(balanceOfAc s.1 (sender tx) ≤ balanceOfAc newer.1 (sender tx))%N) →
remainingEffReserveBalOfSender s old previous tx ≤
remainingEffReserveBalOfSender newer fresh later tx.
Proof using All.
intros Hbudget Hthreshold Hempty Hrefresh Hbalance.
unfold remainingEffReserveBalOfSender.
rewrite <- Hthreshold, <- Hempty, <- Hrefresh.
destruct (isAllowedToEmpty K s previous tx) eqn:He.
{ specialize (Hbalance (or_introl eq_refl)). repeat case_bool_decide; lia. }
destruct (senderNoRecentActivity K s previous tx) eqn:Hr.
{ specialize (Hbalance (or_intror eq_refl)). destruct refreshReserve; simpl; lia. }
rewrite andb_false_r. lia.
Qed.
sender tx ∈ map sender previous →
isAllowedToEmpty K s previous tx = false ∧
senderNoRecentActivity K s previous tx = false.
Proof using All.
intros Hin. unfold isAllowedToEmpty, senderNoRecentActivity.
rewrite (bool_decide_true _ Hin) !orb_true_r. simpl. split; [apply andb_false_r|reflexivity].
Qed.
Lemma remaining_previously_sent s rest :
∀ budget previous a, a ∈ map sender previous →
remainingEffReserveBalsL s budget previous rest a ≤ budget a.
Proof using All.
induction rest as [|tx rest IH]; intros budget previous a Hin; [simpl; lia|].
cbn [remainingEffReserveBalsL]. etransitivity.
{ apply IH. rewrite map_app. set_solver. }
unfold updateKey. destruct (decide (a = sender tx)) as [->|Hneq].
{ rewrite bool_decide_true; [|reflexivity].
destruct (previously_sent s previous tx Hin) as [Hempty Hrefresh].
unfold remainingEffReserveBalOfSender. rewrite Hempty Hrefresh andb_false_r.
unfold advanceEffReserveBals. lia. }
rewrite bool_decide_false; [|exact Hneq]. unfold advanceEffReserveBals. lia.
Qed.
Lemma accepted_head_fee s h tx rest :
consensusAcceptableTxs s h (tx :: rest) →
(maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N.
Proof using All.
intro Haccept. specialize (Haccept (sender tx) ltac:(simpl; set_solver)).
cbn [remainingEffReserveBalsL] in Haccept.
match type of Haccept with context [remainingEffReserveBalsL _ ?budget ?previous _ _] ⇒
pose proof (remaining_previously_sent s rest budget previous (sender tx)
ltac:(simpl; set_solver)) as Hle end.
unfold updateKey in Hle, Haccept. rewrite bool_decide_true in Hle; [|reflexivity].
assert (Hrem : 0 ≤ remainingEffReserveBalOfSender s
((advanceEffReserveBals K s (initialEffReserveBals s h) (txBlockNum tx)) (sender tx)) [] tx) by lia.
unfold remainingEffReserveBalOfSender, initialEffReserveBals, advanceEffReserveBals in Hrem.
destruct (isAllowedToEmpty K s [] tx).
{ destruct (bool_decide (maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N) eqn:Hfee;
[apply bool_decide_eq_true_1 in Hfee; exact Hfee|lia]. }
destruct (refreshReserve && senderNoRecentActivity K s [] tx); lia.
Qed.
Lemma reserve_at_zero es : delayedReserveBal K es 0 = settledReserveBal es.
Proof using All.
unfold delayedReserveBal. destruct (pendingReserveBal es) as [[v b]|]; [|reflexivity].
rewrite bool_decide_false; [reflexivity|lia].
Qed.
Lemma promoted_settled es n :
settledReserveBal (promotePendingReserveBal K es n) = delayedReserveBal K es n.
Proof using All.
unfold promotePendingReserveBal, delayedReserveBal.
destruct (pendingReserveBal es) as [[v b]|]; [|reflexivity].
destruct (bool_decide (b + K ≤ n)%N); reflexivity.
Qed.
Lemma updates_settled updates es n a :
settledReserveBal (applyReserveBalUpdatesForAddr es n a updates) = settledReserveBal es.
Proof using All.
revert es. induction updates as [|[addr v] rest IH]; intros es; [reflexivity|].
cbn [applyReserveBalUpdatesForAddr fold_left]. rewrite IH.
destruct (bool_decide (addr = a)); [|reflexivity].
unfold applyReserveBalUpdate. destruct (pendingReserveBal es) as [[old b]|]; [|reflexivity].
destruct (bool_decide (b = n)); reflexivity.
Qed.
Lemma reserve_after_exec_zero s tx a :
delayedReserveBalOfAddr K (execute s tx).1.2 a 0 =
delayedReserveBalOfAddr K s.2 a (txBlockNum tx).
Proof using All.
unfold execValidatedTx. destruct (evmExecTxCore s.1 tx) as [[[post receipt] changed] updates].
destruct (allFinalBalSufficient K s post changed tx).
{ cbn [fst snd]. unfold delayedReserveBalOfAddr. rewrite reserve_at_zero.
unfold updateExtraState. rewrite updates_settled promoted_settled.
reflexivity. }
destruct (revertTx s.1 tx). cbn [fst snd].
unfold delayedReserveBalOfAddr. rewrite reserve_at_zero.
unfold updateExtraStateNoReserve. rewrite promoted_settled. reflexivity.
Qed.
Lemma reserve_after_exec_current s tx a :
delayedReserveBalOfAddr K (execute s tx).1.2 a (txBlockNum tx) =
delayedReserveBalOfAddr K s.2 a (txBlockNum tx).
Proof using All.
apply (delayedReserveBalOfAddrWithinK K K_pos evmExecTxCore revertTx); lia.
Qed.
Lemma sender_budget_mono s newer old fresh previous later tx :
old ≤ fresh →
delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx) =
delayedReserveBalOfAddr K newer.2 (sender tx) (txBlockNum tx) →
isAllowedToEmpty K s previous tx = isAllowedToEmpty K newer later tx →
senderNoRecentActivity K s previous tx = senderNoRecentActivity K newer later tx →
(isAllowedToEmpty K s previous tx = true ∨ senderNoRecentActivity K s previous tx = true →
(balanceOfAc s.1 (sender tx) ≤ balanceOfAc newer.1 (sender tx))%N) →
remainingEffReserveBalOfSender s old previous tx ≤
remainingEffReserveBalOfSender newer fresh later tx.
Proof using All.
intros Hbudget Hthreshold Hempty Hrefresh Hbalance.
unfold remainingEffReserveBalOfSender.
rewrite <- Hthreshold, <- Hempty, <- Hrefresh.
destruct (isAllowedToEmpty K s previous tx) eqn:He.
{ specialize (Hbalance (or_introl eq_refl)). repeat case_bool_decide; lia. }
destruct (senderNoRecentActivity K s previous tx) eqn:Hr.
{ specialize (Hbalance (or_intror eq_refl)). destruct refreshReserve; simpl; lia. }
rewrite andb_false_r. lia.
Qed.
Budget comparison is enough to transfer an entire consensus scan. The
histories may differ, provided their emptying/refresh decisions agree and
balances used by those exceptions have not decreased.
Lemma scan_mono s newer txs (signers : list EvmAddr) :
(∀ tx, tx ∈ txs → sender tx ∈ signers) →
∀ old fresh previous later,
(∀ a, a ∈ signers → old a ≤ fresh a) →
(∀ tx, tx ∈ txs → ∀ a, a ∈ signers →
delayedReserveBalOfAddr K s.2 a (txBlockNum tx) =
delayedReserveBalOfAddr K newer.2 a (txBlockNum tx)) →
(∀ tx, tx ∈ txs → ∀ extra,
isAllowedToEmpty K s (previous ++ extra) tx =
isAllowedToEmpty K newer (later ++ extra) tx ∧
senderNoRecentActivity K s (previous ++ extra) tx =
senderNoRecentActivity K newer (later ++ extra) tx ∧
(isAllowedToEmpty K s (previous ++ extra) tx = true ∨
senderNoRecentActivity K s (previous ++ extra) tx = true →
(balanceOfAc s.1 (sender tx) ≤ balanceOfAc newer.1 (sender tx))%N)) →
∀ a, a ∈ signers →
remainingEffReserveBalsL s old previous txs a ≤
remainingEffReserveBalsL newer fresh later txs a.
Proof using All.
induction txs as [|tx rest IH]; intros Hsend old fresh previous later Hbudget Hthreshold Hhistory a Ha.
{ simpl. apply Hbudget; exact Ha. }
cbn [remainingEffReserveBalsL]. apply IH.
{ intros t Ht. apply Hsend. set_solver. }
{ intros b Hb. unfold updateKey. destruct (decide (b = sender tx)) as [->|Hneq].
{ rewrite !bool_decide_true; try reflexivity.
destruct (Hhistory tx ltac:(set_solver) []) as [He [Hr Hbal]].
rewrite !app_nil_r in He, Hr, Hbal.
eapply sender_budget_mono; try eassumption.
{ unfold advanceEffReserveBals. rewrite (Hthreshold tx ltac:(set_solver) (sender tx) Hb).
specialize (Hbudget _ Hb). lia. }
{ apply Hthreshold; [set_solver|exact Hb]. } }
rewrite !bool_decide_false; try exact Hneq.
unfold advanceEffReserveBals. rewrite (Hthreshold tx ltac:(set_solver) b Hb).
specialize (Hbudget _ Hb). lia. }
{ intros t Ht b Hb. apply Hthreshold; [set_solver|exact Hb]. }
{ intros t Ht extra. rewrite <- !app_assoc. cbn [app].
apply Hhistory. set_solver. }
{ exact Ha. }
Qed.
Section ExecutionProofs.
Context {transactions : list TxWithHdr} {eas : EVMAssupmtions evmExecTxCore revertTx transactions}.
Lemma initial_after_exec s h tx (signers : list EvmAddr) :
(maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N →
(∀ a, a ∈ signers → isSC (execute s tx).1.1 a = false) →
let clamped := advanceEffReserveBals K s (initialEffReserveBals s h) (txBlockNum tx) in
∀ a, a ∈ signers →
updateKey clamped (sender tx)
(fun _ ⇒ remainingEffReserveBalOfSender s (clamped (sender tx)) [] tx) a ≤
initialEffReserveBals (execute s tx).1 (txBlockNum tx) a.
Proof using All.
intros Hfee Hsc clamped a Ha. unfold updateKey.
destruct (decide (a = sender tx)) as [->|Hneq].
{ rewrite bool_decide_true; [|reflexivity].
pose proof (execTxSenderBal K K_pos evmExecTxCore revertTx tx s Hfee (Hsc _ Ha)) as Hpost.
unfold balanceOfAcA in Hpost.
unfold initialEffReserveBals. rewrite reserve_after_exec_current.
unfold remainingEffReserveBalOfSender, clamped, advanceEffReserveBals, initialEffReserveBals.
destruct (isAllowedToEmpty K s [] tx) eqn:He.
{ rewrite bool_decide_true; [|exact Hfee]. destruct Hpost; lia. }
destruct (refreshReserve && senderNoRecentActivity K s [] tx); lia. }
rewrite bool_decide_false; [|exact Hneq].
pose proof (execTxOtherBalanceLB K K_pos evmExecTxCore revertTx tx s Hfee a Hneq) as Hpost.
rewrite (Hsc a Ha) in Hpost. unfold balanceOfAcA in Hpost.
unfold initialEffReserveBals. rewrite reserve_after_exec_current.
unfold clamped, advanceEffReserveBals, initialEffReserveBals. lia.
Qed.
Lemma accepted_tail s h tx rest :
(∀ a, a ∈ map sender rest → a ∈ map sender transactions) →
(∀ t, t ∈ rest → (txBlockNum tx ≤ txBlockNum t < txBlockNum tx + K)%N) →
(∀ a, a ∈ map sender rest → isSC (execute s tx).1.1 a = false) →
consensusAcceptableTxs s h (tx :: rest) →
consensusAcceptableTxs (execute s tx).1 (txBlockNum tx) rest.
Proof using All.
intros Hscope Hrange Hsc Haccept.
pose proof (accepted_head_fee s h tx rest Haccept) as Hfee.
intros a Ha. specialize (Haccept a ltac:(simpl; set_solver)).
cbn [remainingEffReserveBalsL app] in Haccept.
eapply Z.le_trans; [exact Haccept|].
eapply (scan_mono s (execute s tx).1 rest (map sender rest)).
{ intros t Ht. apply list_elem_of_In, in_map, list_elem_of_In. exact Ht. }
{ apply initial_after_exec; assumption. }
{ intros t Ht b Hb. symmetry.
apply (delayedReserveBalOfAddrWithinK K K_pos evmExecTxCore revertTx).
all: specialize (Hrange t Ht); lia. }
{ intros t Ht extra. cbn [app].
assert (Hs : sender t ∈ map sender rest).
{ apply list_elem_of_In, in_map, list_elem_of_In. exact Ht. }
pose proof (Hrange t Ht) as Htime. split.
{ apply (execPreservesIsAllowedToEmpty K K_pos evmExecTxCore revertTx); lia. }
split.
{ apply (execPreservesSenderNoRecentActivity K K_pos evmExecTxCore revertTx); lia. }
intros [He|Hr].
{ eapply (emptyBalanceUb K K_pos evmExecTxCore revertTx); eauto. }
{ eapply (inactiveBalanceUb K K_pos evmExecTxCore revertTx); eauto. } }
{ exact Ha. }
Qed.
Lemma fullBlockStep_scoped (s : AugmentedState) (h : N) (first rest : list TxWithHdr) :
(∀ a, a ∈ map sender (first ++ rest) → a ∈ map sender transactions) →
blockNumsInRange (first ++ rest) →
consensusAcceptableTxs s h (first ++ rest) →
(∀ tx, tx ∈ first ++ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender (first ++ rest))) →
(∀ a, a ∈ map sender (first ++ rest) → isSC s.1 a = false) →
match execTxs s first with
| None ⇒ False
| Some (post, _) ⇒
consensusAcceptableTxs post (fold_left (fun _ tx ⇒ txBlockNum tx) first h) rest ∧
blockNumsInRange rest ∧
(∀ a, a ∈ map sender rest → isSC post.1 a = false) ∧
(∀ tx, tx ∈ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender rest))
end.
Proof using All.
revert s h. induction first as [|tx first IH]; intros s h Hscope Hrange Haccept Hcrypto Hsc.
{ cbn [app execTxs fold_left] in ×. repeat split; assumption. }
cbn [app blockNumsInRange] in Hrange. destruct Hrange as [Hrange Htailrange].
cbn [app] in Hscope, Haccept, Hcrypto, Hsc.
pose proof (accepted_head_fee s h tx (first ++ rest) Haccept) as Hfee.
assert (HnextSc : ∀ a, a ∈ map sender (first ++ rest) →
isSC (execute s tx).1.1 a = false).
{ intros a Ha. apply (Hcrypto tx ltac:(set_solver) s a).
{ simpl. set_solver. }
{ apply Hsc. simpl. set_solver. } }
assert (HnextAccept : consensusAcceptableTxs (execute s tx).1 (txBlockNum tx) (first ++ rest)).
{ eapply accepted_tail; try eassumption. intros a Ha. apply Hscope. simpl. set_solver. }
specialize (IH (execute s tx).1 (txBlockNum tx)).
assert (HnextScope : ∀ a, a ∈ map sender (first ++ rest) → a ∈ map sender transactions).
{ intros a Ha. apply Hscope. simpl. set_solver. }
assert (HnextCrypto : ∀ t, t ∈ first ++ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx t (map sender (first ++ rest))).
{ intros t Ht state; cbn zeta; intros a Ha Hcode. apply (Hcrypto t ltac:(set_solver) state a); [simpl; set_solver|exact Hcode]. }
specialize (IH HnextScope Htailrange HnextAccept HnextCrypto HnextSc).
cbn [execTxs fold_left]. unfold validateTx. rewrite bool_decide_true; [|exact Hfee].
destruct (execute s tx) as [next receipt]. cbn [fst] in IH.
destruct (execTxs next first) as [[post receipts]|]; simpl in *; assumption.
Qed.
End ExecutionProofs.
(∀ tx, tx ∈ txs → sender tx ∈ signers) →
∀ old fresh previous later,
(∀ a, a ∈ signers → old a ≤ fresh a) →
(∀ tx, tx ∈ txs → ∀ a, a ∈ signers →
delayedReserveBalOfAddr K s.2 a (txBlockNum tx) =
delayedReserveBalOfAddr K newer.2 a (txBlockNum tx)) →
(∀ tx, tx ∈ txs → ∀ extra,
isAllowedToEmpty K s (previous ++ extra) tx =
isAllowedToEmpty K newer (later ++ extra) tx ∧
senderNoRecentActivity K s (previous ++ extra) tx =
senderNoRecentActivity K newer (later ++ extra) tx ∧
(isAllowedToEmpty K s (previous ++ extra) tx = true ∨
senderNoRecentActivity K s (previous ++ extra) tx = true →
(balanceOfAc s.1 (sender tx) ≤ balanceOfAc newer.1 (sender tx))%N)) →
∀ a, a ∈ signers →
remainingEffReserveBalsL s old previous txs a ≤
remainingEffReserveBalsL newer fresh later txs a.
Proof using All.
induction txs as [|tx rest IH]; intros Hsend old fresh previous later Hbudget Hthreshold Hhistory a Ha.
{ simpl. apply Hbudget; exact Ha. }
cbn [remainingEffReserveBalsL]. apply IH.
{ intros t Ht. apply Hsend. set_solver. }
{ intros b Hb. unfold updateKey. destruct (decide (b = sender tx)) as [->|Hneq].
{ rewrite !bool_decide_true; try reflexivity.
destruct (Hhistory tx ltac:(set_solver) []) as [He [Hr Hbal]].
rewrite !app_nil_r in He, Hr, Hbal.
eapply sender_budget_mono; try eassumption.
{ unfold advanceEffReserveBals. rewrite (Hthreshold tx ltac:(set_solver) (sender tx) Hb).
specialize (Hbudget _ Hb). lia. }
{ apply Hthreshold; [set_solver|exact Hb]. } }
rewrite !bool_decide_false; try exact Hneq.
unfold advanceEffReserveBals. rewrite (Hthreshold tx ltac:(set_solver) b Hb).
specialize (Hbudget _ Hb). lia. }
{ intros t Ht b Hb. apply Hthreshold; [set_solver|exact Hb]. }
{ intros t Ht extra. rewrite <- !app_assoc. cbn [app].
apply Hhistory. set_solver. }
{ exact Ha. }
Qed.
Section ExecutionProofs.
Context {transactions : list TxWithHdr} {eas : EVMAssupmtions evmExecTxCore revertTx transactions}.
Lemma initial_after_exec s h tx (signers : list EvmAddr) :
(maxTxFee tx ≤ balanceOfAc s.1 (sender tx))%N →
(∀ a, a ∈ signers → isSC (execute s tx).1.1 a = false) →
let clamped := advanceEffReserveBals K s (initialEffReserveBals s h) (txBlockNum tx) in
∀ a, a ∈ signers →
updateKey clamped (sender tx)
(fun _ ⇒ remainingEffReserveBalOfSender s (clamped (sender tx)) [] tx) a ≤
initialEffReserveBals (execute s tx).1 (txBlockNum tx) a.
Proof using All.
intros Hfee Hsc clamped a Ha. unfold updateKey.
destruct (decide (a = sender tx)) as [->|Hneq].
{ rewrite bool_decide_true; [|reflexivity].
pose proof (execTxSenderBal K K_pos evmExecTxCore revertTx tx s Hfee (Hsc _ Ha)) as Hpost.
unfold balanceOfAcA in Hpost.
unfold initialEffReserveBals. rewrite reserve_after_exec_current.
unfold remainingEffReserveBalOfSender, clamped, advanceEffReserveBals, initialEffReserveBals.
destruct (isAllowedToEmpty K s [] tx) eqn:He.
{ rewrite bool_decide_true; [|exact Hfee]. destruct Hpost; lia. }
destruct (refreshReserve && senderNoRecentActivity K s [] tx); lia. }
rewrite bool_decide_false; [|exact Hneq].
pose proof (execTxOtherBalanceLB K K_pos evmExecTxCore revertTx tx s Hfee a Hneq) as Hpost.
rewrite (Hsc a Ha) in Hpost. unfold balanceOfAcA in Hpost.
unfold initialEffReserveBals. rewrite reserve_after_exec_current.
unfold clamped, advanceEffReserveBals, initialEffReserveBals. lia.
Qed.
Lemma accepted_tail s h tx rest :
(∀ a, a ∈ map sender rest → a ∈ map sender transactions) →
(∀ t, t ∈ rest → (txBlockNum tx ≤ txBlockNum t < txBlockNum tx + K)%N) →
(∀ a, a ∈ map sender rest → isSC (execute s tx).1.1 a = false) →
consensusAcceptableTxs s h (tx :: rest) →
consensusAcceptableTxs (execute s tx).1 (txBlockNum tx) rest.
Proof using All.
intros Hscope Hrange Hsc Haccept.
pose proof (accepted_head_fee s h tx rest Haccept) as Hfee.
intros a Ha. specialize (Haccept a ltac:(simpl; set_solver)).
cbn [remainingEffReserveBalsL app] in Haccept.
eapply Z.le_trans; [exact Haccept|].
eapply (scan_mono s (execute s tx).1 rest (map sender rest)).
{ intros t Ht. apply list_elem_of_In, in_map, list_elem_of_In. exact Ht. }
{ apply initial_after_exec; assumption. }
{ intros t Ht b Hb. symmetry.
apply (delayedReserveBalOfAddrWithinK K K_pos evmExecTxCore revertTx).
all: specialize (Hrange t Ht); lia. }
{ intros t Ht extra. cbn [app].
assert (Hs : sender t ∈ map sender rest).
{ apply list_elem_of_In, in_map, list_elem_of_In. exact Ht. }
pose proof (Hrange t Ht) as Htime. split.
{ apply (execPreservesIsAllowedToEmpty K K_pos evmExecTxCore revertTx); lia. }
split.
{ apply (execPreservesSenderNoRecentActivity K K_pos evmExecTxCore revertTx); lia. }
intros [He|Hr].
{ eapply (emptyBalanceUb K K_pos evmExecTxCore revertTx); eauto. }
{ eapply (inactiveBalanceUb K K_pos evmExecTxCore revertTx); eauto. } }
{ exact Ha. }
Qed.
Lemma fullBlockStep_scoped (s : AugmentedState) (h : N) (first rest : list TxWithHdr) :
(∀ a, a ∈ map sender (first ++ rest) → a ∈ map sender transactions) →
blockNumsInRange (first ++ rest) →
consensusAcceptableTxs s h (first ++ rest) →
(∀ tx, tx ∈ first ++ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender (first ++ rest))) →
(∀ a, a ∈ map sender (first ++ rest) → isSC s.1 a = false) →
match execTxs s first with
| None ⇒ False
| Some (post, _) ⇒
consensusAcceptableTxs post (fold_left (fun _ tx ⇒ txBlockNum tx) first h) rest ∧
blockNumsInRange rest ∧
(∀ a, a ∈ map sender rest → isSC post.1 a = false) ∧
(∀ tx, tx ∈ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender rest))
end.
Proof using All.
revert s h. induction first as [|tx first IH]; intros s h Hscope Hrange Haccept Hcrypto Hsc.
{ cbn [app execTxs fold_left] in ×. repeat split; assumption. }
cbn [app blockNumsInRange] in Hrange. destruct Hrange as [Hrange Htailrange].
cbn [app] in Hscope, Haccept, Hcrypto, Hsc.
pose proof (accepted_head_fee s h tx (first ++ rest) Haccept) as Hfee.
assert (HnextSc : ∀ a, a ∈ map sender (first ++ rest) →
isSC (execute s tx).1.1 a = false).
{ intros a Ha. apply (Hcrypto tx ltac:(set_solver) s a).
{ simpl. set_solver. }
{ apply Hsc. simpl. set_solver. } }
assert (HnextAccept : consensusAcceptableTxs (execute s tx).1 (txBlockNum tx) (first ++ rest)).
{ eapply accepted_tail; try eassumption. intros a Ha. apply Hscope. simpl. set_solver. }
specialize (IH (execute s tx).1 (txBlockNum tx)).
assert (HnextScope : ∀ a, a ∈ map sender (first ++ rest) → a ∈ map sender transactions).
{ intros a Ha. apply Hscope. simpl. set_solver. }
assert (HnextCrypto : ∀ t, t ∈ first ++ rest →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx t (map sender (first ++ rest))).
{ intros t Ht state; cbn zeta; intros a Ha Hcode. apply (Hcrypto t ltac:(set_solver) state a); [simpl; set_solver|exact Hcode]. }
specialize (IH HnextScope Htailrange HnextAccept HnextCrypto HnextSc).
cbn [execTxs fold_left]. unfold validateTx. rewrite bool_decide_true; [|exact Hfee].
destruct (execute s tx) as [next receipt]. cbn [fst] in IH.
destruct (execTxs next first) as [[post receipts]|]; simpl in *; assumption.
Qed.
End ExecutionProofs.
Both Boolean settings satisfy the original prefix/suffix guarantee, not
merely a weaker final fee bound. Restarting consensus from the actual
post-prefix state with fresh budgets accepts the remaining transactions.
The post-prefix height is its last transaction's block, or h for an
empty prefix. No hypothesis requires refreshReserve to be true.
Theorem fullBlockStep (latestState : AugmentedState) (h : N) (firstblock restblocks : list TxWithHdr)
`{eas : EVMAssupmtions evmExecTxCore revertTx (firstblock ++ restblocks)} :
blockNumsInRange (firstblock ++ restblocks) →
consensusAcceptableTxs latestState h (firstblock ++ restblocks) →
(∀ tx, tx ∈ firstblock ++ restblocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender (firstblock ++ restblocks))) →
(∀ a, a ∈ map sender (firstblock ++ restblocks) → isSC latestState.1 a = false) →
match execTxs latestState firstblock with
| None ⇒ False
| Some (post, _) ⇒
consensusAcceptableTxs post (fold_left (fun _ tx ⇒ txBlockNum tx) firstblock h) restblocks ∧
blockNumsInRange restblocks ∧
(∀ a, a ∈ map sender restblocks → isSC post.1 a = false) ∧
(∀ tx, tx ∈ restblocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender restblocks))
end.
Proof using All.
apply (fullBlockStep_scoped (transactions := firstblock ++ restblocks)).
intros a Ha. exact Ha.
Qed.
Corollary fullBlockStep2 (latestState : AugmentedState) (h : N) (blocks : list TxWithHdr)
`{eas : EVMAssupmtions evmExecTxCore revertTx blocks} :
blockNumsInRange blocks →
consensusAcceptableTxs latestState h blocks →
(∀ tx, tx ∈ blocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender blocks)) →
(∀ a, a ∈ map sender blocks → isSC latestState.1 a = false) →
∃ post receipts, execTxs latestState blocks = Some (post, receipts).
Proof using All.
intros Hrange Haccept Hcrypto Hsc.
pose proof (fullBlockStep_scoped (transactions := blocks) latestState h blocks []) as Hfull.
rewrite app_nil_r in Hfull.
specialize (Hfull ltac:(auto) Hrange Haccept Hcrypto Hsc).
destruct (execTxs latestState blocks) as [[post receipts]|] eqn:Hrun; [eauto|contradiction].
Qed.
End Consensus.
Print Assumptions fullBlockStep.
Print Assumptions fullBlockStep2.
`{eas : EVMAssupmtions evmExecTxCore revertTx (firstblock ++ restblocks)} :
blockNumsInRange (firstblock ++ restblocks) →
consensusAcceptableTxs latestState h (firstblock ++ restblocks) →
(∀ tx, tx ∈ firstblock ++ restblocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender (firstblock ++ restblocks))) →
(∀ a, a ∈ map sender (firstblock ++ restblocks) → isSC latestState.1 a = false) →
match execTxs latestState firstblock with
| None ⇒ False
| Some (post, _) ⇒
consensusAcceptableTxs post (fold_left (fun _ tx ⇒ txBlockNum tx) firstblock h) restblocks ∧
blockNumsInRange restblocks ∧
(∀ a, a ∈ map sender restblocks → isSC post.1 a = false) ∧
(∀ tx, tx ∈ restblocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender restblocks))
end.
Proof using All.
apply (fullBlockStep_scoped (transactions := firstblock ++ restblocks)).
intros a Ha. exact Ha.
Qed.
Corollary fullBlockStep2 (latestState : AugmentedState) (h : N) (blocks : list TxWithHdr)
`{eas : EVMAssupmtions evmExecTxCore revertTx blocks} :
blockNumsInRange blocks →
consensusAcceptableTxs latestState h blocks →
(∀ tx, tx ∈ blocks →
txCannotCreateContractAtAddrs K evmExecTxCore revertTx tx (map sender blocks)) →
(∀ a, a ∈ map sender blocks → isSC latestState.1 a = false) →
∃ post receipts, execTxs latestState blocks = Some (post, receipts).
Proof using All.
intros Hrange Haccept Hcrypto Hsc.
pose proof (fullBlockStep_scoped (transactions := blocks) latestState h blocks []) as Hfull.
rewrite app_nil_r in Hfull.
specialize (Hfull ltac:(auto) Hrange Haccept Hcrypto Hsc).
destruct (execTxs latestState blocks) as [[post receipts]|] eqn:Hrun; [eauto|contradiction].
Qed.
End Consensus.
Print Assumptions fullBlockStep.
Print Assumptions fullBlockStep2.
The natural-number range used above is the original signed range, with
subtraction eliminated; the strict upper bound still excludes height h+K.
Lemma block_range_original K h t :
(0 < K)%N →
((h ≤ t < h + K)%N ↔
(Z.of_N t - (Z.of_N K - 1) ≤ Z.of_N h ≤ Z.of_N t)%Z).
Proof. lia. Qed.
(0 < K)%N →
((h ≤ t < h + K)%N ↔
(Z.of_N t - (Z.of_N K - 1) ≤ Z.of_N h ≤ Z.of_N t)%Z).
Proof. lia. Qed.
The switch changes neither emptying nor active-sender checks.
Lemma refresh_inactive_only K s budget previous tx :
senderNoRecentActivity K s previous tx = false →
remainingEffReserveBalOfSender K true s budget previous tx =
remainingEffReserveBalOfSender K false s budget previous tx.
Proof.
intros H. unfold remainingEffReserveBalOfSender. rewrite H. reflexivity.
Qed.
senderNoRecentActivity K s previous tx = false →
remainingEffReserveBalOfSender K true s budget previous tx =
remainingEffReserveBalOfSender K false s budget previous tx.
Proof.
intros H. unfold remainingEffReserveBalOfSender. rewrite H. reflexivity.
Qed.
Regression for the self-authorizing example: the snapshot-height
threshold is 10, the candidate-height threshold is 100, and fee 20 fits
only after refresh. The flag premises describe an inactive undelegated
sender whose current authorization disables emptying, but not refresh.
Example refresh_acceptance_difference K s h tx :
balanceOfAc s.1 (sender tx) = 100 →
delayedReserveBalOfAddr K s.2 (sender tx) h = 10 →
delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx) = 100 →
maxTxFee tx = 20 →
senderNoRecentActivity K s [] tx = true →
isAllowedToEmpty K s [] tx = false →
consensusAcceptableTxs K true s h [tx] ∧
¬ consensusAcceptableTxs K false s h [tx].
Proof.
intros Hbalance Hsettled Hthreshold Hfee Hrefresh Hempty.
assert (Hremaining : ∀ b,
remainingEffReserveBalsL K b s (initialEffReserveBals K s h) [] [tx] (sender tx) =
(if b then 80 else -10)%Z).
{ intros b. cbn [remainingEffReserveBalsL]. unfold updateKey.
rewrite bool_decide_true; [|reflexivity].
unfold remainingEffReserveBalOfSender, advanceEffReserveBals, initialEffReserveBals.
rewrite Hbalance Hsettled Hthreshold Hfee Hrefresh Hempty.
destruct b; reflexivity. }
split.
{ intros a Ha. assert (a = sender tx) by (simpl in Ha; set_solver). subst a.
rewrite Hremaining. lia. }
intros Haccept. specialize (Haccept (sender tx) ltac:(simpl; set_solver)).
rewrite Hremaining in Haccept. lia.
Qed.
balanceOfAc s.1 (sender tx) = 100 →
delayedReserveBalOfAddr K s.2 (sender tx) h = 10 →
delayedReserveBalOfAddr K s.2 (sender tx) (txBlockNum tx) = 100 →
maxTxFee tx = 20 →
senderNoRecentActivity K s [] tx = true →
isAllowedToEmpty K s [] tx = false →
consensusAcceptableTxs K true s h [tx] ∧
¬ consensusAcceptableTxs K false s h [tx].
Proof.
intros Hbalance Hsettled Hthreshold Hfee Hrefresh Hempty.
assert (Hremaining : ∀ b,
remainingEffReserveBalsL K b s (initialEffReserveBals K s h) [] [tx] (sender tx) =
(if b then 80 else -10)%Z).
{ intros b. cbn [remainingEffReserveBalsL]. unfold updateKey.
rewrite bool_decide_true; [|reflexivity].
unfold remainingEffReserveBalOfSender, advanceEffReserveBals, initialEffReserveBals.
rewrite Hbalance Hsettled Hthreshold Hfee Hrefresh Hempty.
destruct b; reflexivity. }
split.
{ intros a Ha. assert (a = sender tx) by (simpl in Ha; set_solver). subst a.
rewrite Hremaining. lia. }
intros Haccept. specialize (Haccept (sender tx) ltac:(simpl; set_solver)).
rewrite Hremaining in Haccept. lia.
Qed.
Initial budgets do not depend on whether the representation has already
promoted settings that are effective at the snapshot height.
Lemma initialEffReserveBals_promoted K s h a :
(0 < K)%N →
initialEffReserveBals K
(s.1, fun b ⇒ promotePendingReserveBal K (s.2 b) h) h a =
initialEffReserveBals K s h a.
Proof.
intros Hpos. unfold initialEffReserveBals, delayedReserveBalOfAddr. cbn [fst snd].
rewrite (delayedReserveBal_promoteWithinK K Hpos); [reflexivity|lia|lia].
Qed.
Section SnapshotHeightRegressions.
Variable accounts : StateOfAccounts.
Variable tx : TxWithHdr.
Hypothesis sender_balance : balanceOfAc accounts (sender tx) = 100.
Hypothesis delegated_sender : addrDelegated accounts (sender tx) = true.
Hypothesis candidate_height : txBlockNum tx = 106.
Hypothesis candidate_fee : maxTxFee tx = 20.
(0 < K)%N →
initialEffReserveBals K
(s.1, fun b ⇒ promotePendingReserveBal K (s.2 b) h) h a =
initialEffReserveBals K s h a.
Proof.
intros Hpos. unfold initialEffReserveBals, delayedReserveBalOfAddr. cbn [fst snd].
rewrite (delayedReserveBal_promoteWithinK K Hpos); [reflexivity|lia|lia].
Qed.
Section SnapshotHeightRegressions.
Variable accounts : StateOfAccounts.
Variable tx : TxWithHdr.
Hypothesis sender_balance : balanceOfAc accounts (sender tx) = 100.
Hypothesis delegated_sender : addrDelegated accounts (sender tx) = true.
Hypothesis candidate_height : txBlockNum tx = 106.
Hypothesis candidate_fee : maxTxFee tx = 20.
Request in block 100, activation at 103, and no transactions in 101--103:
the snapshot record still has the old settled value. Delegation rules out
both emptying and refresh, so acceptance below tests initialization alone.
Let snapshot : AugmentedState := (accounts, fun a ⇒
if bool_decide (a = sender tx) then
{| lastTxInBlockIndex := Some 100; lastDelUndelInBlockIndex := None;
settledReserveBal := 10; pendingReserveBal := Some (100, 100) |}
else
{| lastTxInBlockIndex := None; lastDelUndelInBlockIndex := None;
settledReserveBal := 10; pendingReserveBal := None |}).
Example empty_activation_uses_effective_not_settled_threshold :
settledReserveBal (snapshot.2 (sender tx)) = 10 ∧
initialEffReserveBals 3 snapshot 102 (sender tx) = 10%Z ∧
initialEffReserveBals 3 snapshot 103 (sender tx) = 100%Z.
Proof using All.
unfold snapshot, initialEffReserveBals, delayedReserveBalOfAddr, delayedReserveBal.
cbn [fst snd]. rewrite (bool_decide_true (sender tx = sender tx) eq_refl).
cbn [settledReserveBal pendingReserveBal]. rewrite sender_balance.
vm_compute. auto.
Qed.
Example accepts_after_empty_activation (refresh : bool) :
consensusAcceptableTxs 3 refresh snapshot 103 [tx].
Proof using All.
intros a Ha. assert (a = sender tx) by (simpl in Ha; set_solver). subst a.
cbn [remainingEffReserveBalsL]. unfold updateKey.
rewrite bool_decide_true; [|reflexivity].
unfold remainingEffReserveBalOfSender, advanceEffReserveBals, initialEffReserveBals,
senderNoRecentActivity, isAllowedToEmpty, delayedReserveBalOfAddr.
unfold snapshot. cbn [fst snd].
rewrite (bool_decide_true (sender tx = sender tx) eq_refl).
rewrite delegated_sender sender_balance candidate_height candidate_fee.
rewrite !orb_true_l !andb_false_r. cbn [negb andb].
vm_compute. discriminate.
Qed.
End SnapshotHeightRegressions.
if bool_decide (a = sender tx) then
{| lastTxInBlockIndex := Some 100; lastDelUndelInBlockIndex := None;
settledReserveBal := 10; pendingReserveBal := Some (100, 100) |}
else
{| lastTxInBlockIndex := None; lastDelUndelInBlockIndex := None;
settledReserveBal := 10; pendingReserveBal := None |}).
Example empty_activation_uses_effective_not_settled_threshold :
settledReserveBal (snapshot.2 (sender tx)) = 10 ∧
initialEffReserveBals 3 snapshot 102 (sender tx) = 10%Z ∧
initialEffReserveBals 3 snapshot 103 (sender tx) = 100%Z.
Proof using All.
unfold snapshot, initialEffReserveBals, delayedReserveBalOfAddr, delayedReserveBal.
cbn [fst snd]. rewrite (bool_decide_true (sender tx = sender tx) eq_refl).
cbn [settledReserveBal pendingReserveBal]. rewrite sender_balance.
vm_compute. auto.
Qed.
Example accepts_after_empty_activation (refresh : bool) :
consensusAcceptableTxs 3 refresh snapshot 103 [tx].
Proof using All.
intros a Ha. assert (a = sender tx) by (simpl in Ha; set_solver). subst a.
cbn [remainingEffReserveBalsL]. unfold updateKey.
rewrite bool_decide_true; [|reflexivity].
unfold remainingEffReserveBalOfSender, advanceEffReserveBals, initialEffReserveBals,
senderNoRecentActivity, isAllowedToEmpty, delayedReserveBalOfAddr.
unfold snapshot. cbn [fst snd].
rewrite (bool_decide_true (sender tx = sender tx) eq_refl).
rewrite delegated_sender sender_balance candidate_height candidate_fee.
rewrite !orb_true_l !andb_false_r. cbn [negb andb].
vm_compute. discriminate.
Qed.
End SnapshotHeightRegressions.